X-Git-Url: https://defiant.homedns.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=bus_pirate.py;h=d7c8eaf0d483df61e87b463df04db1a0a8c2d868;hb=d75dcf78890558e4b8e2ded3d734f769c217e0ef;hp=cdd259fa7581ee42dba23da879fbf10b3aa4d287;hpb=c9dbcc66879f0e1d8beb05b49179fcb200ef8cf0;p=pyshared.git diff --git a/bus_pirate.py b/bus_pirate.py index cdd259f..d7c8eaf 100644 --- a/bus_pirate.py +++ b/bus_pirate.py @@ -3,6 +3,7 @@ import serial import struct +import threading dPinToBit = { "POWER": 6, @@ -18,14 +19,16 @@ dPinToBit = { # 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):