Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

PCI-6527 reading input/output after callback problem using NIDAQmx 8.0

Hello!

I encountered a small issue with NIDAQmx. Or at least I think it is. I have a task to reprogram one of our applications that run on Traditional NI DAQ and board PCI-6527 so, that it would run using NIDAQmx drivers in the future.
However, I encountered several difficulties for our application while migrating:
1) In NIDAQmx there is no function to read a single line input/output. You can only read the whole taske.
2) A driver doesn't seem to allow using same Callback function for multiple tasks. Which would be handy, since lots of code would otherwise be multiplied 24 times.
3) If I set change detection to a task, I cannot read startup input. If inputs are already set prior to application running.
4) And the beauty of it all... When change detection arrives, NIDAQmx only returns valid values for the first time that I access data via DAQmxReadDigitalLines. Every next call returns zero for all inputs, regardless of it's state.

Can you please elaborate on the issue, how could I read only one line at the time and not all 24? Also, I would need to know if there is any way of telling NIDAQmx to hold the data untill next change detection arrives.

Best regards,
    Vladimir Kocjancic
0 Kudos
Message 1 of 8
(4,879 Views)
Hello Vladimir,

I am not exactly sure what the end goal of your application is, so I cannot try to help get you on the right track.  However, I will try to answer the questions you have asked.

First, when you create a digital DAQmx task, you have an option in the DAQmxCreateDIChan command to specify to group lines into one or more digital channels.  In the C Reference Help installed with the driver, you can find the following:


lineGrouping     Specifies whether to group digital lines into one or more virtual channels. If you specify one or more entire ports in lines, you must set lineGrouping to DAQmx_Val_ChanForAllLines.

Value                                            Description
DAQmx_Val_ChanPerLine         One channel for each line
DAQmx_Val_ChanForAllLines     One channel for all lines


When you perform a DAQmx read, you will read in all the channels at once if they are grouped into the same task.

Next, I am not sure what you are trying to do with the callbacks accessing the same function.  I understand that you want multiple callbacks to execute the same function/code, however I do not know what callbacks you are using.  I assume you are trying to use the change detection event.  Can you confirm this?  If you are using the two change detection event, are you using two boards?

For 3, if you would like to know the state of your digital lines before you start your change detection event, you could perform a single software timed read of the lines before you start your change detection task.

For 4, this might just be a configuration problem.  Could you please make sure that you have the latest version of DAQmx (8.3).  Once you have the latest version, you can test one of the change detection shipping examples.  DAQmx ships with many examples.  I assume you are using c or c++ to program this.  If so, you can typically find the ansi c change detection example here:

C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Events\Signal\Change Detection\Read Dig Chan-Change Detection Event

I hope this helps.

Jesse O.
Applications Engineering
National Instruments


Jesse O. | National Instruments R&D
Message 2 of 8
(4,833 Views)
Hello Jesse,

Sorry for lack of information given. This project is about regulating some 20 devices, which rarely use more than one input/output line. And I am using Visual C++ 2003 with NiDAQmx 8.1.
Now the problem is, that I would like to control each line (or rarely two lines) seperately. This was easily done in Traditional DAQ with reading line or two when change detection occured. Now, when change detection occured, the value of the input is available only when I read it the first time after the event occured. All later read calls before next change  detection event retrieve me nothing but zeros for all inputs. This could be a thing with drivers and settings, but I am not sure wether there was that kind of significant correction made in the 8.3.
Back to the problem. After seing that read funciton returns data only once for all inputs in one task, I tried to create a task for nearly every input and set it to detect changes, which seemed a logical thing to do. It worked even worse. It returned 0 for some inputs and 204 for others? And those with 204 were definitely not the ones that were on. Neither were those with 0.
Any ideas, what I could do about this?

Regarding point 3... In traditional DAQ, you were able to read the input even if you already set change detection event. If it doesn't work the same for DAQmx, I'll apparently will have to read the input before setting change detection event.,

Point 4 is a bit dodgy. I tried to run an example on DAQmx 8.1 and the example is buggy. It shuts down itself if change detection event triggers, while it is reading inputs. With serious error, I might add. Luckily, it doesn't restart the computer. It works fine if you wait until timeout is due.
0 Kudos
Message 3 of 8
(4,830 Views)

Hello Vladimir,

To clarify a little more, when using change detection/notification in DAQmx you configure change detection for the task with the DAQmx timing VI.  When you use the timing VI, you set the condition for when new data is available.  In the case of change notification you have available data everytime there is a change in one of the lines you are looking at. 

This means that if you perform a DAQmx read it will wait for a change to occur before returning.  If no change occurs within the amount of time specified by the timeout parameter of the read function, it will return invalid data along with an error status code.  I believe this is what is happening to you.  This is why performing a single software timed read before you start your change notification task allows you to read valid data.

Secondly, you are limited to a single change detection event.  For example, if you try to create a change detection task for Dev1/port0/line0, and another change detection task for Dev1/port0/line1 you should receive error -50103 which states that "The specific resource is reserved.  The operation could not be completed as specified."

