LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus data

I am using NI Modbus.llb for my modbus serial application. The problem I am having is, when I try to write a data value beyond 32,767 using write single register function code, the data does not get written into the slave.
 
Should I use "write multiple register" or do I need to specify full starting address like 401831 instead of 1831 in addressing the registers?
 
Any help?
 
Thanks,
 
0 Kudos
Message 1 of 15
(4,869 Views)
What is your Slave device?  I am wondering if that has been configured to write Signed numbers.  In which case the 16-bit range of 65535 will become –32767 to +32768. 
 
You would use the "write multiple registers" if you were trying to write to more than one registers. 
 
I would make sure your Slave is configured to accept full 16-bits for each holding register as a positive value.
 
Regards,
 
-Khalid
0 Kudos
Message 2 of 15
(4,843 Views)
Hi Khalid,
My slave device is a modbus device- AC drive from Control techniques. I am not sure, hos is my slave configured. All I know is, the slave is set at 19200, 8, 1,0 in RTU mode.
 
I was debugging the modbus VIs, and I suspect that MB CRC-16 is causing this trouble. I may be wrong. Please advice.
 
If so, is there MB CRC-32 available?
 
Thanks once again,
 
0 Kudos
Message 3 of 15
(4,837 Views)

I just spoke with the drive vendor and found that the register is configured to take 32-bit signed number. If that's the case, would NI modbus vis support it? If so, how?

Thanks,

0 Kudos
Message 4 of 15
(4,836 Views)

B.2 Multi-word quantities

 

In principle, any data structure which can be ‘cast’ to an array of 16-bit words can be transported, and will arrive unchanged on a machine with the same data representation.

 

The following PLC data types should be noted

B.2.1 984 Data Types

 

984 16-bit Unsigned Integer

 

Natural meaning: bit 15 - 0 of integer = bit 15 - 0 of register

 

984 16-bit Signed Integer

 

Natural meaning: bit 15 - 0 of integer = bit 15 - 0 of register

 

984 ASCII

 

Although PLC’s had no text manipulation capabilities as such, the original ladder language editors allowed registers to be displayed as 2 ASCII characters each. The first character displayed was the UPPER byte (bits 15 - 😎 and the second character displayed was the LOWER byte (bits 7- 0). Note in particular that this is the reverse of any use of a character array in C or other high level languages on modern PLC’s.

 

984 Floating point

 

Intel single precision real

First register contains bits 15 - 0 of 32-bit number (bits 15 - 0 of significand)

Second register contains bits 31 - 16 of 32-bit number (exponent and bits 23 - 16 of significand)

 

984 Single precision unsigned decimal

 

Although the range of values is limited at 0 - 9999, the data representation is the same as a 16-bit unsigned integer

 

984 Double precision unsigned decimal

 

This data format is now little-used, except to drive old-style 4-digit decade displays.

The range of values is 0 to 99999999. The first register contains the MOST significant 4 digits, the second register contains the LEAST significant 4 digits, each expressed as binary values in the range 0-9999.

 

My suggestion would be to download a demo of the Kepware Modbus OPC server program and use portmon to watch the communications on the serial port. Setup a single tag as signed 32 bit integer. Modbus transfer 16 bit values. It is up to the user to convert the values into proper format.

0 Kudos
Message 5 of 15
(4,830 Views)

Chokro,

If the Slave device supports signed 16-bit numbers then you won't be able to write values higher than 32767.  As for writing out negative values, you will again want to check with the device people how they expect the data-byte formatting.

-Khalid

0 Kudos
Message 6 of 15
(4,818 Views)
Khalid,
The device supports signed 32-bit values. Attached I have a test program 01_MB_DRIVE_TEST01.vi, where I am writing 14000.0 to a single register. Let me know what I am doing wrong?
 
Thanks,
 
0 Kudos
Message 7 of 15
(4,791 Views)

Two things:

1.  You are multiplying the number by 10, so you are really trying to write 140000 (and not 14000). 

2.  Since the Modbus uses U16s, the 140000 is getting coerced to 8928 (which is what your device should be seeing).  Typically, to support 32-bit numbers, the device manufacturers read two adjacent 16-bit numbers and then construct the 32-bit number.  See if this is how they do it in your case as well.  If yes, then you will need to split your 140000 into two 16-bit numbers and then write to two registers (i.e., setting the Quantity to 2). 

Hope this helps.

-Khalid

0 Kudos
Message 8 of 15
(4,786 Views)
Typecast the value into a string and then convert it into a byte array.
0 Kudos
Message 9 of 15
(4,773 Views)

A SGL can be used to represent the number.  Since Modbus expects U16s (two bytes), we then cast the SGL number to a U32 first, and then use the Split Number function to get the two U16s.  These should be written to the two adjacent holding registers.  The words may have to be swapped depending on how the device expects them. 

Regards,

-Khalid

0 Kudos
Message 10 of 15
(4,756 Views)