C-DAQ Hot Module Swap #665
Replies: 3 comments 2 replies
-
Can you be more specific? Does a method/property call not return? If you shared your code and annotated a bit what happens when it "hangs" that would be useful. FWIW, for this type of operation it is probably best to use the nisyscfg module (github). That is what is used for things like NI MAX and Hardware Configuration Utility to operate. Something like this will list all modules plugged into a cDAQ chassis (untested): import nisyscfg
with nisyscfg.Session() as session:
# Print user aliases for all National Instruments devices in the local system
filter = session.create_filter()
filter.is_present = True
filter.is_ni_product = True
filter.is_device = True
filter.connects_to_bus_type = nisyscfg.BusType.COMPACT_DAQ
for resource in session.find_hardware(filter):
print(resource.expert_user_alias[0]) The underlying implementation of both nisyscfg and what DAQmx uses for the System instance is similar, though. So what you're doing is probably also fine. |
Beta Was this translation helpful? Give feedback.
-
Every five seconds this runs to look for NI stuff: def _get_chassis(self) -> List[Dict]:
"""Get a list of all NI-DAQ chassis on the network."""
chassis_list = []
try:
device_filter = self.ni_syscfg.create_filter()
device_filter.is_ni_product = True
device_filter.is_chassis = True
devices = self.ni_syscfg.find_hardware(device_filter)
for device in devices:
chassis_info = {
"name": device.name,
"serial_number": device.serial_number,
"ip_address": device.tcp_ip_address,
"host_name": device.tcp_host_name,
"firmware_version": device.firmware_revision,
"model": device.product_name,
}
chassis_list.append(chassis_info)
except Exception as e:
logger.error(f"Error in _get_chassis: {str(e)}")
return chassis_list def _get_modules(self, chassis: str) -> List[Dict]:
"""Get a list of all modules for a given chassis."""
module_list = []
try:
device_filter = self.ni_syscfg.create_filter()
device_filter.is_ni_product = True
device_filter.is_chassis = False
device_filter.number_of_slots = False
device_filter.name = f"*{chassis}*"
devices = self.ni_syscfg.find_hardware(device_filter)
for device in devices:
module_info = {
"name": device.name,
"serial_number": device.serial_number,
"model": device.product_name,
"slot_number": device.slot_number,
"chassis": chassis,
}
logger.debug(f"Module found: {device.name}")
if device.name.startswith(chassis):
module_info["sub_module"] = False
else:
module_info["sub_module"] = True
module_list.append(module_info)
except Exception as e:
logger.error(f"Error in _get_modules for chassis {chassis}: {str(e)}")
return module_list If I hot plug/unplug a module in the c-daq the find_hardware call will hang. I will be debugging a bit more tomorrow to absolutely make sure that is where the hang is...but if I don't touch the physical modules all is well in the world. |
Beta Was this translation helpful? Give feedback.
-
This code worked for me. The main difference is that I don't have an ethernet chassis, which you seem to have. Anything else I got wrong? Definitely interested in where its hanging specifically from your debugging. import logging
import nisyscfg
import time
logger = logging.getLogger(__name__)
def get_chassis(session: nisyscfg.Session, ) -> list[dict]:
"""Get a list of all NI-DAQ chassis on the network."""
chassis_list = []
try:
device_filter = session.create_filter()
device_filter.is_ni_product = True
device_filter.is_chassis = True
devices = session.find_hardware(device_filter)
for device in devices:
chassis_info = {
"name": device.name,
"serial_number": device.serial_number,
# "ip_address": device.tcp_ip_address,
# "host_name": device.tcp_host_name,
# "firmware_version": device.firmware_revision,
"model": device.product_name,
"link_name": device.provides_link_name,
"is_present": device.is_present
}
chassis_list.append(chassis_info)
except Exception as e:
logger.error(f"Error in _get_chassis: {str(e)}")
return chassis_list
def get_modules(session: nisyscfg.Session, chassis_link_name: str) -> list[dict]:
"""Get a list of all modules for a given chassis."""
module_list = []
try:
device_filter = session.create_filter()
device_filter.is_ni_product = True
device_filter.is_chassis = False
device_filter.connects_to_link_name = chassis_link_name
devices = session.find_hardware(device_filter)
for device in devices:
module_info = {
"name": device.name,
"serial_number": device.serial_number,
"model": device.product_name,
"slot_number": device.slot_number,
"is_present": device.is_present
}
module_list.append(module_info)
except Exception as e:
logger.error(f"Error in _get_modules for chassis {chassis}: {str(e)}")
return module_list
if __name__ == "__main__":
while True:
with nisyscfg.Session() as session:
all_chassis = get_chassis(session)
for chassis in all_chassis:
print(f"Found {chassis['model']} (S/N: {chassis['serial_number']}): {chassis['name']} (Present: {chassis['is_present']})")
for module in get_modules(session, chassis['link_name']):
print(f"Found {module['model']} (S/N: {module['serial_number']}): {module['name']} (Present: {module['is_present']})")
for i in range(5):
print('.', end='', flush=True)
time.sleep(1.0)
print() |
Beta Was this translation helpful? Give feedback.
-
I have a service which polls every few seconds or so that the chassis is alive, modules present, etc in our c-daq chassis. I have noticed when hot plugging/unplugging a device on a c-daq chassis it will cause the System instance to hang or become unresponsive. I could catch that and restart it but wondered if I needed to handle hot actions in the chassis differently or not at all supported? Didn't want to post as an issue if it is working as intended.
Beta Was this translation helpful? Give feedback.
All reactions