LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Command Trigger

I have a sequence structure set up with 4 frames.  Initialize, write, wait, read are the 4 steps and I need to be able to include a trigger in the write frame that automatically starts the next command once the previous command finishes.  Each command takes different lengths of time so I cannot use a wait command.  Inside the write frame is a for loop with an array of strings (my commands) wired to a write subVI.
 
I consulted NIs online manuals and searched in the forums, but most of the results dealt with boards and other DAQ instruments.
 
Any help would be greatly appreciated.
Thanks
0 Kudos
Message 1 of 11
(3,965 Views)
Steve,

In place of the sequence structure use a state machine. The simplest state machines consist of a while loop with a case structure inside. The next state is a variable passed to the case selector via a queue. There are lots of examples both on the Forums and in LV.

Lynn
Message 2 of 11
(3,961 Views)
Lynn is correct that a state machine is much better than a sequence structure but what kind of instrument are you talking to? A wait is seldom necessary with GPIB instruments and if you have a serial instrument, you can also do your reads without any kind of fixed waits at all. Assuming that it is serial, put a VISA Bytes at Serial Port in a loop and keep checking until the number of bytes available is greater than zero. Then you can read that number of bytes, check the number of bytes, and if there are still bytes left to be read, read again. If it's a erial instrument that sends a termination character at the end of it's data, you don't even have to do that. If you do a write and immediately a read, the VISA Read will wait until the termination character is detected or the VISA timeout is reached.
Message 3 of 11
(3,955 Views)
Thanks Lynn and Dennis,
 
The instrument I'm using is the same one I've been fighting with for the past two weeks:  a Cecil CE3055 Spectrophotometer.  Default settings for it are baud rate - 9600, data bits - 8, parity - none, stop bits - 1, flow control - none.  I check it through HyperTerminal and it all works fine, but as I start sending commands to the meter through LabVIEW I receive the same transient error again and again; parity or framing error.  I know the baud rate and parity are correct so it must have something to do with a data length mismatch between instruments.  The instrument is a serial instrument that sends a termination character, but I send 12 commands, wait, and then read, so I have to find a work around for that, which I think I've done...my primary error lies in the write stage.
0 Kudos
Message 4 of 11
(3,941 Views)
Steve,

1. Can the instrument buffer 12 commands or is it getting confused as it starts to respond to the first commands while receiving later ones? Some instruments are happy with having multiple commands queued up while others are not.

2. The suggestion Dennis made about Bytes at Port in conjunction with the termination character should allow you communicate fairly cleanly. Does it echo the commands or give something in the response which identifies which command it is responding to?

3. Does Hyperterminal ever see an error if you send the 12 commands before reading the response? (I am unfamiliar with Hyperterminal because it is not available on the Mac).

Lynn
Message 5 of 11
(3,935 Views)
Another thing to try is adding some intercharacter delay. This is pretty simple to do by parsing the command string and sending a character, wait, repeat. See the attached VI.
Message 6 of 11
(3,931 Views)
Lynn,
 
I'll answer your questions the best I can...
 
1)  The instrument has two running programs.  DataStream and RS232 Control.  DataStream is what controls the machine on its own, and I am using RS232 control in order to have a running system through LabVIEW.  Through DataStream it can easily handle the 12 commands, and I am able to input each command with a 2 second delay in Measurement and Automation, so I can't really see the problem being there. 
 
2)  When I send the commands to the meter I should be able to see what it's doing on the front window display.  However, the only thing that changes is a display command "E17 Serial Comms error: parity or framing".  For instance, when I send my first command ?RNG%T  , I should see the absorbance switch to transmittance, but the error is only displayed.  I'll go back and run the VI again with NI-Spy running, and everything seems to send properly...the error is coming from the spectrophotometer only. 
Here is a link to the spectrophotometer: http://www.dialspace.dial.pipex.com/cecil/spec-3.htm
 
3)  I was recently introduced to HyperTerminal so I'm only a little ahead of you with this program.  I only ever used HyperTerminal to establish proper connection from computer to spectrophotometer.  I've tried keeping it up while switching to RS232 control, but it only allows me to do one thing at a time because I receive a message something along the lines of "only one serial/VISA connection able.  the VISA is active, but cannot be accessed"
 
 
Dennis,
 
If I'm looking at this properly, the VI will get the first string, write it, wait until the status of it is complete, then go to the next iteration which in turn will send the next string command?  I think if I place this as a subVI where my current write subVI is I should have success.  I'll attach mine so you can take a quick look at them and most likely critique it to no end.
 
 
Attached is my whole VI (string array 2), the Serial Port Write VI, and the Open Serial Driver VI (which lies in the Serial Port Write).
I wasn't sure if I had to attach the subVIs so I did anyway.
 
Thank you very much, both of you...
 

Message Edited by Steve.Briggs on 12-05-2006 10:42 AM

0 Kudos
Message 7 of 11
(3,925 Views)
Steve,

Can your LV program send ONE command alone and get a useful response (no error on instrument front panel)? In the LV program you must explicitly append any termination character required by the instrument. For example: ?RNG%T Hyperterminal may append one by default.

Lynn
0 Kudos
Message 8 of 11
(3,917 Views)
-Lynn
I do include a termination character (\r) for each command.  When I send ?RNG%T  \r on its own I receive the same error as if I were sending all of the commands.

Message Edited by Steve.Briggs on 12-05-2006 10:50 AM

0 Kudos
Message 9 of 11
(3,915 Views)

First try this. I don't know where you found those old serial functions. They must have been pulled in from a very old version of LabVIEW. With 7.1, the old serial functions do use VISA unless you've done something really weird. In any case, it's better to use the normal VISA Read and Write. The strings you were sending were not terminated with \r. They were terminated with the characters '\' and 'r'. You have to right click on the string constant and select '\' Code Display to correctly send the control characters. You may also be better off doing a write and then a read instead of 8 writes and a single read. Are you asking for 8 different parameters to be returned from the instrument? Many instruments don't allow this. And if you are requesting 8 different parameters, how could you possibly test this in Hyperterminal. As soon as you typed the first one, the instrument would respond before you could type the second one.

The other cleanup was minor. When you pass an array into a for loop, the array is automatically indexed so you don't need the separate array index function inside the for loop or need to wire the count terminal up. The sequence structure is totally unnecessary so I eliminated that.

If you do need to try the inter-character delay, just replace the VISA Write with the Serial Write Slow example.

Message 10 of 11
(3,908 Views)