LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Prompt user and wait for RS232 input

Hello

 

I was unable to find an answer for my question and hope someone can help here. I am putting together a test station for a "unit" and for one of the sub tests I want to verify each button on the unit functions and is read by software. The unit is running test code with rs-232 input/output enabled. So, when I press the first button on the unit, the rs-232 serial port will output "button 1: pressed", and similarly for each additional button. Once I understand how to use labview to check this I wont have a problem setting up a loop to check each button, but for a single button case how would one create a VI? All of the prompt user/dialog functions require "OK" buttons or similar. I want my code to prompt the user to "press button 1" then wait until it sees the string "button 1: pressed" at the RS-232 serial port and when it does, auto-close the dialog and continue on to the next. 

 

Thank you!

0 Kudos
Message 1 of 3
(3,377 Views)

Are you just asking how to get user input...? That's what the front panel is for. Alternatively, you can make your own dialog box that functions however you want by creating a subVI that shows its front panel when called. This requires a bit of know-how and trial/error to get it to function right. A lot of new developers will get their code caught up within the subVI popup and the top level application will never end.

 

If you're just trying to get some good programming practices in, it sounds like you want a State Machine.

The Simple State Machine template that ships with LabVIEW is really the best way for new developers to get familiar with LabVIEW while utilizing a semi-scalable architecture.

Here's a broad example of how a state machine works:

  • States: Init, Idle, Exit, DoThing1, DoThing2, DoThing3
  • Each state contains code that might take some time. Ideally, not too long because that's how long you code could be unresponsive.
  • The Idle state contains an event structure for all user interaction.
  • The front panel has a button that says "Do Thing 1".
  1. Loop Iteration 0: Application begins, first state is Init. The Init state does some initialization stuff and tells the application to go to the Idle state when finished.
  2. Loop Iteration 1: Application goes to Idle state. It sits there, waiting at the event structure.
  3. Time goes by, then user presses button "Do Thing 1". There is no code, or minimal code, within this event case. The output of this event state tells the application to go to the DoThing1 state.
  4. Loop Iteration 3: Application goes to DoThing1 state. There is code here that does some stuff. The output of DoThing1 state tells the application to go back to the Idle state.
  5. Loop Iteration 4: Application goes to Idle state where it waits at the event structure again.
  • Each of the states can tell the application to go to any state they want. Want to reinitialize? Go to the Init state again. Want to end the program? Go to the Exit state? Want each state to trigger another (like a sequence)? Have DoThing1 output DoThing2, which outputs DoThing3,  which outputs Idle.

Lastly, 

"Give me six hours to chop down a tree and I will spend the first four sharpening the axe."  - Abraham Lincoln

Here are some free training tools primarily focused on LabVIEW and NI hardware to help get started.

NI Learning Center

NI Getting Started

-Hardware Basics

-MyRIO Project Essentials Guide (lots of good simple circuits with links to youtube demonstrations)

-LabVEW Basics

-DAQ Application Tutorials

-cRIO Developer's Guide

Learn NI Training Resource Videos

3 Hour LabVIEW Introduction

6 Hour LabVIEW Introduction
Self Paced training for students
Self Paced training beginner to advanced, SSP Required
LabVIEW Wiki on Training

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 3
(3,371 Views)

You could do this with just a simple loop in a subVI.  Have a string that you pass into the subVI to tell the user which button to press.  Have a cancel button just in case something does not work.  In your loop, you just keep reading the serial port.  You will want a somewhat small timeout so that the cancel button can be read to abort the loop.  Make the subVI display when called and close when done.


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 3 of 3
(3,328 Views)