From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
10-18-2013 05:49 AM
Hi Folks,
I have a NI DAQmx ANSI C problem which I hope someone will be able to help me with. Before I delve in to the problem I should state that I have a NI-USB-6008 device, which will be running on Windows 7, with which I wish to read digital input and analog input voltage. I will be writing an ANSI C library that will be compiled as a DLL using Microsoft Visual Studio 2010. The library will then be invoked via Java using JNA. I am an experienced Java programmer who is fairly comfortable programming in C. I have looked at the examples provided in C:\Programme\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\ and searched the forums, but havent found what I'm looking for yet. Appologies if this post is not in the correct forum.
I have a program which does most of what I need it to, but I am getting some unexpected results.
When calling the functions I'll outline below here are the results I am getting:
However after writing some unit tests I was able to confirm:
I then tried reducing the sample rate:
From these results I suspect that the problem lies in having to use sleep to provide the sampling rate that I am interested in.
I should point out that I have no issues with the Java integration, that seems to work fine.
Is there any NI DAQmx functions for the NI-USB-6008 device which will prevent me from calling sleep every n milliseconds?
Am I using the correct API calls?
Is my NI-USB-6008 device capable of doing what I need it to?
I want to expose a function which will read digital input. The prototype for the function will look something like this:
__declspec(dllexport) signed long readDigital(const char* deviceId, int line, int sampleRate, int numberOfSamples, INT_CALLBACK digitalReadingCallback, SHOULD_READ_CALLBACK shouldReadCallback, LOG_CALLBACK logCallback);
where:-
The desired behaviour for my readDigital function is:
My current implementation involves:
//
// Please not that this is the jist of the code that I am running some code has been missed out to try to improve the readability for this post.
//
readDigital(){
DAQmxCreateTask("",&taskHandle);
DAQmxCreateDIChan(taskHandle,digitalLineId,digitalLineName,DAQmx_Val_ChanForAllLines);
DAQmxStartTask(taskHandle);
while shouldRead() {
DAQmxReadDigitalLines(taskHandle,numberOfSamples,10.0,DAQmx_Val_GroupByChannel,data,dataSizeInBytes,&numberOfSamplesReadPerLine,&numberOfBytesPerSample,NULL);()
for each reading {
if we have no previous data {
digitalReadingCallback(value)
}
else{
if value is different to previous value {
digitalReadingCallback(value)
}
else {
do nothing
}
}
}
if shouldRead() {
sleep()
}
}
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
Thanks in advance for any help you can provide.
Cameron
10-18-2013 10:15 AM
As you can see in the specs for the 6008, the digital I/O is software timed. You simply cannot specify a sample rate. You take one sample at a time and expect some serious jitter in the sample rate due to windows.