LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

using "switch until released" to initiate serial communication

Hello,
 
I am writing a program to send and receive data via the serial port (RS-232) from and to an Elmo Controls Bassoon servo drive.  I do not have the hardware as of yet but it is enroute.
 
The question:
 
I did not want the program to send the data to the servo drive as soon as I started to run LabVIEW so I made a case structure that includes the serial communication sub VI with a boolean control set to "switch until released" to initiate the communication (This is in the "Wave Form" tab in the "Waveform and Jog" file).  I use a similar format to try to receive data from the servo drive (This is in the "Number of Cycles" tab in the "Waveform and Jog" file).
 
Does it seem reasonable to think this will work?  I want the "switch until released" so that I can modify my command string and send it to the servo drive multiple times without having to stop LabVIEW.
 
I have attached my sub VI program and also the program to send the data to the servo drive. 
 
Thanks for any help.  It is surely appreciated.
 
Mark 
 
 
Download All
0 Kudos
Message 1 of 7
(5,461 Views)


JMJ wrote:
Does it seem reasonable to think this will work?  I want the "switch until released" so that I can modify my command string and send it to the servo drive multiple times without having to stop LabVIEW.

No, switch until release (like a doorbell) is not correct, You need e.g. "latch when released".
 
(If you use "switch until released" it is possible that the initialization code runs several times in you press the button a little too long by accident. With latch action, the boolean is true until it is read once by the code ad a double-trigger is impossible.)
0 Kudos
Message 2 of 7
(5,458 Views)
A few more comments to your coding style:
  1. You seem to be under the false impression that wires cannot cross structure boundaries, leading to overuse of local variables and race conditions.
  2. All code that is the same in all cases of a case structure belongs outside the case structure.
  3. Your main loop needs a small wait statement.

Here's an example area:

  1. Look at your code: the inverse, multiplication, and formatting, etc are the same in all cases, thus they belong outside the case.
  2. You have a serious race condition, because you cannot guarantee that the global variable is written with the new value before the new value is read inside the small case.
  3. Only wires guarantee that things occur in a predictable order. No locals and globals needed.

 

As a first alternative, take the shared stuff outside and wire across structures, eliminating the locals and globals.

 

You actually probably only need one output string, so the following might be sufficient.

 


I would recommend to rewrite the entire thing as a simple state machine.

Message Edited by altenbach on 04-29-2008 04:13 PM
Download All
Message 3 of 7
(5,452 Views)
altenbach,
 
Thanks for your help.  I will make some changes.  As you may have determined I am a novice and I appreciate the help.
 
JMJ
0 Kudos
Message 4 of 7
(5,420 Views)
Mark,
pay particular attention to Altenbach's last comment.  The one in large red text.  State machine architecture is a powerful tool to master in LabVIEW.
Jim

LV 2020
0 Kudos
Message 5 of 7
(5,403 Views)

Hello again,

I made the changes suggested and added the wait statement.

Could the reasoning behind using the wait statement please be explained?  Does this simply give the functions inside the while loop time to operate before a new loop begins?

Thanks, Mark

0 Kudos
Message 6 of 7
(5,377 Views)

A wait statement will help provide pacing for the loop.  In the event your case structures are set for jog and false, nothing will really happen that takes any time and the while loop will run as fast as it possibly again, potentially even starving other windows process from getting processor time.  I actually haven't seen this as much of a problem lately, but if it does happen, you will see it as a sluggish system.  For example your mouse will be very herky jerky moving across the screen.

The while loop will not begin its next iteration until all nodes inside of it have executed.  So that may be a little bit of time for the cases that have some code, and near zero time if the cases have no code in them.  Having a wait statement in there guarantees that it will take at least a little bit of time to execute a loop and will allow the processor to handle other tasks.  Whether you need 500 milliseconds or not is up to you and something you can experiment with.  Even a 0 millisecond wait statement allows the processor to handle other tasks.  You probably don't need to spin an empty while loop that fast.  I find 100 to 200 milliseconds is still fast enough to appear to be an instantaneous response to a user pressing the front panel buttons.

0 Kudos
Message 7 of 7
(5,369 Views)