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.
06-24-2015 10:38 AM
Hi there, I was wondering what is the best way to run code continuously in an event driven state machine. Particularly, I am going off the JKI state machine. At the moment I put the code I want to run continuously (acquire from an instrument) in the timeout case of the event structure. When the user presses the button, the event sends the value 0 to the timeout terminal of the event structure (through a shift register). If the user stops the acquisition then the value -1 is sent to the timeout terminal. This is a tip that I took from an article by Mike Porter.
Would it be better to run this process in a separate loop? Is a state machine a bad design choice for running code continuously? I don't like my current solution because if I have another process I'll have to start putting case structures into the timeout case. Also, if the process takes a while then the event structure will take a while to respond.
Thanks for your input!
06-24-2015 11:45 AM
I typically put those things into another loop and communicate with that loop using a queue. I also will use the timeout trick of setting the queue's timeout to -1 when not continuously running and 0 (or whatever loop rate you actually want) for when you are repeatedly running something. I find this simplifies your main state machine loop, especially if your state machine is doing a lot of stuff.
06-24-2015 12:12 PM
Adding to that I believe Preview Queue element to read the data and Lossy enqueue to transfer the I/O output, especially if the I/O device responds slowly. This should keep your event structure polling along very nicely during I/O calls to the other structure.
06-24-2015 12:37 PM
@AKA_TG wrote:
Adding to that I believe Preview Queue element to read the data and Lossy enqueue to transfer the I/O output, especially if the I/O device responds slowly. This should keep your event structure polling along very nicely during I/O calls to the other structure.
I actually prefer to use an User Event to send the data to the main event structure and/or whoever else needs it. I am not a fan of the lossy enqueue (loss of data). At that point, I might as well just use a Notifier and/or global variable.
06-26-2015 03:32 AM - edited 06-26-2015 03:33 AM
In a recent related conversation on LAVA, I posted an example of "triggering" a JKI state machine, with two independantly-timed continuous processes.
This involves separate loops, but they are reusable timers that send messages (via User Event) to the JKI to trigger the process.
06-26-2015 10:54 AM
Very helpful, thanks!