07-03-2013 04:56 PM
Hello, I'm attempting to communicate with a serial device via VISA and have been stuck for a while trying to figure out why my program hangs at the VISA Read VI (it hangs until it times out). Increasing the VISA session timeout value hasn't helped - it merely causes the program to hang for longer before it times out.
I'll attempt to provide as much information as I can, so below I'm posting screenshots of my front panel and block diagram and below that an explanation of the operation of the program:
http://i.imgur.com/IdHnl6K.jpg
http://i.imgur.com/2RSK2vX.jpg
This program is intended to trigger a case structure based upon the iteration value of the while loop that encases it for as many times as the value "number of steps" inputted on the front panel. Within each case of the case structure are a series of "serial device command" string concatenations which are tunelled out and passed to the VISA Write VI. From there the program is meant to read back the serial response (a string represenation of a floating point number ie. 2.0000) which is converted to numeric form and added to an array to store the response value from each iteration of the encasing while loop.
All the commands written execute just fine as evidenced by the operation of the serial device to which I'm writing and each "error out" is "OK" (including the Visa Write error out) until the Visa Read error out. When running the program and highlighting execution, the program simply hangs after reaching Visa Read (all the wires coming out of it are gray) until the VISA session timeout is reached at which point it [i]actually passes out the value[/i] it was supposed to read (ie. 2.0000), which gets stored into the array as desired, while putting out the error:
Error -1073807339 occurred at VISA Read in LabVIEW Delay Stage.vi
Possible reason(s):
VISA: (Hex 0xBFFF0015) Timeout expired before operation completed.
and consequently ending the program (the while loop is not executed again).
Any advice would be very much appreciated. I must admit that I'm a relative rookie when it comes to both Labview and serial communication, so I encourage you to treat me like a 5 year old. If you require any further information I'll be happy to try my best to provide it.
Note: I'm aware I probably don't need the execution structures within the case structures, but they're working so I've decided not to tamper with it for now.
07-03-2013 05:09 PM
First of all, you should initialize your VISA session and serial port once before the loop. You should also only close it after the while loop.
Secondly, is the device sending a termination character? Usually an End Of Line character. I noticed you turned it off. But if the device is sending one, you should setup the serial port to use the termination character.
Why are you telling the VISA Read to read the number of bytes you wrote? You should be putting in the number of bytes you expect to get back from your device.
There are more things, but we'll worry about those after you get your VISA communications working.
07-03-2013 05:12 PM
07-03-2013 05:48 PM - edited 07-03-2013 05:59 PM
Okay, I've moved the serial port VI, Visa Resource, and Visa Close VI out of the loop now such that it looks like this now (I added a black separation line in the middle of this image - it's not part of the block diagram).
http://i.imgur.com/gv4dXgb.jpg
In response to your second point, I don't believe the device is sending a termination character. Other people who have communicated with this device in the past have also turned the termination character off.
In regard to why I'm telling the VISA Read the number of bytes I wrote, I suppose I don't have a good answer for that except that it gave me semi-functionality... there's likely a better setup. I just recreated the way I had it originally set up which is with a "Bytes at port" property node:
http://i.imgur.com/0b8FhLQ.jpg
however, this was and is giving me a consistent "return count" of 0 as well as the Visa Read VI not returning any value. However, it should really be noted that having just put that property node back in has now eliminated the Visa Read error leading me to suspect this is where the problem lies.
Edit: Using a different write command I'm now getting the proper return count and value - I'm gonna tinker with this for a bit and update this post.
07-03-2013 06:31 PM
Well, it seems that's solved the main problem that this thread was about (I have no idea why that property node didn't work earlier). My only issue right now is getting the Visa Read return value to be added to a new index of the array for each repetition of the overall while loop, but I think that's something I can solve myself.
I notice, crossrulz, that you said there were some other things wrong too. I've changed the loop condition from stop to repeat, but if there's anything else that you'd like to point out I'd be very thankful.
Besides that, thanks for the help!
07-03-2013 08:01 PM
The other things I was referring to were how you were building the data array, but you seem to already be aware of that.
07-04-2013 09:27 AM
One reason the Bytes at Port is not giving you the count of the complete return message is that you do not give it enough time. At 19200 baud you get about 2 characters per millisecond. The Bytes at Port probably executes a few microseconds after the VISA Write. Thus, the remote device has not had time to send any characters at the time Bytes at Port executes. You can try adding a delay between Write and Bytes at Port. That is a somewhat brute force approach but will tell you whether the communications is working.
Lynn