Commit 3f15a50b authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Try to make PrologicUSB thread safe

parent d7ed83c0
...@@ -3,6 +3,7 @@ import time ...@@ -3,6 +3,7 @@ import time
import re import re
import platform import platform
import sys import sys
from threading import Lock
class PortDevice(object): class PortDevice(object):
...@@ -27,6 +28,7 @@ class PrologixGpibUsb(PortDevice): ...@@ -27,6 +28,7 @@ class PrologixGpibUsb(PortDevice):
max_device_num, port, port_format = self._set_default_platform_values() max_device_num, port, port_format = self._set_default_platform_values()
self._validate_port(port) self._validate_port(port)
self._lock = Lock()
if verbose: if verbose:
print("Looking for ports such as %s in range %d on %s" % \ print("Looking for ports such as %s in range %d on %s" % \
...@@ -101,7 +103,8 @@ class PrologixGpibUsb(PortDevice): ...@@ -101,7 +103,8 @@ class PrologixGpibUsb(PortDevice):
command = "++addr " + str(hpib_address) + chr(10) + command command = "++addr " + str(hpib_address) + chr(10) + command
self._hpib_address = hpib_address self._hpib_address = hpib_address
self._write_serial(command + chr(10)) with self._lock:
self._write_serial(command + chr(10))
def query(self, hpib_address, query, count=80): def query(self, hpib_address, query, count=80):
if hpib_address != self._hpib_address: if hpib_address != self._hpib_address:
...@@ -109,8 +112,9 @@ class PrologixGpibUsb(PortDevice): ...@@ -109,8 +112,9 @@ class PrologixGpibUsb(PortDevice):
self._hpib_address = hpib_address self._hpib_address = hpib_address
query += chr(10) + "++read eoi" + chr(10) query += chr(10) + "++read eoi" + chr(10)
self._write_serial(query) with self._lock:
line = self._serialPort.readline() self._write_serial(query)
line = self._serialPort.readline()
return line[:-1] return line[:-1]
def set_local(self, hpib_address): def set_local(self, hpib_address):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment