LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus Array Size Error

I am having issues with the Modbus Serial Master Query VI in the NI Modbus 8_2 package.  I am reading multiple registers of a device in one communication.  The majority of the time it will work perfectly, but with 1 in approx. 20 reads I get a response of 5 registers.  It does not return an error,  just an array that is only 5 values instead of 6.  Has anyone else had this problem or know a solution?  I have implemented a simple vi to disregard the data if it is not correctly sized, but this results in missed data.

 

Thanks,

Dan

0 Kudos
Message 1 of 14
(3,864 Views)

I have not seen this before.  I can't think of a scenario of how this would happen.  Unless the device you are communicating with (what is the device?) is not sending back a complete dataset.

 

Do the 5 values you get make any sense?  Is it a case of the 5 are correct, but 1 is missing either from the end, the beginning, or the middle?  Or by missing 1,do the 5 you get seem scrambled.

 

My first thought would be that you are missing some of the bytes on the serial read.  But I don't think that could happen without the Modbus drivers generating an error.  That is because there is a checksum going on for all the data received.  The modbus frame is going to have some header, some data, and a checksum (you can look up the Modbus spec. at Modbus.org to see exactly what a Modbus frame would look like).  If it was missing any data (which would be coming from the middle of the frame) the checksum would be invalid (though there would be a very, very slight chance it would still be good) and the Modbus drivers would generate an error.

 

So if a byte or two was missing, it would have to have been missing from the very beginning before the data was sent and the checksum calculated in the sending device in order for the sending device to still have sent a valid checksum.

0 Kudos
Message 2 of 14
(3,862 Views)

The device that I am currently communicating with is an ADAM-4118 data acquisition module by Advantech.  I have also tried communicating with a GE Fanuc PLC and I end up with the same scenario.

 

The 5 values that I get are valid.  It is dropping off the 6th value. 

0 Kudos
Message 3 of 14
(3,850 Views)
If you are reading the same values every time, you should be able to calculate how many bytes to receive in the response. Then wait to read until your bytes at port is equal to the number you want. Possibly a parity bit, stop bit, or baud rate setting is not the same in each device. We need to see your code and maybe some portmon data captures to show what is being transmitted out of the port.
0 Kudos
Message 4 of 14
(3,842 Views)
I want to echo previous the previous poster's request for more information.  Some portmon captures of this occuring would be very helpful.
Ben

National Instruments
Certified LabVIEW Associate Developer
Certified TestStand Developer
0 Kudos
Message 5 of 14
(3,794 Views)

Attached is some documentation.  I created a simple VI for modbus master communication, when the GO button is pushed it sends 1 modbus request.  A screenshot of the block diagram is attached.

 

Also attached is a screenshot of the front panel when the request is successful and when it is not successful.  The main difference is the last byte of the received bytes.

 

See the next post for portmon screenshots.

 

 

0 Kudos
Message 6 of 14
(3,785 Views)
attached are the portmon captures:
Download All
0 Kudos
Message 7 of 14
(3,784 Views)
Do you really want the starting address to be zero?? It has been awhile since I've used portmon. Can you get it to show the hex code that is received/transmitted on the right hand side of the screen??
0 Kudos
Message 8 of 14
(3,770 Views)

The starting address at 0 has no effect,  I can start at address 1 and I still get the same results every 20th time or so.

 

Attached are the screenshots of portmon w/ hex:

0 Kudos
Message 9 of 14
(3,763 Views)

Could you post your vi as an llb file?? Seems like it should be waiting for more bytes to be received. Maybe the timeout value needs to be increased.

 

Download a demo of the kepware opc server with modbus drivers. Run this program with the quick client reading modbus data and watch the transfers with portmon.

0 Kudos
Message 10 of 14
(3,754 Views)