Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxBaseResetDevice basic use in Mac OS X, NI-DAQmx Base Version 2.0

I am using NI-DAQmx Base Version 2.0 installed on a PowerPC G5 with Mac OS X (Version 10.4.5). I have a USB-6501.

I trimmed down one of the example C-files in "NI-DAQmx Base/examples/dio" folder to be the minimum necessary to make a single call to the DAQmxBaseResetDevice command. The file is short enough that I just pasted it below.

When I run the application lsdaq.app, it indicates that my USB-6501 is called:

NI USB-6501: "Dev1" (USB0::0x3923::0x718A::011957D3::RAW)

So as you can see below, I declare it as "Dev1" in my C-code.

But when I run it the file from the Terminal prompt (i.e., $ ./reset_UNIX), I get the following error:

DAQmxBase Error -200220: Device identifier is invalid.

Please let me know if there is anything wrong with my code or if there is a know issue with what I have described. As addtional background, I have had success creating tasks and channels, and reading and writing in more involved code with identifiers like "Dev1/port2/line0:3" in my custom MEXMAC-files for use in MATLAB 7.1. But I feel the need at this point to be able to reset my device since I seem to get the DAQmxErrorPhysicalChanDoesNotExist (-200170) error when I stop (i.e., kill) and restart my MEXMAC-file in the same MATLAB session, possibly because previous tasks are not stopped and cleared.

------------------------------

Code for reset_UNIX.c follows:

#include
#include
#define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } }
int main (int argc, char *argv[])
{
int32 error = 0;
char errBuff[2048];
// DAQmxResetDevice parameter.
const char deviceName[] = "Dev1";
// Reset device.
DAQmxErrChk (DAQmxBaseResetDevice (deviceName));
Error:
if (DAQmxFailed (error))
DAQmxBaseGetExtendedErrorInfo (errBuff, 2048);
if (error)
printf ("DAQmxBase Error %d: %s\n", error, errBuff);
}

------------------------------

Daniel Shima
Vanderbilt Vision Research Center
0 Kudos
Message 1 of 7
(4,510 Views)

Daniel,

It looks like that code should be working.  I'm going to try to recreate it here on my end...I've already gotten it to compile and run on my machine, now I just have to get my hands on a 6501 to test it out.  I'll update you as soon as I try it.

-Justin

0 Kudos
Message 2 of 7
(4,494 Views)
Justin,
 
Looking forward to hearing how it goes on your end.  By the way, in pasting my short program to the forum, somehow "NIDAQmxBase.h" and "stdio.h" disappeared from my two include declarations.  Obviously you figured that out yourself, but just wanted to verify to anyone else who might review my post that those header files were definitely in the code I compiled.
 
Daniel Shima
Vanderbilt Vision Research Center
 
0 Kudos
Message 3 of 7
(4,489 Views)
So I couldn't get a 6501, but I DID try running the program using a USB-6008.  I got the same error that you're seeing...and I'm still not sure why!  Just wanted to give you a quick update...I'll let you know when I find out more.
 
-Justin
0 Kudos
Message 4 of 7
(4,479 Views)

I ended up creating 2 identical programs to reset the hardware...one using DAQmx and the other using DAQmx Base.  The DAQmx program worked fine, but the DAQmx Base version threw that same error. 

It looks like this is a bug in the DAQmx Base code.  I have submitted a bug report on the issue, and am hoping for a response sometime next week.  I'll try to post back as soon as I get an update on the issue.

-Justin

0 Kudos
Message 5 of 7
(4,461 Views)
Justin,
 
Very interesting comparison test, and thank you very much for submitting a bug report about it.  Always nice to present an only slightly-different working situation along the non-working one to those who might be able to help you.  I remain very interested in any response you get on it.
 
As a parallel effort on my end, I redesigned my MATLAB M-code to allow the user to press a key to quit which calls a 3rd custom MEX-file to perform a DAQmxBaseStopTask and a DAQmxBaseClearTask on each my four running USB-6501 tasks.  I avoided doing this before for fear that the extra keyboard check would take too much time each iteration and the program would not be able to loop as fast.  But my test today showed that the keyboard check does not take a significant amount of time, so I will keep the modification in place since it a nicer way to code things.
 
More relevant to this thread, and not surprisingly, properly stopping and clearing USB-6501 tasks before exiting the MATLAB M-code seems to keep subsequent runs of the same M-code from having the problems cause by just ungracefully killing the running MATLAB process as I was before.  (i.e., the problems that made me interested in resetting my USB-6501 in the first place)  That was probably leaving device states and task handles hanging in a problematic state which could not be recovered without restarting MATLAB or even restarting the Mac.
 
But nonetheless, for the inevitable occasional circumstances when the running process in MATLAB is killed ungracefully for whatever reason, I remain interested in having the option to reset the USB-6501 from within MATLAB, so I look forward to hearing back about DAQmxBaseResetDevice.  Thanks again.
 
Daniel Shima
Vanderbilt Vision Research Center
0 Kudos
Message 6 of 7
(4,446 Views)

Hi Daniel,

Thank you very much for your patience in this matter.  I have heard back from R&D on the issue, and it's definitely a bug in the code.  The reset function fails to initialize the device list when it is called, which is why we were getting that "device not found" error.  This bug will be fixed in the next release.

As a workaround until then, call the create task function followed by the clear task function first, then call the reset device function. This will work for C as well as for the LabVIEW users out there. For LabVIEW, you can also run the config tool inside of LabVIEW first, then call Reset Device.  The extra step is added in to correctly load the device list so that the device is found correctly when the reset function is called.

I hope this helps.  Again, sorry for the long delay!

Thanks,

Justin M
National Instruments

0 Kudos
Message 7 of 7
(4,430 Views)