LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

bytes at serial port problem

Hi all,
 
I have a strange problem with the "bytes at Port" property. I use LV 7.1 for Linux.
 
I have a function that reads variable size packets coming from the serial port. I use the Bytes at Port property to know how many bytes to read and then I read that number of bytes. In some situations, the Bytes at Port returns 8 bytes when there's only 7 bytes in the buffer (the read timeouts...). How could it be?
 
BTW these functions come from the NI Modbus library and I didn't modify them.
 
Thanks,
 
Alex
0 Kudos
Message 1 of 11
(7,322 Views)
Alex--

Does your serial device return a termination character?  The Bytes per Port will return all bytes including the termination character.  If you are comparing this number to the return count from the VISA Read function, it does not include the termination character as a byte.  This might be causing your discrepancy with the Bytes per Port property node.

How do you determine the number of bytes in the buffer?

Mark
Message 2 of 11
(7,259 Views)
Hi Mark,
 
I use the MODBUS protocol to communicate with the device. The situation that I described occur when the device (a slave) answers to a query from the master (the PC w/ Labview). The MODBUS RTU protocol doesn't use a termination character. Moreover, I configured the serial port so that it doesn't use a termination character.
 
When I place a breakpoint between the Bytes at serial port block and the read block, I see that there's 8 bytes available. When I step over the VISA read block, it wants to read 8 bytes (of course), but it produces a timeout error after the default 10 secs. When I probe the output of the read block I see that there's actually 7 bytes (I copy the data in a hex editor). Those 7 bytes correspond to a complete MODBUS message, so I really doesn't know what the eightieth byte is all about...
 
Any idea?
 
Thanks a lot,
 
cyberblak
0 Kudos
Message 3 of 11
(7,254 Views)
Normally when you use a modbus read command, one of the parameters is how much data to read(registers). You should know how many bytes to receive from that info. If you use the NI modbus library, I don't think you need to worry about bytes at port. Just give it the parameters for slave address, modbus command, starting addresss, quantity. Attached is a modbus serial query in 7.0 format. This came from the 7.1 library and was saved to the previous version.
Message 4 of 11
(7,243 Views)

Hi,

Actually, I use the NI Modbus library. I agree that it is possible to avoid the use of Bytes at serial port since the messages length can be determined, but the Modbus Read function from the library does use the Bytes at serial port property.

In the worst case, I'll modify it, but I was curious to know why that property could generate a wrong value. More so that I know that it works under Windows and it doesn't work under Linux.

Thanks,

Alex

0 Kudos
Message 5 of 11
(7,233 Views)

I also have some code available where I calculate the CRC checksum in plc logic for a block of registers. Then I read the data in labview and calculate a new checksum for the data registers. I put this inside a loop and make labview read the data until the Labview calculated checksum matches the plc generated checksum. Kind of a way to guarantee the labview tag values are accurate.

Does the modbus read return any error values when you get more bytes than expected?? You could intercept this error and read the data again??

Message 6 of 11
(7,225 Views)
The Modbus serial receive function also calculate the CRC checksum on the incoming bytes as they are read. It doesn't return an error though since the first error to occur is the timeout from the VISA read block. And even if I ignore this timeout error, the data is correct since it really reads 7 bytes, which is the expected size for the Modbus packet (and the read bytes are OK).
 
Thanks,
 
Alex
 
0 Kudos
Message 7 of 11
(7,220 Views)
Alex--

Are you using the MB Serial Master Query , more specifically the MB Serial Receive sub-VI causing the error?  Testing the same VI with a Windows based operating system, you do not receive the same error?  Which distribution/version of Linux are you using when you receive the error?

-Mark
Message 8 of 11
(7,180 Views)

Effectively, I don't get any error with the Windows version, using the same VI. I use the original MB serial receive.

My linux distribution is Red hat 9.0

Thanks,

Alex

0 Kudos
Message 9 of 11
(7,175 Views)
Alex--

Can you successfully run the MB Serial Init.VI with Linux?  The VI using the Bytes at Port Property Node and the VISA Read in succession.


Mark
Message 10 of 11
(7,141 Views)