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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timeout Visa Read in a state machine

I am writing a program for a device that I want to read when a button is pressed When pressed the controller sends a Hex message via serial communication, I am reading this Hex to verify the state. When a button is pressed ON it sends a specific hex message and the same goes for when it is pressed off, sending another specific hex message. An input array is made to indicate which button for a user to press and increments when the off is pressed.

 

What I have made is a state machine with a case for each button press ON and button press OFF state.

I verify that there are no shorts by reading each button. In a sub state machine built in the first case of a main state machine.  The Visa Read Buffer is sent to a ‘Match True/False String’ function so when it is pressed it turns true and moves on to the next case and increments the front panel at the same time. When every there is an issue it will turn flag an error and turn off the device.

 

So, everything here is working fine.  The issue that I want to create a timeout for when the button is pressed, and serial read is getting data.  I noticed that with the button ON pressed it will stay in that state and the vi runs continuously since data is being received.    I have tried multiple methods, placing the elapsed timer in different spots, but the time just never elapses inside the main case statements. I tried using dynamic event structure but that attempt failed. I could read the first button press but after that I got stuck.

 

I am kind of new to LabView.  I know there are some other approaches that could be used and even some subVI’s I was going to lay it out before I made a subVI. Attached is the VI if anyone can look at this if you have time and help point me in a direction or even just to chat about this setup.  Thank you

JB

0 Kudos
Message 1 of 2
(1,758 Views)

I'm having a little difficulty understanding what you want to do, but I don't think you want a state machine for it. Your state machine will read 4 bytes and check to see if it is specifically a certain message, but what if you do have a valid message that's not that specific one? Your code also will lock up execution if it isn't getting 4 bytes of data from the device for 50 seconds.

 

I think what you want to do is poll the device for 4 bytes of data and if you get data from it, decipher what it's saying!

 

This is a stripped down version, but shows you what I think you want to be doing for the serial communication aspect of your program. 

 

Visa Read Forums Example.png

 

0 Kudos
Message 2 of 2
(1,725 Views)