"""wrapper around PyANC350v4 main purpose: make Positioner thread safe without this, when accessing the device from different threads, timeouts may appear allows also to omit axis in method arguments """ import inspect import threading # make sure PYTHONPATH points to the directory of PyANC350v4.py # e.g. in /home/l_samenv/Documents/anc350/Linux64/userlib/lib from PyANC350v4 import Positioner class HwAxis: hw = None lock = None axes = set() def __init__(self, axisNo): self.axisNo = axisNo if not self.axes: self.axes.add(axisNo) HwAxis.hw = Positioner() HwAxis.lock = threading.Lock() super().__init__() def close(self): self.axes.discard(self.axisNo) if not self.axes: self.hw.disconnect() # wrap methods from Positioner and insert to HwAxis for name, method in Positioner.__dict__.items(): try: arguments = inspect.getfullargspec(method).args except TypeError as e: continue if arguments[0:2] == ['self', 'axisNo']: def wrapper(self, *args, _method=method, **kwds): with self.lock: return _method(self.hw, self.axisNo, *args, **kwds) setattr(HwAxis, name, wrapper)