Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathserial_client.py
More file actions
Latest commit
executable file
·54 lines (45 loc) · 1.96 KB
/
Copy pathserial_client.py
File metadata and controls
executable file
·54 lines (45 loc) · 1.96 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
importos
importsys
try:
importserial
exceptImportError:
print("This application requires pyserial. Please install (pip install pyserial) and run again.")
sys.exit(1)
# Add the Python root directory (fusion-engine-client/python/) to the import search path to enable FusionEngine imports
# if this application is being run directly out of the repository and is not installed as a pip package.
root_dir=os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, root_dir)
fromfusion_engine_client.utils.argument_parserimportArgumentParser
fromfusion_engine_client.messagesimportMessagePayload
fromfusion_engine_client.parsersimportFusionEngineDecoder
if__name__=="__main__":
# Parse command-line arguments.
parser=ArgumentParser(description="""\
Connect to a Point One device over serial and print out the incoming message
contents.
""")
parser.add_argument('-b', '--baud', type=int, default=460800,
help="The serial baud rate to be used.")
parser.add_argument('port',
help="The serial device to use (e.g., /dev/ttyUSB0, COM1)")
options=parser.parse_args()
# Connect to the device.
transport=serial.Serial(port=options.port, baudrate=options.baud)
# Listen for incoming data and parse FusionEngine messages.
try:
decoder=FusionEngineDecoder()
whileTrue:
received_data=transport.read(1024)
messages=decoder.on_data(received_data)
forheader, messageinmessages:
ifisinstance(message, MessagePayload):
print(str(message))
else:
print(f'{header.message_type} message (not supported)')
exceptKeyboardInterrupt:
pass
exceptserial.SerialExceptionase:
print('Unexpected error reading from device:\r%s'%str(e))
# Close the transport when finished.
transport.close()