]> defiant.homedns.org Git - pyshared.git/commitdiff
bus_pirate: protect hw with lock
authorErik Andresen <erik@vontaene.de>
Fri, 6 Sep 2019 06:12:02 +0000 (08:12 +0200)
committerErik Andresen <erik@vontaene.de>
Fri, 6 Sep 2019 06:12:02 +0000 (08:12 +0200)
bus_pirate.py

index cdd259fa7581ee42dba23da879fbf10b3aa4d287..d7c8eaf0d483df61e87b463df04db1a0a8c2d868 100644 (file)
@@ -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):