From 7ee96d63dd37f502c66b1e39d9ad1cea5b94c208 Mon Sep 17 00:00:00 2001 From: neo Date: Tue, 8 Oct 2024 15:36:05 +0200 Subject: [PATCH] advantech digital I/O ok on linux, tbt --- config/machine_settings/hostnames.ini | 1 + config/machine_settings/test-linux.ini | 2 + init.sh | 10 +- src/components/usb_586x.py | 127 ++++++++----------------- src/test_usb586x.py | 2 +- 5 files changed, 50 insertions(+), 92 deletions(-) diff --git a/config/machine_settings/hostnames.ini b/config/machine_settings/hostnames.ini index dfdc1c7..3299c30 100644 --- a/config/machine_settings/hostnames.ini +++ b/config/machine_settings/hostnames.ini @@ -12,4 +12,5 @@ st-ten-10: st-ten-10 st-ten-11: st-ten-11 st-ten-12: st-ten-12 st-ten-13: st-ten-13 +test-linux: test-linux diff --git a/config/machine_settings/test-linux.ini b/config/machine_settings/test-linux.ini index 490c522..97e9295 100644 --- a/config/machine_settings/test-linux.ini +++ b/config/machine_settings/test-linux.ini @@ -27,6 +27,8 @@ model: t3p port: COM5 [digital_io] +# OUTPUT MAP FOR VALVE CONTROL UNITS +id: USB-5862,BID#0 # OUTPUT MAP FOR FIXTURE CONNECTOR id_fixture: USB-5862,BID#0 discard_idx:12 # BIT NUMBER OF THE I/0 MODULE USED FOR DISCARD SENSING diff --git a/init.sh b/init.sh index 9b612e6..dc2528c 100755 --- a/init.sh +++ b/init.sh @@ -2,6 +2,7 @@ set -x here="$(realpath "$(dirname "$0")")" cd "$here" +mkdir -p "$here/tmp" echo "---------- initialize venv ----------" sudo apt-get install python3 python3-venv python-is-python3 python3-pip @@ -30,8 +31,6 @@ source "./venv/bin/activate" || source "./venv/Scripts/activate" || : # # echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list # # sudo apt-get update # sudo apt install -y build-essential docker # bazel libusb-1.0-0-dev libabsl-dev libflatbuffers-dev -# mkdir -p "$here/tmp" -# cd "$here/tmp" # # git clone https://github.com/tensorflow/tensorflow || : # # cd tensorflow # # git pull @@ -61,4 +60,11 @@ source "./venv/bin/activate" || source "./venv/Scripts/activate" || : #python3 setup.py install #cd "$here" +echo "---------- INSTALL ADVANTECH DAQNAVI DRIVER ----------" +cd "$here/tmp" +wget --continue "https://advdownload.advantech.com/productfile/Downloadfile5/1-2MULY66/DAQ_Linux_4.0.11.0_64bit.run" +chmod +x DAQ_Linux_4.0.11.0_64bit.run +sudo ./DAQ_Linux_4.0.11.0_64bit.run + +echo "---------- INIT DONE ----------" cd "$here" diff --git a/src/components/usb_586x.py b/src/components/usb_586x.py index c4a954b..af8c073 100644 --- a/src/components/usb_586x.py +++ b/src/components/usb_586x.py @@ -9,21 +9,14 @@ from PyQt5.QtWidgets import QMessageBox, QApplication from .component import Component -is_win = platform.system().lower() == "windows" - if "--sim-io" not in sys.argv: - if is_win: - from components.Automation.BDaq import * - from components.Automation.BDaq.InstantDoCtrl import InstantDoCtrl - from components.Automation.BDaq.InstantDiCtrl import InstantDiCtrl - else: - libbiodaq = ctypes.CDLL("/opt/advantech/libs/libbiodaq.so") + from components.Automation.BDaq import * + from components.Automation.BDaq.InstantDoCtrl import InstantDoCtrl + from components.Automation.BDaq.InstantDiCtrl import InstantDiCtrl else: from components.dummies.Automation.BDaq import * from components.dummies.Automation.BDaq.InstantDoCtrl import InstantDoCtrl from components.dummies.Automation.BDaq.InstantDiCtrl import InstantDiCtrl - #is_win=False - #import components.dummies.libbiodaq as libbiodaq from components.dummies.libbiodaq import ErrorCode class USB_586x(Component): @@ -77,52 +70,19 @@ class USB_586x(Component): # DIGITAL I/O CLASS if not self.simulate: self.log.info("OPENING USB MODULE...") - if is_win: - try: - 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) - self.io_ok=True - except ValueError: - QMessageBox.critical(None, "ERRORE", f"ERRORE I/O DIGITALE - VERIFICARE CONNESSIONE USB") - exit(-1) - self.io_ok = False - - time.sleep(1) - 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 + try: + 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) - # 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)) - self.io_ok = True + self.io_ok=True + except ValueError: + QMessageBox.critical(None, "ERRORE", f"ERRORE I/O DIGITALE - VERIFICARE CONNESSIONE USB") + exit(-1) + self.io_ok = False + + time.sleep(1) else: self.di_ctrl = InstantDiCtrl(self.info.Description) self.do_ctrl = InstantDoCtrl(self.info.Description) @@ -177,38 +137,30 @@ class USB_586x(Component): max_retry = 3 while retry < max_retry: - if is_win or self.simulate: - if self.simulate: - read = self.sim_in + if self.simulate: + read = self.sim_in + break + else: + if self.io_ok: + ret = self.di_read(0, self.in_size) + if ret[0].value == ErrorCode.Success.value: + self.buffer = ret[1] + for byte_num in range(len(self.buffer)): + byte = self.buffer[byte_num] + read.append([bool(byte & m) for m in self.masks]) + else: + self.buffer = None + self.log.error(f"READ ERROR") + self.di_ctrl.dispose() + self.do_ctrl.dispose() + self.io_ok = False + + + if self.io_ok: break else: - if self.io_ok: - ret = self.di_read(0, self.in_size) - if ret[0].value == ErrorCode.Success.value: - self.buffer = ret[1] - for byte_num in range(len(self.buffer)): - byte = self.buffer[byte_num] - read.append([bool(byte & m) for m in self.masks]) - else: - self.buffer = None - self.log.error(f"READ ERROR") - self.di_ctrl.dispose() - self.do_ctrl.dispose() - self.io_ok = False - - - if self.io_ok: - break - else: - time.sleep(1) - self.open_device() - else: - self.di_read(self.di_ctrl, 0, self.in_size, self.buffer) - - for byte_num in range(len(self.buffer)): - byte = int.from_bytes(self.buffer[byte_num], "little") - read.append([bool(byte & m) for m in self.masks]) - + time.sleep(1) + self.open_device() self.mutex.unlock() return read @@ -239,10 +191,7 @@ class USB_586x(Component): # print("set", byte, bit, not val, flush=True) if self.io_ok: if not self.simulate: - if is_win: - ret=self.do_write_bit(byte, bit, int(val)) - else: - ret=self.do_write_bit(self.do_ctrl, byte, bit, int(val)) + ret=self.do_write_bit(byte, bit, int(val)) else: ret = ErrorCode.Success diff --git a/src/test_usb586x.py b/src/test_usb586x.py index 0d55c44..b055474 100644 --- a/src/test_usb586x.py +++ b/src/test_usb586x.py @@ -9,7 +9,7 @@ from src.components.usb_586x import USB_586x from lib.helpers import ConfigReader -test_config = ConfigReader() +test_config = ConfigReader(system_id="test-linux") if "USB-5862" in test_config["digital_io"]["id"]: out_size = in_size = 16