Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

how to write negative value in MODBUS register in a device.

hi all,

 

I am using NI Modbus Library to communicate with a MODBUS Device on RS 485 Network.

On the block diagram, i just placed the MB Serial Master Query.vi and selected Write Single Register which has a function code of 0x06 in hex.

 

My Questions are:

 

1. Suppose i am writing to a register whose address in the device is 39204 as the input of this vi has a U16 data type to be written as a register value. In Starting address Control, what address should i give? 39204 in decimal or just 9204 in decimal as the function code switches the series for input register in the device by its own (series 30000 in MODBUS) as shown in Fig. 1. I just given the address as 39203 as in standard MODBUS the address is represented as -1 of the actual address to call (39204 - 1). I am getting the response and working fine.

 

2. There is a requirement that one register have the range for configuration as -50 to 50. My question is how to write -50 to the register. I had read from NI Forum that to load a negative value it should be subtracted from 65535 (0XFFFF). I just simply changed the representation of the control in Fig. 1 from U16 to I16 and wrote -50 into this control and send to the device. The device responded with the response data as " 01 06 00 AE FF CD E9 E1 ".

I am not sure of this whether the device register has loaded itself with -50 or not. When i queried the same register i got the response as " 01 04 02 FF CD + CRC Bytes "

 

Is this write or suggest any other solution or method to do this.

Please tell how to load a register with a negative value simply, or any code or example made earlier.

 

Thanks & Regrads,

Samriddh Sarbalhi

 

 

 

0 Kudos
Message 1 of 7
(11,191 Views)

Hi,

 

I just forget to add the Figure.

I will tag the same by tomorrow because the fig is in my office desktop.

 

Regards,

 

Samriddh Sarbalhi

0 Kudos
Message 2 of 7
(11,185 Views)

Hi,

 

Here is the figure.

Please let me know for the solution.

 

 

Regards,

Samriddh Sarbalhi

0 Kudos
Message 3 of 7
(11,161 Views)

Hi,

 

Can anybody Please respond to this question.

Where are you all (Ravens Fan, Mr. Hillman and other people).

 

Regrads,

Samriddh Sarbalhi

0 Kudos
Message 4 of 7
(11,148 Views)

Hi Samriddh,

 

I am one of the other people 😉

 

I think most of the thing you are asking depends on the ModBus device  you are using.

 

I know that addressing can be different because the first digits tells you what function MB should use. But that is not always true. So check your device for the right address. In you example of write a single register you use address 0xAE (174) something completely different.

 

Also for negative number you should check your device. What you write you will read back but that does not mean that it is the right value.

You use a one's complement value but I think most devices expect a two's complement value.

 

Hope this helps.

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

Hi KC,

 

Very much relief having your reply.

 

I checked for the Register Address and the concept of 39204 and 9204 seems to be faulty in my case as i am able to get the reply from my MODBUS Device by calling 9923 and same by 0xAE.

I believe if the address would have been wrong, then MODBUS Device will definately send Exception code relevant to faulty Register Address to me.

 

Secondly, As far as Negative number is concerned, i must check with the coder of the MODBUS at device end. Moreover, the reply i am getting is correct though it doesn't gaurantees for true, otherwise the device must send an exception code regarding register values in terms of range.

 

Third, Please expalin a little bit about one's complement and two's complement phenomenon that you had written in your last line of your reply and how it is related to MODBUS implementation.

 

I didn't get that.

 

Regards,

 

Samriddh Sarbalhi

0 Kudos
Message 6 of 7
(11,129 Views)

Hi,

 

One's complement is simply invert the value

 

Two's complement is invert and plus 1 See this

 

It is device dependent and not ModBus. 

0 Kudos
Message 7 of 7
(11,124 Views)