ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Buffer problem when using mex file created with Math Interface Toolkit

I have a vi which does simultaneous clocked AO and digital pattern output on a PCI-6221, with finite samples. It works perfectly in Labview.
 
I have created a mex file from it using math interface toolkit. This also works perfectly in Matlab, but only once! The second time I try to run the function, I get the error -200288 Attempted to write a sample beyond the final sample generated.
 
My vi is tidy - the sequence goes:
 
[first set up the timing and write the data to the buffers, then...]
DAQmx Start Task
DAQmx Wait Until Done
DAQmx Stop Task (not sure if strictly necessary, but can't do any harm)
DAQmx Clear task
 
So, if I am ending with a Clear Task,  why is at least one of the buffers and the pointer into the buffer being retained in Matlab between calls to the function?
 
Chris
 
0 Kudos
Message 1 of 3
(3,267 Views)

More information...

If I try to call the function a 3rd time in Matlab, Matlab hangs.

I tried setting the DAQmx Write properties Relative to and Offset to "First sample" and zero respectively, before the data is written to the buffers. I really thought this would fix the problem because there is no way it should be trying to write data after the end of the buffer if I have specifically told it to write at the start. It doesn't make any difference, I still get the same error.

I noticed that after I have used the function once in Matlab, I cannot run the corresponding vi in Labview because the hardware resource (ie. the PCI-6221) is in use by another program. I think this is a clue to what's going on - Matlab is not releasing the DAQ card after the function executes.

 

0 Kudos
Message 2 of 3
(3,246 Views)

OK, found the cause of the problem - I had not cleared the digital output task.

 

0 Kudos
Message 3 of 3
(3,244 Views)