Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Digital IO Async Callback with Read

I am developing an application using Measurement Studio 2005 and I am having a design issue that I hope someone can help me with.  I am using an NI USB-6229 digital input channel to read the value of a contact switch to find out if the switch is open or closed.  While the application is running, I will need to know when the switch transitions from high to low, and low to high.  However I will also need to read the current value of the switch at startup and a couple of times during the run cycle.
 
I am currently using an asynchronous callback to a function that will handle the transitions of the channel.  The problem that I am having is that I can't read the current digital value of the channel without getting a runtime error saying that the channel reasources are in use.  Is it possible to read the channel value without ending the asynchronous callback method or is there another solution that I haven't tried?  I would like to avoid starting an stopping this method continuously, but if that is the only way I would like to know that too.

Thanks for your help!
 
   
0 Kudos
Message 1 of 4
(3,706 Views)
Hello bryan C.,

Looking at your overall application, I think you may be able to use change detection to accomplish your task. According to this document, the USB-6229 supports change detection, so it shouldn't be a problem for you. Change detection is described in this tutorial, but basically it allows you to monitor lines for changes and only latch data when a change occurs. This should also allow you to read the current state by checking the last pattern that was latched. Since data is stored on changes, knowing the current state is the same as knowing the last value and knowing that no change has occurred. This will also allow you to avoid starting and stopping the task continuously. There is an NI-DAQmx example for change detection in Measurement Studio 2005, which is installed to the following location by default:

C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DotNET2.0\Digital\Read Values\ReadDigChan_ChangeDetection


Matt Anderson

Hardware Services Marketing Manager
National Instruments
0 Kudos
Message 2 of 4
(3,691 Views)
Matt A.


You mentioned checking the last pattern that was latched, how would you do that in VB .NET 2005? I have both the asynchronous and digital change event detection setup and working, but I cannot figure out how to capture any data from the LAST event. The tutorial you linked to regarding digital change event and masking bits seemed promising, but can you get direct access to those bits?

The reason I highlight LAST is I am having problems with a bouncing switch. I have done as much hardware debouncing as I can, but there is still a little ripple. For both a change event and asynchronous read, the buffer of samples to read goes from 20-100 depending on the circuit I use. Each one of these raises an event. I have tried slowing down the sample rate, but it doesn't seem to change this problem dramatically.


Thanks for the help!

Jon

0 Kudos
Message 3 of 4
(3,681 Views)
Hello Jon,

To view the last data in a change detection event I would recommend that you examine the example called ReadDigChan_ChangeDetection_Event.2005. The description in the ReadMe for this example states:

"This example demonstrates how to read values from one or
more digital input channels using the digital change
detection event."

Basically, this program uses an event handler for the Digital Change Detection event and then reads the data and displays it in the Digital Change Detection event callback. I found the specific example I referenced at:

C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DotNET2.0\Digital\Read Values\ReadDigChan_ChangeDetection_Events\vb

This example should provide you with a solid foundation on which you can build your application.

Matt Anderson

Hardware Services Marketing Manager
National Instruments
0 Kudos
Message 4 of 4
(3,657 Views)