-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.py
More file actions
31 lines (25 loc) · 904 Bytes
/
Copy pathcmd.py
File metadata and controls
31 lines (25 loc) · 904 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
## cmd_response wrapper for python
class Cmd_Response(object):
'''interface class with cmd_response Arduino sketch'''
def __init__(self, serial_port, baud=115200,
delimiter='\n', timeout=PORT_TIMEOUT):
self.serial_port = serial_port
self.baud = baud
self.delimiter = delimiter
self.timeout = timeout
self.port = serial.Serial(serial_port, baud, timeout=self.timeout)
self.port.flushInput()
def send(self, cmd):
'''write the command to the USB port'''
self.port.write(cmd + self.delimiter)
def receive(self):
'''read the device response from the USB port'''
return self.port.readline().strip()
def request(self, cmd):
'''return the result from the command'''
self.send(cmd)
return self.receive()
def report(self, cmd):
'''print the response to the command'''
print "%s " % cmd,
print self.request(cmd)