Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I VISA WRITE to 2 devices from within a WHILE loop?

Solved!
Go to solution

Hi,

 

I developed a fairly complex vi that reads data from two sensors and the writes SERIAL commands to two  motor controllers.  The idea is to send the motor commands  more or less "simultaneously" and they are generally not the same commands.  The two motor commands are determined by the sensor input at each iteration of the WHILE loop and subsequently sent to the motor controller by VISA WRITE.  I was getting a errors and failures with the vi, so, we decided to break it up and test the components individually.  In the original vi, I had two sets of  VISA OPEN, WRITE, CLOSE wired inside the WHILE loop, and it sent the two commands to the two motors successfully.

 

The test code I have attached here, "simple VISA speed controller rev1.vi" has the VISA sequence configured around the WHILE loop according to advice from NI.  They suggested putting the VISA OPEN and CLOSE outside the WHILE loop and wiring the two VISA WRITE's as shown.  However, in this configuration, only the STRING 3 command executes.  The STRING 1 command does not execute.  The string "/1V..." commands motor 1, and "/3V.." commands motor 3.  So, by changing the 1 and the 3, I can command both motors from this vi, but, only the string going to the first VISA WRITE actually executes, regardless of which motor is selected in the string command.  There is no malfunction of the motors or wiring, and I can command both motors independently using the software provided from the motor controller manufacturer, so, the hardware configuration has been confirmed to work fine.  I am using NI USB-RS232 to send the string to the motor controllers.  The motor controllers are daisy-chained, and each one has an address switch so motor 1 knows to respond to "/1V..." and the motor with address switch set to "3" responds to "/3V..." etc.

 

The other code attached here, "simple VISA speed controller 2 motors.vi" sends the two commands simultaneously.

 

So, why doesn't the second VISA WRITE work in the "...rev1.vi"? 

 

Thanks,

Dave

0 Kudos
Message 1 of 5
(4,046 Views)
Solution
Accepted by topic author dav2010

Hello Dave,

 

As per our phone conversation, give this a try.

 

Joel C

National Instruments

Applications Engineering

Message 2 of 5
(4,016 Views)

Like magic!  Now both motors are activating per the loop commands.

Thanks!

0 Kudos
Message 3 of 5
(4,005 Views)

Hi Joel,

Thanks for the help laying out the VISA command structure.  I was pretty successful scaling it up as I wanted to, but, then, we found some USB transaction errors, and I noticed something else too.  In the architecture we discussed previously, above, I am sending 3 serial commands on every execution of the WHILE loop.  The flat sequence structures put a delay in between the serail commands so as not to overwhelm the motor controllers (they cannot accept commands as fast at Labview sends them). 

 

In my application, there will be times when the string command from the previous iteration does not need to be updated and re-sent, but, I am resending it anyway; there is a limitation to how many string commands can be sent per second, so, eliminating the redundant ones makes a lot of sense.

 

So, can I use a case structure with a simple TRUE/FALSE criterion to eliminate the sending of redundant commands.  I have built a simple illustration of my concept here.  Will this kind of structure work?  Suppose that  I am monitoring and controlling three motors, and during a given iteration, only 1 of the three motor commands needs to be updated, will it work correctly, and update the one command only, and "ignore" the other two until the following WHILE loop iteration if a boolean input changes?  Will it send 0, 1, 2, OR 3 commands on a given iteration?  There may be iterations of the WHILE loop where none of the motors needs to be updated, so, I would send ZERO commands.

 

By the way, does Labview have a function (indicator) that will let me read the serial commands that are being sent by VISA?  Without connecting my PC to the motors, I don't have any idea if the correct commands are being written to the serial port.

 

Thanks,

Dave

0 Kudos
Message 4 of 5
(3,894 Views)

Hey Dave,

 

I don't see anything that would lead me to think that this wouldn't work.

 

You could do a compare that implements the following logic to remove the manual booleans and have a more automated program:

IF previous Motor 1 Speed != (does not equal) current Motor 1 Speed THEN update Motor 1 Speed. Repeat for Motor 2 Speed and Motor 3 Speed

 

I've modified your example for how to implement the above logic for Motor 1.

 

As for something to monitor the COM port with, there are many applications that can do this. Windows XP comes with a program called hyperterminal. Windows 7 got rid of this feature, but there are a bunch of third party programs that work similarly (i.e. Cool Term). There are some labview variants of COM port monitors as well that you can find with a little searching. You might run into problems with the resource being reserved by LabVIEW if you try to run one of these programs in paralell with your application though. I haven't tested this theory, but it's worth a shot.

 

Thanks,

Joel C

Applications Engineer

National Instruments

Message 5 of 5
(3,886 Views)