LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial VISA, Problems recieving data.

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. 

Captura.JPG

 

Tanks in advance

0 Kudos
Message 1 of 12
(3,903 Views)

Hi aitor,

 

first of all: don't use BytesAtPort when you enabled the TermChar!

 

check.png

(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?

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 12
(3,884 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 12
(3,880 Views)

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.

Captura.JPG

 

what could I do?

 

Thanks

 

0 Kudos
Message 4 of 12
(3,875 Views)

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?

0 Kudos
Message 5 of 12
(3,856 Views)

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!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 12
(3,836 Views)

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?

0 Kudos
Message 7 of 12
(3,817 Views)

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!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 12
(3,812 Views)

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?

 

 

0 Kudos
Message 9 of 12
(3,807 Views)

Hi aitor,

 

in your latest VI you only send "PV?" to your device. You need to append the CR character!!!

 

Like this: check.png

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…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 12
(3,803 Views)