I am trying to read a 16 Bit word from a Modbus device. When the following reaches 32767 it rolls over to negative. Is there a way I can read larger values from a single register?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2020-07-08
I have attempted a few things but am not sure this is what I need. Should the standard method int[] ReadHoldingRegisters(int startingAddress, int quantity) be able to read int values above 32767? It appears tha the other methods combine multiple registers to create either the double, or float. I was able to get the FLoat conversion to work fine on registers that use IEEE -754 , but in this case I just want to read one register that has a value that reaches 65,000 plus. I feel I am just using the ReadHoldingRegisters method incorrectly, and perhaps it is what I need. Can you provide any additional thoughts on what I may have set up incorrectly? This line gives some very large result:
double varTest4 = ModbusClient.ConvertRegistersToDouble(modbusClient.ReadHoldingRegisters(0, 4));
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That is NOT a Modbus Issue, thats simple C# programming and you'll find some anwers already in this duscussion (or ask google). A Modbus Register contains 16 Bit and is handles is signed value -32768 - 32768. If you need values between 0 - 65535, you have to convert.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying to read a 16 Bit word from a Modbus device. When the following reaches 32767 it rolls over to negative. Is there a way I can read larger values from a single register?
int[] readHoldingRegisters = modbusClient.ReadHoldingRegisters(0, 8);
label2.Text = readHoldingRegisters[7].ToString();
Double - Please check a few Posts below
I have attempted a few things but am not sure this is what I need. Should the standard method int[] ReadHoldingRegisters(int startingAddress, int quantity) be able to read int values above 32767? It appears tha the other methods combine multiple registers to create either the double, or float. I was able to get the FLoat conversion to work fine on registers that use IEEE -754 , but in this case I just want to read one register that has a value that reaches 65,000 plus. I feel I am just using the ReadHoldingRegisters method incorrectly, and perhaps it is what I need. Can you provide any additional thoughts on what I may have set up incorrectly? This line gives some very large result:
double varTest4 = ModbusClient.ConvertRegistersToDouble(modbusClient.ReadHoldingRegisters(0, 4));
That is NOT a Modbus Issue, thats simple C# programming and you'll find some anwers already in this duscussion (or ask google). A Modbus Register contains 16 Bit and is handles is signed value -32768 - 32768. If you need values between 0 - 65535, you have to convert.
so why can't we write decimal value? float values are rounded