advantech digital I/O ok on linux, tbt

This commit is contained in:
neo 2024-10-08 15:36:05 +02:00
parent 9bf55ee87f
commit 7ee96d63dd
5 changed files with 50 additions and 92 deletions

View File

@ -12,4 +12,5 @@ st-ten-10: st-ten-10
st-ten-11: st-ten-11 st-ten-11: st-ten-11
st-ten-12: st-ten-12 st-ten-12: st-ten-12
st-ten-13: st-ten-13 st-ten-13: st-ten-13
test-linux: test-linux

View File

@ -27,6 +27,8 @@ model: t3p
port: COM5 port: COM5
[digital_io] [digital_io]
# OUTPUT MAP FOR VALVE CONTROL UNITS
id: USB-5862,BID#0
# OUTPUT MAP FOR FIXTURE CONNECTOR # OUTPUT MAP FOR FIXTURE CONNECTOR
id_fixture: USB-5862,BID#0 id_fixture: USB-5862,BID#0
discard_idx:12 # BIT NUMBER OF THE I/0 MODULE USED FOR DISCARD SENSING discard_idx:12 # BIT NUMBER OF THE I/0 MODULE USED FOR DISCARD SENSING

10
init.sh
View File

@ -2,6 +2,7 @@
set -x set -x
here="$(realpath "$(dirname "$0")")" here="$(realpath "$(dirname "$0")")"
cd "$here" cd "$here"
mkdir -p "$here/tmp"
echo "---------- initialize venv ----------" echo "---------- initialize venv ----------"
sudo apt-get install python3 python3-venv python-is-python3 python3-pip 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 # # 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-get update
# sudo apt install -y build-essential docker # bazel libusb-1.0-0-dev libabsl-dev libflatbuffers-dev # 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 || : # # git clone https://github.com/tensorflow/tensorflow || :
# # cd tensorflow # # cd tensorflow
# # git pull # # git pull
@ -61,4 +60,11 @@ source "./venv/bin/activate" || source "./venv/Scripts/activate" || :
#python3 setup.py install #python3 setup.py install
#cd "$here" #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" cd "$here"

View File

@ -9,21 +9,14 @@ from PyQt5.QtWidgets import QMessageBox, QApplication
from .component import Component from .component import Component
is_win = platform.system().lower() == "windows"
if "--sim-io" not in sys.argv: if "--sim-io" not in sys.argv:
if is_win: from components.Automation.BDaq import *
from components.Automation.BDaq import * from components.Automation.BDaq.InstantDoCtrl import InstantDoCtrl
from components.Automation.BDaq.InstantDoCtrl import InstantDoCtrl from components.Automation.BDaq.InstantDiCtrl import InstantDiCtrl
from components.Automation.BDaq.InstantDiCtrl import InstantDiCtrl
else:
libbiodaq = ctypes.CDLL("/opt/advantech/libs/libbiodaq.so")
else: else:
from components.dummies.Automation.BDaq import * from components.dummies.Automation.BDaq import *
from components.dummies.Automation.BDaq.InstantDoCtrl import InstantDoCtrl from components.dummies.Automation.BDaq.InstantDoCtrl import InstantDoCtrl
from components.dummies.Automation.BDaq.InstantDiCtrl import InstantDiCtrl from components.dummies.Automation.BDaq.InstantDiCtrl import InstantDiCtrl
#is_win=False
#import components.dummies.libbiodaq as libbiodaq
from components.dummies.libbiodaq import ErrorCode from components.dummies.libbiodaq import ErrorCode
class USB_586x(Component): class USB_586x(Component):
@ -77,52 +70,19 @@ class USB_586x(Component):
# DIGITAL I/O CLASS # DIGITAL I/O CLASS
if not self.simulate: if not self.simulate:
self.log.info("OPENING USB MODULE...") self.log.info("OPENING USB MODULE...")
if is_win: try:
try: self.di_ctrl = InstantDiCtrl(self.info.Description)
self.di_ctrl = InstantDiCtrl(self.info.Description) self.do_ctrl = InstantDoCtrl(self.info.Description)
self.do_ctrl = InstantDoCtrl(self.info.Description) self.di_read = self.di_ctrl.readAny
self.di_read = self.di_ctrl.readAny self.do_write_bit = self.do_ctrl.writeBit
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
self.buffer = ctypes.create_string_buffer(2) self.buffer = ctypes.create_string_buffer(2)
# INIT OBJECTS self.io_ok=True
self.di_ctrl = self.di_create() except ValueError:
self.do_ctrl = self.do_create() QMessageBox.critical(None, "ERRORE", f"ERRORE I/O DIGITALE - VERIFICARE CONNESSIONE USB")
self.di_init_status = self.di_setSelectedDevice(self.di_ctrl, ctypes.byref(self.info)) exit(-1)
self.do_init_status = self.do_setSelectedDevice(self.do_ctrl, ctypes.byref(self.info)) self.io_ok = False
self.io_ok = True
time.sleep(1)
else: else:
self.di_ctrl = InstantDiCtrl(self.info.Description) self.di_ctrl = InstantDiCtrl(self.info.Description)
self.do_ctrl = InstantDoCtrl(self.info.Description) self.do_ctrl = InstantDoCtrl(self.info.Description)
@ -177,38 +137,30 @@ class USB_586x(Component):
max_retry = 3 max_retry = 3
while retry < max_retry: while retry < max_retry:
if is_win or self.simulate: if self.simulate:
if self.simulate: read = self.sim_in
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 break
else: else:
if self.io_ok: time.sleep(1)
ret = self.di_read(0, self.in_size) self.open_device()
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])
self.mutex.unlock() self.mutex.unlock()
return read return read
@ -239,10 +191,7 @@ class USB_586x(Component):
# print("set", byte, bit, not val, flush=True) # print("set", byte, bit, not val, flush=True)
if self.io_ok: if self.io_ok:
if not self.simulate: if not self.simulate:
if is_win: ret=self.do_write_bit(byte, bit, int(val))
ret=self.do_write_bit(byte, bit, int(val))
else:
ret=self.do_write_bit(self.do_ctrl, byte, bit, int(val))
else: else:
ret = ErrorCode.Success ret = ErrorCode.Success

View File

@ -9,7 +9,7 @@ from src.components.usb_586x import USB_586x
from lib.helpers import ConfigReader from lib.helpers import ConfigReader
test_config = ConfigReader() test_config = ConfigReader(system_id="test-linux")
if "USB-5862" in test_config["digital_io"]["id"]: if "USB-5862" in test_config["digital_io"]["id"]:
out_size = in_size = 16 out_size = in_size = 16