02-05-2012 10:33 AM
First, thanks for the great products. (Both LabVIEW and LIFA.) Both work very well.
Having taken Core 1 and Core 2, I see the value of event-based programming. Is this possible with the Arduino, where LV sleeps until the Arduino notifies it of some event? For example, right now anytime I need to read a button press, I have to poll the Arduino. The RX and TX lights on the board don't get a break. It would be great if LV and Arduino could coordinate things such that I could create an event in my VI that executes only when a certain digital pin is asserted.
An alternate way of asking this: there's already a Digital Read low-level function. It returns a value no matter what. I want a Digital Read Blocking function that'll block (on the Arduino side! No polling!) until I get the value I am looking for.
Solved! Go to Solution.
02-06-2012 09:30 AM
Hey,
You can set upa digital read function with no timeout that just waits until a byte is written to the serial port by the Arduino. You will have to set it up so that it polls the serial port every once in a while to see if the byte is available though.
02-06-2012 09:50 AM
Kevin, can you elaborate on how this works? The function waits until a byte is written, yet it still polls? Is it just an abstraction for a while loop that polls every X ms and stops once it gets the right value?
My experience is with programming languages like C++, so I am trying to map my knowledge of C++, with its powerful callback / asynchronous IO capabilities, to LabVIEW.
Right now my VI consists of two threads: one that continuously polls a digital pin and generates a notification if the pin is asserted (button is pressed), and another thread that waits for a notification and runs the main logic. The latter thread also clears any pending notifications at the end of its iteration, since as a side effect, the tight loop occasionally generates multiple notifications for a single button press. This works well.
But I dream of a way to tie an indicator to a special function (and maybe it's one you mentioned, which waits for a byte) that'll block until my button is pressed. The key is that it should block until the Arduino notifies it of a new digital value, rather than polling.
02-06-2012 10:02 AM
What I was describing is essentially an abstraction of a while loop which polls every Xms. Since the communication between the Arduino and the PC is over serial there is no good way to set up a method other than polling. Is there a reason you can't use polling in your application? You shouldn't see any performance hit as long as you don't set it up to poll as quickly as possible -adding a 10ms wait in the check for bytes at port loop for example.
02-06-2012 10:11 AM
No, there's no reason I cannot use polling. I just wanted to avoid polling since it's not as efficient as the Arduino sending a single notification when the value changes. (Similar to how Core 2 teaches us to use events instead of a simple while loop for acting on UI controls.)
If polling pins is the recommended (or the only) way, then that's fine with me. Thanks.
02-07-2012
03:23 PM
- last edited on
04-15-2024
04:30 PM
by
Content Cleaner
National Instruments has other software better suited for event driven programming than LIFA. See:
<https://www.ni.com/en/support/documentation/supplemental/06/event-driven-programming-in-labview.html>
Then there is also event driven programming available for Arduino. See:
<http://www.state-machine.com/arduino/>
Howard
02-07-2012 05:19 PM
Thanks, hrh1818, that's very helpful. But is DAQmx compatible with Arduino?
Also, thank you for the pointer to state-machine.com. Their software is very appealing.
02-07-2012
06:17 PM
- last edited on
04-15-2024
04:31 PM
by
Content Cleaner
NO. DAQmx is not directly compatible with Arduino. Depending upon what you are trying to accomplish you possibly could use a digital I/O interface like the following with a DAQmx driver to interface the events your Arduino program generates to Labview.
<https://www.ni.com/en-us/shop/model/usb-6501.html>
Or
<https://www.ni.com/en-us/support/model.usb-6008.html>
Howard