-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathusing_autoconnect.py
More file actions
36 lines (26 loc) · 1014 Bytes
/
Copy pathusing_autoconnect.py
File metadata and controls
36 lines (26 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/python3
##-------------------------------------------------------------------------------\
# tinySA_python (tsapython)
# './examples/using_autoconnect.py'
# This is an example of using the autoconnect feature.
# The detected device ID is returned and the serial disconnected
#
# Last update: August 17, 2025
##-------------------------------------------------------------------------------\
# import tinySA_python (tsapython) package
from tsapython import tinySA
# create a new tinySA object
tsa = tinySA()
# set the return message preferences
tsa.set_verbose(True) #detailed messages
tsa.set_error_byte_return(True) #get explicit b'ERROR' if error thrown
# attempt to autoconnect
found_bool, connected_bool = tsa.autoconnect()
# if port found and connected, then complete task(s) and disconnect
if connected_bool == True:
print("device connected")
msg = tsa.get_device_id()
print(msg)
tsa.disconnect()
else:
print("ERROR: could not connect to port")