mcculw
mcculw copied to clipboard
Example python code digital_in.py always failed once during two continue executions
Environment:
- Device: USB-1024HLS
- OS: Windows 10 Enterprise 22H2
- Connection: USB
- Python: 3.12.5, 3.10.4, 3.10.6 (All same error)
- mcculw: 1.0.0
- cbw64.dll: product version: 6.74; file version: 1.94.0.0
- MccDaq.dll: product version: 6.74; file version 2.9.00
Run https://github.com/mccdaq/mcculw/blob/master/examples/console/digital_in.py multiple times: 1st:
C:\code\mcculw\.venv\Scripts\python.exe C:\code\mcculw\examples\console\digital_in.py
Found 1 DAQ device(s):
USB-1024HLS (168B4DE) - Device ID = 127
Active DAQ device: USB-1024HLS (168B4DE)
FIRSTPORTA Value: 0
Bit 0 Value: 0
Process finished with exit code 0
2nd:
C:\code\mcculw\.venv\Scripts\python.exe C:\code\mcculw\examples\console\digital_in.py
Found 1 DAQ device(s):
USB-1024HLS (0) - Device ID = 127
Error: The DAQ device does not support digital I/O
Process finished with exit code 0
It will keep this pattern if we keep the execution loop.
Please notice that on the error case, device.unique_id
is always 0 and ports number of device configuration is 0 that cause the error being thrown.
https://github.com/mccdaq/mcculw/blob/master/examples/console/console_examples_util.py#L28
for device in devices:
print(' ', device.product_name, ' (', device.unique_id, ') - ',
'Device ID = ', device.product_id, sep='')
It seems some resource is not cleaned up in succeed case, but always be released on failed case.
I have another piece of code bypass the configuration validation but still return the same result. It's just a different error thrown. Same pattern (1st succeed, 2nd failed) if we continue the execution loop.
from mcculw import ul
from mcculw.enums import InterfaceType, DigitalPortType
def reproduce(board_num: int, counter: int) -> None:
ul.ignore_instacal()
devices = ul.get_daq_device_inventory(InterfaceType.ANY)
assert len(devices) > 0
selected = devices[0] # USB-1024HLS
ul.create_daq_device(board_num, selected)
registered = ul.get_board_number(selected)
assert registered == board_num
data_val = ul.d_in(board_num, DigitalPortType.FIRSTPORTA)
print(f'data_val: {data_val} @ {counter}')
bit_val = ul.d_bit_in(board_num, DigitalPortType.FIRSTPORTA, 0)
print(f'bit_val: {bit_val} @ {counter}')
ul.release_daq_device(board_num)
if __name__ == "__main__":
reproduce(0, 0)
1st:
C:\code\programs\theia\mcc_usb_1024\.venv\Scripts\python.exe C:\code\programs\theia\mcc_usb_1024\integration\reproduce.py
data_val: 0 @ 0
bit_val: 0 @ 0
Process finished with exit code 0
2nd:
C:\code\programs\theia\mcc_usb_1024\.venv\Scripts\python.exe C:\code\programs\theia\mcc_usb_1024\integration\reproduce.py
Traceback (most recent call last):
File "C:\code\programs\theia\mcc_usb_1024\integration\reproduce.py", line 27, in <module>
reproduce(0, 0)
File "C:\code\programs\theia\mcc_usb_1024\integration\reproduce.py", line 18, in reproduce
data_val = ul.d_in(board_num, DigitalPortType.FIRSTPORTA)
File "C:\code\programs\theia\mcc_usb_1024\.venv\lib\site-packages\mcculw\ul.py", line 2705, in d_in
_check_err(_cbw.cbDIn(board_num, port_type, byref(data_value)))
File "C:\code\programs\theia\mcc_usb_1024\.venv\lib\site-packages\mcculw\ul.py", line 6128, in _check_err
raise ULError(errcode)
mcculw.ul.ULError: Error 1: Invalid board number.
Process finished with exit code 1