12-18-2017 05:36 AM
Hi,
I have a contreller connected via serial and I want to some information abou the controller.
I can get this information using serial visa but I have a problem when I try to read it.
On the attached VI, I read the command that I am sending, and I do not want that, I would like to read the response thath I recieve from the controller.
For example, if I send PV, i wave to recieve the version of the controller, but I recieve the same, PV.
Please, could you help me?
I attach de vi.
Tanks in advance
12-18-2017 06:18 AM - edited 12-18-2017 06:19 AM
Hi aitor,
first of all: don't use BytesAtPort when you enabled the TermChar!
(You might need to handle TimeOut errors after VISARead. I also changed the switch mode of your buttons to eliminate the local variables! And I used AutoCleanup…)
For example, if I send PV, i wave to recieve the version of the controller, but I recieve the same, PV.
- Do you send the correct command? (Sometimes there needs to be a question mark like "PV?" to trigger a response. Maybe a different TermChar is needed!?)
- Which device are you communicating with? Can you share a programming manual for this device?
- Is there a device driver available at IDNet?
12-18-2017 06:28 AM
DO NOT USE THE BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (still not enough emphasis, and yes I type that in a mad manner).
The Bytes At Port causes an interesting race condition with your device. You request data and instantly check to see if there is any data back. 1) You did not give the instrument a chance to respond. 2) You do not know if you got your whole message.
So, assuming your instrument uses an ASCII formatted message structure and is using the termination character (which you currently do have enabled by default), then the solution is to simply tell the VISA Read to read more bytes than you ever expect in a single message. I tend to use 50 or 100. Some go extreme and use 4096.
Why does this fix the problem? The VISA Read will stop reading when one of the following situation happen (whichever comes first):
1. The number of bytes you told it to read is read.
2. The termination character is read (assuming it is enabled).
3. The read times out, typically from a bad connection or wrong serial settings (baud rate, etc).
So by telling the VISA Read to read more than we expect, it is almost a guarantee that the read will end with the termination character unless something is terribly wrong, in which a timeout should occur. And this will fix every issue we had due to the evil Bytes At Port.
12-18-2017 06:35 AM
Hi,
first of all thankk for your answer.
I have implemented your image and now I can not write or read. I am 90% sure that the command sent is correct since using the Putty application I have no problem with communication.
My goal is to do it in labview. The device is a welding controller.
Attached a photo which shows the manual for RS232 and possible parameters to enter it.
what could I do?
Thanks
12-18-2017 07:54 AM - edited 12-18-2017 07:55 AM
We can't tell whether the command you're sending is formatted correctly, since it's just an empty control in your code. Can you type the command into the control and then either turn it into a constant, or set that as the control's default value, so we can see it?
12-18-2017 01:16 PM
Hi aitor,
do you send your command with a CR attached - as is described in your manual?
Putty (and other terminal programs) tend to automatically append the CR char. LabVIEW will not do this by default!
(And please look up the meaning of <CR>, after all its a single-byte ASCII char!)
12-19-2017 01:34 AM - edited 12-19-2017 01:39 AM
Hi,
Yes, I attach the VI I am using, i have tried the following string constants without succes:
·#PV (As Putty)
·PV<CR>
·PV (enter)
In addition, I set byte count to 123 as your image atach but I do not know why because i do not the number of byte that I am going to recieve. Every single consult will obtain differents responses.
The response I am waiting for is MCPC3.128.
Do you know what could I do?
12-19-2017 01:39 AM - edited 12-19-2017 01:41 AM
Dear aitor,
you need to attach the CR char to your command string!
- You could either use a string constant set to Hex display mode and enter "0D".
- You could use the CR constant from the string palette.
- You could use a stzring constant set to \-code display and enter "\r".
Did you read the ASCII explanation and did you notice what "CR" means?
There surely is a paragraph in your manual explaining those <CR> and <LF> terms in the image you posted before!
12-19-2017 01:48 AM
Hi,
Yes, I know what CR means, I am using this comand but not in labview, so I can not comunicate.
I have introduced 0D in hex.
I have tried in \ code PV \r.
I do not know what to do more, Do you think taht the problem could be on the diagram?
12-19-2017 02:12 AM
Hi aitor,
in your latest VI you only send "PV?" to your device. You need to append the CR character!!!
Like this:
What's the problem with adding a CR to your string?
Btw. when your device ALWAYS requires to get a CR at the end of a receive message you could set the CR as termchar for outgoing VISA messages using a VISA property node…