From ea381a4093ccc093021c92f7c59f8e99d2bc07a8 Mon Sep 17 00:00:00 2001 From: neo-dl Date: Thu, 30 Mar 2023 12:06:45 +0200 Subject: [PATCH] sim-io linux TBT --- .../Automation/BDaq/NoiseFilterChannel.py | 4 +- src/components/__init__.py | 1 + .../dummies/Automation/BDaq/BDaqApi.py | 6 +- .../dummies/Automation/BDaq/DaqCtrlBase.py | 16 ++-- .../dummies/Automation/BDaq/DeviceCtrl.py | 8 +- .../dummies/Automation/BDaq/DiCosintPort.py | 4 +- .../dummies/Automation/BDaq/DiPmintPort.py | 4 +- .../dummies/Automation/BDaq/DiintChannel.py | 6 +- .../dummies/Automation/BDaq/DioFeatures.py | 8 +- .../dummies/Automation/BDaq/DioPort.py | 6 +- src/components/usb_586x.py | 74 ++++++++++--------- src/main.py | 11 ++- 12 files changed, 77 insertions(+), 71 deletions(-) diff --git a/src/components/Automation/BDaq/NoiseFilterChannel.py b/src/components/Automation/BDaq/NoiseFilterChannel.py index 0de98c2..2adc278 100644 --- a/src/components/Automation/BDaq/NoiseFilterChannel.py +++ b/src/components/Automation/BDaq/NoiseFilterChannel.py @@ -1,8 +1,8 @@ #!/usr/bin/python # -*- coding:utf-8 -*- -from Automation.BDaq.BDaqApi import TNosFltChannel, BioFailed -from Automation.BDaq import ErrorCode +from dummies.Automation.BDaq.BDaqApi import TNosFltChannel, BioFailed +from dummies.Automation.BDaq import ErrorCode class NoiseFilterChannel(object): diff --git a/src/components/__init__.py b/src/components/__init__.py index 297def7..973d595 100644 --- a/src/components/__init__.py +++ b/src/components/__init__.py @@ -10,6 +10,7 @@ from .serial_label_printer import Serial_Label_Printer from .tecna_marposs_provaset_t3 import TecnaMarpossProvasetT3 from .tecna_screwdriver import TecnaScrewdriver from .test_component import TestComponent +from .usb_586x import USB_586x if "--vision" in sys.argv: from .galaxy_camera import GalaxyCamera from .neo_pixels import NeoPixels diff --git a/src/components/dummies/Automation/BDaq/BDaqApi.py b/src/components/dummies/Automation/BDaq/BDaqApi.py index 8a07693..7e2f0b1 100644 --- a/src/components/dummies/Automation/BDaq/BDaqApi.py +++ b/src/components/dummies/Automation/BDaq/BDaqApi.py @@ -13,7 +13,7 @@ if platform.architecture()[0] == '32bit': if platform.system().lower() == 'windows': dll = windll.LoadLibrary(r"biodaq") else: - dll = cdll.LoadLibrary(r"libbiodaq.so") + dll = None def AdxEnumToString(enumName, enumValue, enumStrLen): @@ -716,9 +716,7 @@ class TDaqCtrlBase(object): @staticmethod def Create(scenario): - dll.TDaqCtrlBase_Create.argtypes = [c_int32] - dll.TDaqCtrlBase_Create.restype = c_uint64 - return dll.TDaqCtrlBase_Create(scenario) + return None @staticmethod def getModule(obj): diff --git a/src/components/dummies/Automation/BDaq/DaqCtrlBase.py b/src/components/dummies/Automation/BDaq/DaqCtrlBase.py index e769696..86b2ef7 100644 --- a/src/components/dummies/Automation/BDaq/DaqCtrlBase.py +++ b/src/components/dummies/Automation/BDaq/DaqCtrlBase.py @@ -2,11 +2,11 @@ # -*- coding:utf-8 -*- from Automation.BDaq import ErrorCode -from Automation.BDaq.BDaqApi import TDaqCtrlBase, TArray, BioFailed -from Automation.BDaq import DeviceInformation, ControlState -from Automation.BDaq.DeviceCtrl import DeviceCtrl -from Automation.BDaq import Utils -from Automation.BDaq import ErrorCode +from dummies.Automation.BDaq.BDaqApi import TDaqCtrlBase, TArray, BioFailed +from dummies.Automation.BDaq import DeviceInformation, ControlState +from dummies.Automation.BDaq.DeviceCtrl import DeviceCtrl +from dummies.Automation.BDaq import Utils +from dummies.Automation.BDaq import ErrorCode class DaqCtrlBase(object): @@ -39,11 +39,11 @@ class DaqCtrlBase(object): raise TypeError('The parameter value is not supported.') if isinstance(devInfo, str): - ret = ErrorCode.lookup(TDaqCtrlBase.setSelectedDevice(self._obj, DeviceInformation(Description=devInfo))) + ret = ErrorCode.Success elif isinstance(devInfo, int): - ret = ErrorCode.lookup(TDaqCtrlBase.setSelectedDevice(self._obj, DeviceInformation(Description=u'', DeviceNumber=devInfo))) + ret = ErrorCode.Success else: - ret = ErrorCode.lookup(TDaqCtrlBase.setSelectedDevice(self._obj, devInfo)) + ret = ErrorCode.Success #if BioFailed(ret): # raise ValueError('ERRORE MODULO I/O: CODICE 0x%X' % (ret.value)) diff --git a/src/components/dummies/Automation/BDaq/DeviceCtrl.py b/src/components/dummies/Automation/BDaq/DeviceCtrl.py index 75700d1..b324e26 100644 --- a/src/components/dummies/Automation/BDaq/DeviceCtrl.py +++ b/src/components/dummies/Automation/BDaq/DeviceCtrl.py @@ -5,10 +5,10 @@ from ctypes import c_int32, c_byte, c_uint8 from ctypes import create_unicode_buffer from ctypes import pointer -from Automation.BDaq.BDaqApi import TArray, TerminalBoard -from Automation.BDaq.BDaqApi import TDeviceCtrl, BioFailed -from Automation.BDaq import ErrorCode -from Automation.BDaq import Utils +from dummies.Automation.BDaq.BDaqApi import TArray, TerminalBoard +from dummies.Automation.BDaq.BDaqApi import TDeviceCtrl, BioFailed +from dummies.Automation.BDaq import ErrorCode +from dummies.Automation.BDaq import Utils class DeviceCtrl(object): diff --git a/src/components/dummies/Automation/BDaq/DiCosintPort.py b/src/components/dummies/Automation/BDaq/DiCosintPort.py index 30e4f24..aab182c 100644 --- a/src/components/dummies/Automation/BDaq/DiCosintPort.py +++ b/src/components/dummies/Automation/BDaq/DiCosintPort.py @@ -2,8 +2,8 @@ # -*- coding:utf-8 -*- -from Automation.BDaq.BDaqApi import TDiCosintPort, BioFailed -from Automation.BDaq import ErrorCode +from dummies.Automation.BDaq.BDaqApi import TDiCosintPort, BioFailed +from dummies.Automation.BDaq import ErrorCode class DiCosintPort(object): diff --git a/src/components/dummies/Automation/BDaq/DiPmintPort.py b/src/components/dummies/Automation/BDaq/DiPmintPort.py index e8733fd..2288e01 100644 --- a/src/components/dummies/Automation/BDaq/DiPmintPort.py +++ b/src/components/dummies/Automation/BDaq/DiPmintPort.py @@ -1,8 +1,8 @@ #!/usr/bin/python # -*- coding:utf-8 -*- -from Automation.BDaq.BDaqApi import TDiPmintPort -from Automation.BDaq import ErrorCode +from dummies.Automation.BDaq.BDaqApi import TDiPmintPort +from dummies.Automation.BDaq import ErrorCode class DiPmintPort(object): diff --git a/src/components/dummies/Automation/BDaq/DiintChannel.py b/src/components/dummies/Automation/BDaq/DiintChannel.py index 7388023..c5f5c95 100644 --- a/src/components/dummies/Automation/BDaq/DiintChannel.py +++ b/src/components/dummies/Automation/BDaq/DiintChannel.py @@ -1,9 +1,9 @@ #!/usr/bin/python # -*- coding:utf-8 -*- -from Automation.BDaq.BDaqApi import TDiintChannel, BioFailed -from Automation.BDaq import ErrorCode, ActiveSignal -from Automation.BDaq import Utils +from dummies.Automation.BDaq.BDaqApi import TDiintChannel, BioFailed +from dummies.Automation.BDaq import ErrorCode, ActiveSignal +from dummies.Automation.BDaq import Utils class DiintChannel(object): diff --git a/src/components/dummies/Automation/BDaq/DioFeatures.py b/src/components/dummies/Automation/BDaq/DioFeatures.py index 2504e57..e89aaf0 100644 --- a/src/components/dummies/Automation/BDaq/DioFeatures.py +++ b/src/components/dummies/Automation/BDaq/DioFeatures.py @@ -3,10 +3,10 @@ import ctypes -from Automation.BDaq.BDaqApi import TArray -from Automation.BDaq.BDaqApi import TDioFeatures -from Automation.BDaq import MathInterval -from Automation.BDaq import Utils +from dummies.Automation.BDaq.BDaqApi import TArray +from dummies.Automation.BDaq.BDaqApi import TDioFeatures +from dummies.Automation.BDaq import MathInterval +from dummies.Automation.BDaq import Utils class DioFeatures(object): diff --git a/src/components/dummies/Automation/BDaq/DioPort.py b/src/components/dummies/Automation/BDaq/DioPort.py index 163b50d..e20ff6c 100644 --- a/src/components/dummies/Automation/BDaq/DioPort.py +++ b/src/components/dummies/Automation/BDaq/DioPort.py @@ -1,9 +1,9 @@ #!/usr/bin/python # -*- coding:utf-8 -*- -from Automation.BDaq.BDaqApi import TDioPort, BioFailed -from Automation.BDaq import Utils -from Automation.BDaq import ErrorCode, DioPortDir, DoCircuitType +from dummies.Automation.BDaq.BDaqApi import TDioPort, BioFailed +from dummies.Automation.BDaq import Utils +from dummies.Automation.BDaq import ErrorCode, DioPortDir, DoCircuitType class DioPort(object): diff --git a/src/components/usb_586x.py b/src/components/usb_586x.py index 2eecef4..2236480 100644 --- a/src/components/usb_586x.py +++ b/src/components/usb_586x.py @@ -70,43 +70,51 @@ class USB_586x(Component): def open_device(self): # DIGITAL INPUTS CLASS - if is_win: + if not self.simulate: + if is_win: + self.di_ctrl = InstantDiCtrl(self.info.Description) + self.do_ctrl = InstantDoCtrl(self.info.Description) + self.di_read = self.di_ctrl.readAny + self.do_write_bit = self.do_ctrl.writeBit + self.buffer = ctypes.create_string_buffer(2) + else: + self.di_create = libbiodaq.AdxInstantDiCtrlCreate + self.di_create.restype = ctypes.c_void_p + self.di_setSelectedDevice = libbiodaq.InstantDiCtrl_setSelectedDevice + self.di_setSelectedDevice.argtypes = [ctypes.c_void_p, ctypes.POINTER(self.DeviceInformation)] + self.di_setSelectedDevice.restype = ctypes.c_uint32 + # DIGITAL INPUTS READ FUNCTION + self.di_read = libbiodaq.InstantDiCtrl_ReadAny + self.di_read.argtypes = [ctypes.c_void_p, ctypes.c_int32, ctypes.c_int32, ctypes.c_char_p] + self.di_read.restype = ctypes.c_int32 + # DIGITAL OUTPUTS CLASS + self.do_create = libbiodaq.AdxInstantDoCtrlCreate + self.do_create.restype = ctypes.c_void_p + # SET SELECTED DEVICE + self.do_setSelectedDevice = libbiodaq.InstantDoCtrl_setSelectedDevice + self.do_setSelectedDevice.argtypes = [ctypes.c_void_p, ctypes.POINTER(self.DeviceInformation)] + self.do_setSelectedDevice.restype = ctypes.c_uint32 + # get ports + self.get_ports = libbiodaq.InstantDoCtrl_getPortDirection + self.get_ports.argtypes = [ctypes.c_void_p] + self.get_ports.restype = ctypes.POINTER(ctypes.c_void_p) + # DIGITAL OUTPUTS WRITE FUNCTION + self.do_write_bit = libbiodaq.InstantDoCtrl_WriteBit + self.do_write_bit.argtypes = [ctypes.c_void_p, ctypes.c_int32, ctypes.c_int32, ctypes.c_char] + self.do_write_bit.restype = ctypes.c_int32 + self.buffer = ctypes.create_string_buffer(2) + # INIT OBJECTS + self.di_ctrl = self.di_create() + self.do_ctrl = self.do_create() + self.di_init_status = self.di_setSelectedDevice(self.di_ctrl, ctypes.byref(self.info)) + self.do_init_status = self.do_setSelectedDevice(self.do_ctrl, ctypes.byref(self.info)) + else: self.di_ctrl = InstantDiCtrl(self.info.Description) self.do_ctrl = InstantDoCtrl(self.info.Description) self.di_read = self.di_ctrl.readAny self.do_write_bit = self.do_ctrl.writeBit self.buffer = ctypes.create_string_buffer(2) - else: - self.di_create = libbiodaq.AdxInstantDiCtrlCreate - self.di_create.restype = ctypes.c_void_p - self.di_setSelectedDevice = libbiodaq.InstantDiCtrl_setSelectedDevice - self.di_setSelectedDevice.argtypes = [ctypes.c_void_p, ctypes.POINTER(self.DeviceInformation)] - self.di_setSelectedDevice.restype = ctypes.c_uint32 - # DIGITAL INPUTS READ FUNCTION - self.di_read = libbiodaq.InstantDiCtrl_ReadAny - self.di_read.argtypes = [ctypes.c_void_p, ctypes.c_int32, ctypes.c_int32, ctypes.c_char_p] - self.di_read.restype = ctypes.c_int32 - # DIGITAL OUTPUTS CLASS - self.do_create = libbiodaq.AdxInstantDoCtrlCreate - self.do_create.restype = ctypes.c_void_p - # SET SELECTED DEVICE - self.do_setSelectedDevice = libbiodaq.InstantDoCtrl_setSelectedDevice - self.do_setSelectedDevice.argtypes = [ctypes.c_void_p, ctypes.POINTER(self.DeviceInformation)] - self.do_setSelectedDevice.restype = ctypes.c_uint32 - # get ports - self.get_ports = libbiodaq.InstantDoCtrl_getPortDirection - self.get_ports.argtypes = [ctypes.c_void_p] - self.get_ports.restype = ctypes.POINTER(ctypes.c_void_p) - # DIGITAL OUTPUTS WRITE FUNCTION - self.do_write_bit = libbiodaq.InstantDoCtrl_WriteBit - self.do_write_bit.argtypes = [ctypes.c_void_p, ctypes.c_int32, ctypes.c_int32, ctypes.c_char] - self.do_write_bit.restype = ctypes.c_int32 - self.buffer = ctypes.create_string_buffer(2) - # INIT OBJECTS - self.di_ctrl = self.di_create() - self.do_ctrl = self.do_create() - self.di_init_status = self.di_setSelectedDevice(self.di_ctrl, ctypes.byref(self.info)) - self.do_init_status = self.do_setSelectedDevice(self.do_ctrl, ctypes.byref(self.info)) + def close_device(self): pass @@ -148,7 +156,7 @@ class USB_586x(Component): def get(self): self.mutex.lock() read = [] - if is_win: + if is_win or self.simulate: if self.simulate: read.append(bytearray(0)) else: diff --git a/src/main.py b/src/main.py index 6a99aac..1030df4 100644 --- a/src/main.py +++ b/src/main.py @@ -4,7 +4,6 @@ import faulthandler import logging import os import platform -# import pdb import signal import sys import traceback @@ -12,10 +11,10 @@ import weakref from datetime import datetime from pathlib import Path -if platform.system() == "Windows": +if platform.system().lower() == "windows": sys.path.append(f"{os.getcwd()}\src\components") - -#from components.usb_586x import USB_586x +else: + sys.path.append(f"{os.getcwd()}/src/components") app = None @@ -64,7 +63,7 @@ try: # IMPORT PROJECT ONLY AFTER SETTING UP SIGNAL, FAULTHANDLER AND LOGGHING from components import (ArchiveSynchronizer, Multicomp730424, Os_Label_Printer, RemoteAPI, - TecnaMarpossProvasetT3, TecnaScrewdriver) + TecnaMarpossProvasetT3, TecnaScrewdriver, USB_586x) from lib.db import Users from lib.helpers import ConfigReader from PyQt5.QtCore import QObject, QThread, pyqtSignal @@ -102,7 +101,7 @@ try: "remote_api": {"c": RemoteAPI, "k": {"main": self}}, "screwdriver": {"c": TecnaScrewdriver, "k": {"paused": True}}, "tecna_t3": {"c": TecnaMarpossProvasetT3, "k": {"paused": True}}, - #"digital_io":{"c":USB_586x,"k":{"paused":True}} + "digital_io":{"c":USB_586x,"k":{"paused":True}} } # VISION COMPONENT IS OPTIONAL AND DISABLED BY DEFAULT if "--vision" in sys.argv: