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-12: st-ten-12
st-ten-13: st-ten-13
test-linux: test-linux

View File

@ -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

10
init.sh
View File

@ -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"

View File

@ -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")
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,7 +70,6 @@ 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)
@ -91,38 +83,6 @@ class USB_586x(Component):
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)
# 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
else:
self.di_ctrl = InstantDiCtrl(self.info.Description)
self.do_ctrl = InstantDoCtrl(self.info.Description)
@ -177,7 +137,6 @@ class USB_586x(Component):
max_retry = 3
while retry < max_retry:
if is_win or self.simulate:
if self.simulate:
read = self.sim_in
break
@ -202,13 +161,6 @@ class USB_586x(Component):
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()
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))
else:
ret = ErrorCode.Success

View File

@ -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