Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Segmentation fault in stop method of nidaqmx Python package

I am getting frequent segmentation faults while trying to stop (and/or close) a nidaqmx task using the Python nidaqmx package, version 0.5.7. One time I got an 'illegal instruction' error.

 

Can anyone see a problem with the code? Has anyone had this issue? Was there a solution or did you need to use something other than NI products?

 

The code snippet is in a sub-routine and triggers a pulsed laser, at the clock rate indicated, while a camera grabs frames and a motor moves a sample.

 

self.current_task = nidaqmx.Task('lissajous')
self.current_task.ao_channels.add_ao_voltage_chan(self.x_channel)
self.current_task.ao_channels.add_ao_voltage_chan(self.y_channel)
self.current_task.ao_channels.add_ao_voltage_chan(self.aom_channel)
self.current_task.timing.cfg_samp_clk_timing(rate=pulse_rate_clock, sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS, samps_per_chan=len(x))
self.current_task.export_signals.export_signal(signal_id=nidaqmx.constants.Signal.SAMPLE_CLOCK,output_terminal="PFI1")
self.current_task.write(data, auto_start=False)
self.current_task.start()

The calling function lets the above task run while grabbing frames from the camera, which averages hundreds of the laser pulses in each frame. After a specified amount of motor movement, the camera is stopped and the the stop_scan_pattern sub-routine below is called to stop the task and (hopefully) free up memory (The del call didn't seem to help either, so it's commented out):

 

def stop_scan_pattern(self):
    # stop the NIDAQmx task, release resources, clear it
    # then explicitly do away with our task object
    if self.current_task:
        self.current_task.stop()
        self.current_task.wait_until_done()
        self.current_task.close()   # stop, release, clear in DLL
        #del self.current_task       # attempt to force a cleanup
    else:
        print('No scan task to stop!')

 

Intermittently, but way too often, I get a segmentation fault. I'm using the Python faulthandler package, which blames the problem on the stop() method in task.py within the NI package. At times it blamed close() so we added the wait_until_done() method to address that, now it seems to be happening in the first close(), not even making it into wait_until_done().

 

Faults are happening after 100 or so cycles, and it seems like some days are clearly bad while others are problem free, for essentially the same types of operations.

 

I am running Python 3.6.8, with nidaqmx module 0.5.7, within VS Code 1.46.1, on Windows 10, using a USB-6343 DAQ.

 

Any help would be greatly appreciated!

0 Kudos
Message 1 of 1
(1,773 Views)