import serial
import struct
+import threading
dPinToBit = {
"POWER": 6,
# http://dangerousprototypes.com/docs/SPI_(binary)
class BP:
def __init__(self, sDevice):
+ self.lock = threading.Lock()
self.pSerial = serial.Serial(sDevice, baudrate=115200, timeout=0.1)
self.mode_bit_bang()
self.io_state = 0
self.io_dir = 0
def command(self, cmd, num_read):
- self.pSerial.write(cmd)
- return self.pSerial.read(num_read)
+ with self.lock:
+ self.pSerial.write(cmd)
+ return self.pSerial.read(num_read)
def mode_bit_bang(self):
for i in range(20):