-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialTactiComExample.py
More file actions
44 lines (30 loc) · 1.12 KB
/
SerialTactiComExample.py
File metadata and controls
44 lines (30 loc) · 1.12 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
"""
This example shows how to use the SerialTactiCom class to communicate with a TactiCom device using events and requests.
"""
import time
from tacticom import SerialTactiCom
def main():
# Create a SerialTactiCom
stc = SerialTactiCom("R1", "/dev/ttyUSB0", 115200)
stc.open() # Open the serial port
print("Connected to TactiCom device")
time.sleep(2) # Let Arduino time to boot (Arduino resets on serial connection)
# send an event
stc.send_event("led", "on")
# send a request
print(stc.send_request("ping"))
# send a request
result_command, result_parameter = stc.send_request("add", "1", "2")
print("The result is: " + result_parameter[0])
# send a request
result_command, result_parameter = stc.send_request("divide", "11", "5")
if result_command == "divide_error":
print("Error: " + result_parameter[0])
else:
print("The result is: " + result_parameter[0] + " r: " + result_parameter[1])
stc.send_event("led", "off")
input("Press Enter to exit...")
# Close the communication port
stc.close()
if __name__ == '__main__':
main()