LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

New information - Bytes at serial port problem

Hi all,
 
 
I've got more information.
 
To make it short, the problem is that the Bytes at serial port reports a wrong number of bytes in some circumpstances under Linux.
 
I found out that one of the circumpstances is when there's 0FFF in the reception buffer. As soon as this value is removed (read), the number of bytes becomes valid.
 
The attached picture illustrates the bug quite well...
 
Bytes at serial port reports 8 bytes to read. I read 5 of them (the last two being 0FFF). Then Bytes at serial port reports 2 bytes...  8-5=2?
 
Thanks,
 
Alex
 
 
Message 1 of 20
(4,996 Views)

Alex,

I'm sorry you're having trouble with this.  I would be curious to see if you get the same problems with the latest version of NI-VISA (3.5) on one of our supported distributions of Linux. 

Could you try this out?

Thanks,

 
Robert Mortensen
Software Engineer
National Instruments
0 Kudos
Message 2 of 20
(4,950 Views)
Hi Robert,
 
Thank you for your quick answer. Unfortunately, your list of supported distribution is quite short. Running the latest Visa drivers on RH 9.0 crashes the application (I have to use 2.6), and I can't use a newer distribution since I have a driver for another peripheral of the system that runs only on RH 9.0.
 
I know that the problem does not occur on Windows, though.
 
Alex
0 Kudos
Message 3 of 20
(4,933 Views)

I think this is maybe the same what I noticed in MacOsX:

 

When reading binary data the property node "Serial Settings:Number of Bytes at Serial Port" shows a wrong number of bytes when one or more bytes has the value of xFF. For each byte on the bus containing xFF the #bytes is incremented by one.

So when the bytes 10,20,30,255,112 are sent to the computer, LabVIEW's #bytes shows 6 bytes. So reading 6 bytes will time-out after which 5 bytes are received with the values as sent. When the bytes 10,20,30,254,112 were sent,  everything is OK.

This was done on MacBookPro MacOsX10.7.5 and VISA5.2.0 LabVIEW2009SP1/2012

 

Scott Hannahs was able to reproduce it with Mac OS X 10.6.8 / LabVIEW 8.5.1 / VISA 5.20

 

seems to be a VISA bug/feature

Regards,
Paul

0 Kudos
Message 4 of 20
(4,435 Views)

Hi,

 

I have this problem also.

I've noticed some strange behavior receiving data with the serial interface on LabVIEW for Linux.

I saw this topic, so I did some testing.

the problem is that when there is an 0xFF in the data, the bytes at com port gives a count of n + 1 bytes.

when I have two 0xFF in my data, it gives n + 2 bytes and so on.

So the bytes at com port gives an extra byte for each 0xFF in the data.

when using the construction: read bytes at com port -> read that amount of bytes, you will get time-outs.

If you have read the 0xFF in the data, the bytes available will be corrected with minus 1.

the only work around for this bug is to get the available bytes at port, and read the half of that amount, each time.

 

I've read that this bug (or feature) is also in other serial devices, so it must be an VISA bug in LabVIEW for Linux.

 

Greetings, 

 

 

Wouter

Wouter.
"LabVIEW for ARM guru and bug destroyer"
0 Kudos
Message 5 of 20
(4,349 Views)

While this is an annoying bug, using Bytes at Serial Port for serial port communication is almost always the suboptimal choice anyways. On serial port communication you have typically two types of communication:

 

- Fixed size protocols: These are protocols where the size of the message is known before trying to read data. This also includes protocols where you have a fixed size header that contains the number of data bytes that will follow.

 

- Character terminated protocols: These protocols use a specific character (in GPIB also a specific handshake line) to signal the end of message.

 

For both types, using Bytes at Serial Port is definitely the wrong choice. The first needs to read the number of bytes that the protocol mandates, rather than what is currently in the buffer, to avoid truncated and/or concatenated messages, while the second is much more reliably (and with a lot less code in the application) handled with the VISA termination character feature.

 

The only case where I could see Bytes at Serial Port somehow useful, is when trying to write a serial port terminal application, but to do that in LabVIEW seems like using a 50 ton hydraulic hammer to drive in a nail.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 6 of 20
(4,313 Views)

Rolf,

 

Fully agreed.

But when reading binary data only your first solution will work because binary data may have any value including terminating characters.

 

Nevertheless Visa MUST show the correct number of bytes on the bus. So this is a bug in my opinion.

 

Have nice holidays you all !

 

Paul

0 Kudos
Message 7 of 20
(4,289 Views)

I fully agree, Pau! Both that it is a bug and that binary data can't be read with the termination character method.

 

However it is my true and full opinion, that a protocol using binary data without some kind of known data length is a completely broken protocol. There is no way to do reliable data communication with Bytes at Serial Port without a lot, and I mean really a lot, of rather involved extra code on the receiving side. Only a terminal type implementation can simply use Bytes at Serial Port, since the interpretation of the displayed data is then done by the human.

For machine control application, to make sure that Bytes at Serial Port wasn't called in the middle of a message and therefore only returns partial messages, or does contain more than one message which then has to be separated and the remaining part stored somewhere to be used for the next cycle, requires a lot of extra code, with a great potential for extra errors, especially  since serial port communication can sometimes return errors too, and if you are not very careful there you loose either already stored data in the intermediate buffer or concatenate errornous data together.  Been there done that and quickly abandoned once the VISA implementation with termination characters got reliable  enough.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 8 of 20
(4,271 Views)
hi Rolf,
 
       I fully agree your opinion, please see attached vi and picture. this vi also call poll instrument response vi,  I using this method in philips hue(www.meethue.com) project,
 
It's very reliable.
 
       Did you remember last year you help me to upgrade named pipe VI? I also using this in hue project, thanks a lot for your help.
Download All
0 Kudos
Message 9 of 20
(4,260 Views)

Sure, the length of the message must be in the protocol used.

I use NrOfBytes to know if the (fixed length) header of the message is there and use the message-length from that header to get the remaining bytes.

Doing so I noticed the VISA-bug.

Regards,

Paul

0 Kudos
Message 10 of 20
(4,252 Views)