04-16-2019 05:45 AM
Hello,
I'm trying to communicate with my PC via serial port (Using RS-232) to a device. I have tried several .vi where I write something with "VISA Write" and expect to read and answer from the device. I saw I have stablish the communication with the device and also the message has been sent, but when when my code arrives to "VISA Read" I always get an error or nothing has been read.
For instance I have used this example:
http://www.ni.com/example/27669/en/
but I get "Error-1073807339".
I don't understand what am I doing wrong?
For more information:
I tried to communicate to two different types of devices (independently), the first one is a module that reads temperatures and the second device is a PLC.
For the first device if If i wirte the commands in Hyperterminal I get an answer. But in labview nothing. This device uses DCON protocol.
For the second device I'm not able of communicate with Hyperterminal or labview (this one uses Modbus serial) I write something in hexadecimal and expect answer.
Any help about what is happening?
Solved! Go to Solution.
04-16-2019 06:45 AM
Well, there is no VI that you attached to be able to see what you are doing. So anything we say is pure speculation.
I'll assume you got the communication settings correct for the first one since you say it works in Hyperterminal and you would know to use the same settings in LabVIEW. The most likely scenario is that your VISA Write did not include the termination character the device expected.
For the second one, you say you send hexadecimal, but that term can often be misused in several ways. My first guess is that you you entered values that are hexadecimal digits 0-9,A-F into a string control, but that control was set for normal display rather than Hex display.
If the VI was attached, I could be more certain of my answers.
04-16-2019 07:33 AM
Hello, thanks for the answer.
For the first case I have tryed to write the termination char "\r" (I write 13 in the box) and it doesn't work (example attached).
For the second case I have changed the string array to hexadeciamal but it doesn't work either.
04-16-2019 07:50 AM
Did you try the line feed character? The VI you attached doesn't have the write string you want to use saved as default.
And for the other, you said it is Modbus which is a more sophisticated protocol. It consists of certain command bytes, data bytes, and some checksum bytes. If you haven't entered them correctly, you'll have problems. Generally, you'll want to use one of the LabVIEW Modbus libraries and not the plain VISA Write and Read functions so that it can build the message packet for you. Are you sure you are using the right kind of cable? Have you read the manuals for both devices?
04-16-2019 08:25 AM
For the first one I use DCON protocol, so I made some changes to send an hexadecimal message.
So if I want to send $01M+(checksum)+end character 0x0D --> I write in the string box 2430 314D 2E(2E=checksum).
Then in termination char I write "13" (it's 0x0D).
I see that I send 5bytes but I get nothing...just a timeout error message
04-16-2019 08:37 AM
I've been handling VISA serial write/read with a version of the VI I've attached here. It uses the default VISA settings, which works for my application. If nothing else, this may give you a place to start.
04-16-2019 08:54 AM - edited 04-16-2019 08:56 AM
No NO NO. Don't use bytes at port! 99% of the time it is the wrong way to go.
The "Basic" example you are using will work better.
I don't know what DCON protocol is. I'm googling but I have not yet found a link that shows what the message structure is. But I did find a link that said "DCON protocol is a request/reply communication protocol for the I-7000/8000/87K series I/O modules. It defines a simple ASCII format protocol, like $AAN, $AASi6, #AAN, .., etc.. The hardware interface to access the I-7000/8000/87K series I/O modules can be divided to ::" (English spelling was por in that link.)
Your VI doesn't show you adding either a \r or \n (carriage return or linefeed) at the end. You are just ending with the checksum.
Since it says it is ASCII format, I'm thinking the checks 2E should not be written as a byte 2E (value 46 decimal), but written as the characters "2" and "E". (Format into Hex string with a width of 2 would handle the conversion for you). Then follow that with the carriage return or linefeed. Considering everything else is ASCII readable characters, it is unlikely they would have switched over to a binary, unreadable byte for the checksum.
Do you have a link to the manual that describes the communications protocol?
04-16-2019 08:55 AM
Thank you for the help, could you send me the .vi for labview 14?
04-16-2019 09:00 AM
Don't use that VI. Yours is better.
Another thing I recommend. If you have it working via hyperterminal, describe exactly what you type in. Do you hit the enter key?
You can use a tool like Winpcap or wireshark to snoop on your serial port and see what the communication looks like when you have it working with another piece of software. That is often enough to see what is wrong with the LabVIEW implementation.
04-16-2019 09:13 AM
The code that JRiggles kindly supplied contains the most discussed "error" in handling VISA Reads that keeps popping up on this Forum.
Many (most?) VISA devices that communicate via Text strings use a "Termination character" that ends their strings, and the most common termination character is a Line Feed (0xA). Shown below is the VISA Configure Serial Port, with constants wired to the top terminals to show their default values (these are rarely wired by users), with the Baud Rate input also shown.
The 10000 is "Timeout" (see later), the 0xA is the default Termination character, and the "True" is "Use Termination character"
When your sending Protocol uses Termination characters, the "Common Wisdom" of the LabVIEW Community is to use this to "get all of the characters". Instead of using Bytes at Port, you do a Read with a Character count that you think is much more than necessary (many use a count of 1000; I'm partial to a count of 1024). As the typical response is usually in the range of 5-50 characters, you get the entire string (because the sender sent the Communication character).
What happens, however, if the sender fails to send a string? That's where the Timeout value comes in. It defaults to 10 seconds (it is a millisecond counter) -- if the VISA Read does not respond, the function will exit with the Error Flag set to let you know that something has gone wrong.
I'll let you modify JRiggles code yourself. Note that doing it this "recommended" way means you also don't need a Wait (or a Delay VIM) between the VISA Write and the VISA Read -- the Read will automatically "wait until it sees the Termination Character or 10 seconds has elapsed", which is all you need.
Bob Schor