|
@ -4,7 +4,7 @@ import threading |
|
|
import serial |
|
|
import serial |
|
|
|
|
|
|
|
|
class Serial(object): |
|
|
class Serial(object): |
|
|
self._callbacks = dict() |
|
|
_callbacks = dict() |
|
|
|
|
|
|
|
|
def __init__(self, devicename='/dev/ttyUSB0', baudrate=115200): |
|
|
def __init__(self, devicename='/dev/ttyUSB0', baudrate=115200): |
|
|
self.devicename = devicename |
|
|
self.devicename = devicename |
|
@ -50,9 +50,10 @@ class Serial(object): |
|
|
print(data) |
|
|
print(data) |
|
|
command = data[0] |
|
|
command = data[0] |
|
|
argument = data[2:] |
|
|
argument = data[2:] |
|
|
cb = self._callbacks[command] |
|
|
if command in data: |
|
|
if cb: |
|
|
cb = self._callbacks[command] |
|
|
cb(argument) |
|
|
if cb: |
|
|
|
|
|
cb(argument) |
|
|
|
|
|
|
|
|
except serial.SerialException: |
|
|
except serial.SerialException: |
|
|
pass |
|
|
pass |
|
|