From: Erik Andresen Date: Fri, 6 Sep 2019 06:12:02 +0000 (+0200) Subject: bus_pirate: protect hw with lock X-Git-Url: https://defiant.homedns.org/gitweb/?a=commitdiff_plain;h=d75dcf78890558e4b8e2ded3d734f769c217e0ef;p=pyshared.git bus_pirate: protect hw with lock --- 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):