LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a stop button to send commands through serial port and end labview vi?

Solved!
Go to solution
I want to send two commands to my device, the first to stop running and the second to exit remote control mode. This is done over RS232. What I want is a way to put this in my existing VI which tells the device to run. Right now if i stop the program the devices just run at the last command unless i stop them manually. How can i set up a stop button that wont send any commands unless pressed? I tried the case structure but did not know how to put a "do nothing" part if ithe stop button in the while loop  is not pressed.
0 Kudos
Message 1 of 43
(6,025 Views)

superomario wrote:
I want to send two commands to my device, the first to stop running and the second to exit remote control mode. This is done over RS232. What I want is a way to put this in my existing VI which tells the device to run. Right now if i stop the program the devices just run at the last command unless i stop them manually. How can i set up a stop button that wont send any commands unless pressed? I tried the case structure but did not know how to put a "do nothing" part if ithe stop button in the while loop  is not pressed.

Have the stop button be a boolean control.
If true, write the command to the device using 'serial write' in the case structure.
If false, you don't need to put any code, just leave the case blank. 

 

Cory K
0 Kudos
Message 2 of 43
(6,020 Views)
I left the case blank it leaves me with an unwired error.
0 Kudos
Message 3 of 43
(6,015 Views)
Can you please post your code?
Message Edited by Cory K on 06-02-2010 12:34 PM
Cory K
0 Kudos
Message 4 of 43
(6,013 Views)
This is only done for device 1 @address 00.
0 Kudos
Message 5 of 43
(6,004 Views)

1) Just because the code appears left to right on your block diagram doesn't mean that is the order in which the code operates.
This means that the 3 'serial write' operations on the left don't necessarily occur before the code in the while loop.

 

2) The 'unwired terminal' error has to do with your while loop. There is no condition set to stop the loop, so it will loop infinitely.

When would you like the loop to stop? Is this supposed to continually loop until the stop button is pressed?
If so, wire your 'stop' control to the red stop sign in the bottom right of your while loop. 

 

3) You have no 'Wait' function in your while loop, so it will run as fast as possible,

which is probably much faster than the device can receive and process the data that is being sent to it. 

Message Edited by Cory K on 06-02-2010 12:42 PM
Cory K
Message 6 of 43
(5,996 Views)
Yes it should run infinitely until the it is stopped. And I thought by putting in the sequence boxes i could control how things are running in what order. when you say wire the stop button, is this the same switch that is feeding into the case structure? or will i have to have two separate switches. Ideally i want one to be pressed and stop everything at once.
0 Kudos
Message 7 of 43
(5,993 Views)
You've got major flaws in the program. You simply cannot do parallel operations on the same serial port, you need to enforce data flow with the error in/out connections, you should not be repeatedly calling the VISA Configure Serial Port or the VISA Close besides the other mentioned problems. If you do not know how to stop a while loop, you should really take the free tutorials before doing any more coding and before posting any more basic questions.
0 Kudos
Message 8 of 43
(5,983 Views)

Try this VI.

It is a modified version of your VI.

Notice that the data flow is dictated by the wires, rather than the position of the code. 

You still need a wait function though, I'm not sure what time scales you are working with. 

Cory K
0 Kudos
Message 9 of 43
(5,976 Views)
Why can't I use the same serial connection? I don't think I have much of a choice, the devices work in such a way that the first device is the only one connected to the computer and the next one is chained to the firsts "out" port  and so on. So all the data is sent to the first device and if the address does not match it is sent to the next one down the line until the right address is found. How else can i do this? And i know the code is neither perfect or robust but I cannot think of any other ways to do these things. Someone posted on another thread of mine recently and what he suggests is incredibly complicated for me to do at this stage. So any simple recommendations you can suggest would be great.
0 Kudos
Message 10 of 43
(5,974 Views)