08-24-2023 05:53 PM
I've having a clash when trying to read data from my USB-6001 using NIDAQMX in Python when also connecting to a third party NI-VISA device (thorlabs DMP40) via python. When the NI-VISA device is initialized, then my script fails to read from the USB-6001. The reason is that it is trying to, erroneously, communicate with the NI-VISA device (apparent from the error it throws, which includes the NI-VISA device USB address) instead of the USB-6001 at Dev1. Why?? Works fine if I do not initialize the NI-VISA device. I've checked with NI MAX and indeed the USB 6001 is still called Dev 1, whether or not the NI-VISA device is initialized.
Any help greatly appreciated!
Example of the error:
import nidaqmx as ni
###NI-VISA device initialization code###
with ni.Task() as task:
task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
DaqError: Syntax for a range of objects in the input string is invalid.
For ranges of objects, specify a number immediately before and after every colon (":") in the input string. Or, if a name is specified after the colon, it must be identical to the name specified immediately before the colon. Colons are not allowed within the names of the individual objects.
Invalid String: USB0::0x1313::0x8016::M00898148:;0::RAW ##This is the address of the NI-VISA device... NOT the USB-6001
Task Name: _unnamedTask<0>
Status Code: -200498
08-25-2023 07:37 AM
Can you post your NI-VISA code? It is possible to do register-level programming on USB-6001 using NI-VISA hence your NI-VISA code might have blocked it.
Besides, what are your OS, NI-VISA and NI-DAQmx versions?
08-25-2023 11:35 AM
The NI-VISA device is controlled via a wrapper to some c functions, so I'm not sure if the Python code is going to be that illuminating (see below).
I'll post version info when I'm back in the lab.
Is there any way to ignore the NI-VISA device/address when using NIDAQMX python calls? I can't be the first person to try to do both simultaneously...
#######
Example code Python code for the NI-VISA device would be something like this. Basically Python loads a dll and accesses c functions to initialize the mirror (the device).
######
import os
import time
from ctypes import *
# Please note that the DMP40 devices have two driver files:
#
# TLDFM: Driver with the basic functions to control the DMP40 mirror segments.
# TLDFMX: Extended driver for mirror segment control using Zernike coefficient.
#os.chdir(r"C:\Program Files\IVI Foundation\VISA\Win64\Bin")
lib = cdll.LoadLibrary("C:\Program Files\IVI Foundation\VISA\Win64\Bin\TLDFM_64.dll")
libX = cdll.LoadLibrary("C:\Program Files\IVI Foundation\VISA\Win64\Bin\TLDFMX_64.dll")
# Detect and initialize DMP40 device
instrumentHandle = c_ulong()
IDQuery = True
resetDevice = False
resource = c_char_p(b"")
deviceCount = c_int()
# Check how many DMP40 are connected
lib.TLDFM_get_device_count(instrumentHandle, byref(deviceCount))
if deviceCount.value < 1 :
print("No DMP40 device found.")
exit()
else:
print(deviceCount.value, "DMP40 device(s) found.")
print("")
# Connect to the first available DMP40
# Use TLDFMX_init to use functions in the extended driver as well
lib.TLDFM_get_device_information(instrumentHandle, 0, 0, 0, 0, 0, resource)
if (0 == libX.TLDFMX_init(resource.value, IDQuery, resetDevice, byref(instrumentHandle))):
print("Connection to first DMP40 initialized.")
else:
print("Error with initialization.")
exit()
print("")
##############