Finally, I have tried the change detection example I mentioned to you in both Visual C++ 6 and .NET 2003.  I have had no problems running these examples.  I have tried all combinations of running and closing the examples with no problems. Could be more specific into exactly what you did to get the program to crash.

Regards,

Jesse O.
Applications Engineering
National Instruments

Jesse O. | National Instruments R&D
0 Kudos
Message 4 of 8
(4,802 Views)
Hi Jesse!

First regarding that error. It is 'Your program was shutdown by Windows and it must be restarted. ...' sort of error. Anyway, since it works with you, I will download NiDAQmx 8.3 and compile it with that library.

Regarding change detection, let us see if I got things right now.
Based on what you told me, if I want to read when change detection event occur, I can only do it with one task at the same time. Meaning that either, I have a task for all inputs, where this is set, or I can't detect a change on inputs not defined in a task. Inputs in a change detection event task can be read only when change detection occurs for this task. Otherwise they return zeros. Also, I can read this inputs only once after change detection occured, since after that all reads return zeros. Is that about how it should be?

I have a couple of questions thought.
1) Let us say I have all inputs in one task (I will call it Task1) that has change detection event set and then every input in some other tasks (TaskX, where x represents number from 2 to number of inputs+1) that does not have change detection event set. When change detection triggers, Task1 will start i.e. callback function, but I can read inputs from it only once. If I then use TaskX to read input, will it return the current state on the board, or zero for that input?

2) I am still a bit confused about that 'timeout' parameter. In DAQmx C reference help, I got the impression that this should represent the largest amount of time in which the Read function should complete. Otherwise an error is returned. However, my exeprience with it is that it waits for the period of time set as timeout and returns when the timeout runs out, even if it did read all inputs way before the timeout was done. Is that how it is supposed to act? Because, I dare not to think what would happen, if I set timeout to -1 or infinte in that case. And that error above happens if timeout still has not run out and another change detection happens.

That would be all for now. However, I am still a bit vague on an inssue as to how NiDAQmx would make development easier, comparing to Traditional NiDAQ.
Thank you for your response.
0 Kudos
Message 5 of 8
(4,785 Views)
Hello Vladimir,

If I understand your first question correctly, you want to have two tasks for the same digital line.  One task that performs change detection and the other task that just performs software timed digital input?  If so, this is not possible.  If you try to setup a task to do this, you will get error -200587 which states that the "Requested operation could not be performed, because the specified digital lines are either reserved or the device is not present in NI-DAQmx. It is possible that these lines are reserved by another task..."

Instead, you could have one software timed task read the input once before you start your change detection task.  Then you have the digital line state in your application.  You would be notified of any future changes.  If you store this updated value in a variable you always know the last data available on the digital lines.

It looks like you want to perform some operations for specific line changes.  To do this, you could read in the current value, compare it to the old value (stored in a variable) and decide from there what code to execute.  Similar to how the example works.

Finally, you mentioned that you are not getting any data back from the change detection read until a timeout occurs.  In running the code (on another board), I found that I required multiple changes to occur before I was able to read data.  I think this might be causing your problems.  I modified the code so that after only a single change data is available in your application.  To do this, you can change the data transfer mechanism.  I have copied the section of code from the example program, plus the modification I made below:

    DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxCreateDIChan(taskHandle,"Dev2/port0/line0:7","",DAQmx_Val_ChanPerLine));
    DAQmxErrChk (DAQmxCfgChangeDetectionTiming(taskHandle,"Dev2/port0/line0:7","Dev2/port0/line0:7",DAQmx_Val_ContSamps,1));
    DAQmxErrChk (DAQmxRegisterSignalEvent(taskHandle,DAQmx_Val_ChangeDetectionEvent,0,ChangeDetectionCallback,NULL));
    DAQmxErrChk (DAQmxGetTaskNumChans(taskHandle,&numLines));
    DAQmxErrChk (DAQmxSetDIDataXferMech(taskHandle, "Dev2/port0/line0:7", DAQmx_Val_Interrupts ))


Regards,

Jesse O.
Applications Engineering
National Instruments



Jesse O. | National Instruments R&D
0 Kudos
Message 6 of 8
(4,748 Views)
Hi Jesse!

Sorry to be absent for so long. I tried your approach and it works well enough.

I would just like to point out htat example for writing outputs has a bug. A value for diabling output channel cannot be 1, but maximum value of variable type. So if variable is 32 but, the value put to output should be 0xFFFFFFFF and not 0x00000001 as is used in test program.

I once again thank you for your time and for your advice and explanation on how NIDAQmx works.

Best regards
0 Kudos
Message 7 of 8
(4,586 Views)

Hello again,

Can you please provide more detail about the problem you were seeing.  The previous examples we were talking about involved digital input and change detection.  You mention that there is a problem with the digital output example.  Which example are you referring to, and can you explain a little more about the problem you are seeing?

Regards,

Jesse O.
Applications Engineering
National Instruments



Jesse O. | National Instruments R&D
0 Kudos
Message 8 of 8
(4,567 Views)