LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA reads string in wrong format

Hi,

 

I read an instrument with visa. I quite often get  '23E-5' or '.23E-5' instead of '+1.23E-5'.

 

What's the reason behind getting inappropriate format by chance?

 

Kind regards,
Balázs

0 Kudos
Message 1 of 8
(725 Views)

Hi Balazs,

 


@LTBALAZS wrote:

I read an instrument with visa. I quite often get  '23E-5' or '.23E-5' instead of '+1.23E-5'.

What's the reason behind getting inappropriate format by chance?


Most probably the reason is the VI you use to read the strings from COM (?) port…

Wrong code produces wrong results!

Best regards,
GerdW


using LV2020 on Win8.1+cRIO
0 Kudos
Message 2 of 8
(719 Views)

Hi GerdW,

 

I attached my VI. Would you please have a look at it?

Can i avoid getting data in wrong format?

 

Kind regards,

Balázs

 

0 Kudos
Message 3 of 8
(697 Views)

DO NOT USE THE BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (still not enough emphasis)

 

Just go watch this and all of your questions will be answered: VIWeek 2020/Proper way to communicate over serial

 

Before even looking at your code, I knew you were using the Bytes At Port.  Instead, just tell VISA Read to read more bytes than you ever expect in a message and, because of the termination character, you will get your full value.


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 4 of 8
(692 Views)

I went ahead and cleaned up your VI with some comments...


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
Download All
Message 5 of 8
(675 Views)

Hi, thanks a lot.

I tried to use given number of bytes, e.g. 50. Also read visa 3 times before while loop. (it helps to avoid wrong read at startup!)

 

During measurement i can get inappropriate value as 0.00E-00 or get measurement value in wrong format just like before. Measurement value must be higher than zero though. I get no error after all on com port.

 

A) Old instrument is using 10m of shielded serial cable crossing plenty of EM cables. Our old application.exe was using the instrument with no truble. But it may have been using reinitialization run time, that i want to avoid now.

 

B) New instrument is using 10m of active USB cable is using the same VISA read method with 'bytes at port'. (Yes!) Communication is stable.

 

I was just wondering if i can have stable communication with old instrument without reinitializing its communication. ( just like the way i do with new instrument)

 

Balázs

0 Kudos
Message 6 of 8
(660 Views)

First, you need to understand the string being sent by the instrument.

  • Is it sending the ASCII string representing the number followed by a control character <LF>?
  • Using bytes at port, it may decide to read any number of bytes (+1.23E-05)
    • The first byte only and respond with 0.00E-00
      • First character is the sign + or -
      • Using the string to exponent will give a value of 0 as there is not further data to convert
      • Port is working properly as it did receive a character, but converted value is not correct
      • Next response may be correct as read with 1.23E-05
    • First 2 bytes should respond with 1
      • Next character is the number 1
      • Converts to 1.00E+00
      • Port is working properly as it did receive a character, but converted value is not correct
      • Next response may be incorrect as read with .23E-05
    • Continue the same process for the rest
    • Reading of just the LF will also convert to 0

One should only use bytes at port [IF and ONLY IF] there is an expected handshaking with a known number of bytes expected similar to ACK / ENQ {Acknowledge / Enquiry} coding.

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
Message 7 of 8
(653 Views)

@LTBALAZS wrote:

B) New instrument is using 10m of active USB cable is using the same VISA read method with 'bytes at port'. (Yes!) Communication is stable.


Really?  You are twice the specified maximum length of USB2.0 (5m).  USB3.0 is even shorter (3m).

 

 


@LTBALAZS wrote:

I was just wondering if i can have stable communication with old instrument without reinitializing its communication. ( just like the way i do with new instrument)


I would suspect a hardware issue of some kind.  It could be a "damaged" cable, a bad connection somewhere, not enough shielding (ie you are in a VERY high noise environment), bad card or chip on the motherboard, etc.  More likely, you just reached the limits of the cable being able to consistently transmit RS-232 signals.  When going over more than a few meters, I recommend converting over to RS-422 to get a more stable communication.


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
Message 8 of 8
(640 Views)