From d75dcf78890558e4b8e2ded3d734f769c217e0ef Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Fri, 6 Sep 2019 08:12:02 +0200 Subject: [PATCH] bus_pirate: protect hw with lock --- bus_pirate.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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): -- 2.39.2