Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA sends/receives to serial port once, but 2nd command fails

I have created a vi that uses VISA to send a command to a serial device, and receive it's response.
The vi is executed twice for each one of 50 RS232 ports (via an Equinox virtual serial port hub).
The first command always seems to work (although I had to increase the wait time between command sent/response received from 1/2 sec to 1 sec.) But the second command always fails - no response is received.

This works fine to the same RS232 devices in my previous vi using pre-VISA low-level serial communications. But I want to upgrade to VISA and can't ever get it to work beyond the first transmission.
If I switch the order of the commands, the first still works but not the second -- so it seems to be my VISA logic, no the command syntax or device.
I've tried using VISA Clear, various property setting, ETX char's (not sure I'm doing that right), longer waits, etc.
The only thing that works is re-initializing the port before each command.

The vi is attached (the Serial String vi formats the supplied values into a correct command syntax - this hasn't changed from pre-VISA version).
I'm using LabVIEW 6.0.2 and VISA 3.3
0 Kudos
Message 1 of 8
(3,650 Views)
Everything looks good in your VI. One other thing you could do is use NI-SPY to get a spy log to help see what may be going wrong and/or also use something like Portmon or some other port monitor program that would allow you to look at the differences between the VISA and non-visa application calls into Windows. If you save these into logs I can help you take a look at them.

-Josh
0 Kudos
Message 2 of 8
(3,643 Views)
You might want to try flushing the serial output buffer after writing. Otherwise you're letting the OS decide when to actually send the data which, depending on the OS settings, could be significantly later than you actualy want.

See the attached. I'm not sure if this actually helps. I alwaye thought it did, and all my RS-232 programs do this, but the help file is self-contradicting regarding whether flushing with "32" send the information or not.

You can try out this version.

Hope this helps.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 3 of 8
(3,616 Views)
Thanks, Josh. I do want to try a port monitor and see what's really transmitting. This has been very frustrating.
Thank you also, Shane. Because I'm using LV 6.0.2, I can't open you example. I'm not familiar with 'flushing' the buffer -- I don't see such a vi in VISA 3.3. Is it the same as 'Clear'? I've tried that previously, without any luck. What is the 32 you mention?

Message Edited by Len P on 05-12-2005 08:51 AM

0 Kudos
Message 4 of 8
(3,611 Views)
Sorry, here it is saved as LV 6.0 (I think).

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 5 of 8
(3,601 Views)
Thanks again, Shane -- I really appreciate the help.
The Flush did not work. I even tried adding 2 more flushes right after the open (in pane 0) -- one to flush the transmit (16) and one to flush the receive buffer (64). That had no effect either.
The interesting thing is I use this vi to send 2 commands to the device and receive the response.
If I run it the desired way (Initialize Port --> 1st Send/Receive --> 2nd Send/Receive) then the 2nd Receive always fails. This sequence works fine w/ pre-VISA serial calls.
If instead I run (Initialize Port --> 1st Send/Receive --> Initialize Port --> 2nd Send/Receive) then everything always works fine.
But I shouldn't have to initialize the port everytime... or should I?

I'm digging through NI-SPY.
(btw.. I did find the Flush vi in my palettes.... thanks again!)

Len
0 Kudos
Message 6 of 8
(3,597 Views)
You need to be careful which flags you set when flushing the transmit and receive buffers. Some of them will discard any data present, which really isn't what you want. This is unfortunately another case where the LV help is completely useless as it is self-contradictory.

I'm at the moment not sure whether 16 or 32 is the correct flas combination. Try them both just to be sure. Oh, and one flush is enough. Two is just overkill.

Hope this helps

Shane.

Ps what happens if you send a third command after the second fails? It might boil down to a termination character problem.

Message Edited by shoneill on 05-13-2005 11:41 AM

Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 7 of 8
(3,585 Views)
Shane,
I've attached the latest version of the vi, which seems to work although I need to test more.
Here's what's changed:
1. I do a VISA Serial Init before every send/receive - this seems to be the real key... more below,
2. I've left the Flush (32) after send as you suggested, because it makes sense,
3. To me, the help seems to say flush w/ a 16 will flush immediately, while 32 waits until the transmit finishes. I think either would work for me.
4. I've changed some of the diagram, but the logic and flow is basically the same.

I can't say why the VISA Serial Init is required, but it DOES make this vi work. We did NOT have to do that in the pre-VISA low-level RS232 vi's - in fact, we'd only do it at program startup and the program would run for days or weeks of sends/receives to these ports.
The only plausible explanation I have is that we are talking to 25 VIRTUAL ports (not real ports) using Equinox software to an Equinox Ethernet Serial Provider hub - LV talks to what looks like Serial ports, but the Equinox software is manipulating that and sending it over the ethernet (and then splits back into individual RS232 ports at the hub). I'm guessing the Equinox s/w on my PC is doing something that changes the 'virtual ports' on my PC in such a way that re-initializing is necessary before every VISA send/receive.

Thanks for you help!
Len
0 Kudos
Message 8 of 8
(3,565 Views)