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.

Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Input from physical buttons triggering events in program

Hi,

 

I'm trying to use the input from digital signals generated by a physical button to trigger events/functions in the code I'm working on. I'm building a unit that will have buttons that will send input via the digital I/O lines of an SCB-68. I can read in the values of the lines, but I don't know how to have (for example) the line going high trigger an event in the program. Would it be best to have functions reading the lines running in different threads? I found an example in the CVI 8.5 help dealing with change detection events but wasn't able to make sense of it.

 

Thanks!

0 Kudos
Message 1 of 4
(4,609 Views)

Which language are you using?  In LabVIEW, I would tell you to use a shift register to hold the previous value and look for a change in state.  On the change, I would use a queue or user event to trigger an action.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 4
(4,608 Views)

Using C and LabWindows. 

0 Kudos
Message 3 of 4
(4,603 Views)

Hello,

 

If you want to avoid polling, you will need to use the change detection event:

http://digital.ni.com/public.nsf/allkb/DF5719473800838086256F1E0054FD7B

 

I would image you would read a port at a time then in your event call back, see which bit has changed and call the appropriate function.

 

Maybe if you had some specific questions about the example I could help you further?

 

Otherwise, you would need a separate thread, reading the digital values and checking for a change. If a change occurs then call your function.

 

There should be plenty of DAQmx examples to help with reading digital data.

 

I hope this helps.

Nick
0 Kudos
Message 4 of 4
(4,584 Views)