Modbus Binding and 32float will not work

Hallo,
i try to get some data from my energy counter.
My problem is when i use this .cfg

modbuspoll=1000
modbus:serial.slave1.connection=COM9:9600:8:even:1:rtu
modbus:serial.slave1.type=holding
modbus:serial.slave1.id=1
modbus:serial.slave1.start=8192
modbus:serial.slave1.length=2
modbus:serial.slave1.valuetype=float32

then i get this error

17:48:40.896 [DEBUG] [b.m.internal.ModbusSerialSlave:117 ] - connection was null, going to create a new one
17:48:41.131 [INFO ] [.b.modbus.internal.ModbusSlave:305 ] - ModbusSlave error getting responce from slave
17:48:41.334 [DEBUG] [b.m.internal.ModbusSerialSlave:117 ] - connection was null, going to create a new one
17:48:41.569 [INFO ] [.b.modbus.internal.ModbusSlave:305 ] - ModbusSlave error getting responce from slave
17:48:41.772 [DEBUG] [b.m.internal.ModbusSerialSlave:117 ] - connection was null, going to create a new one
17:48:42.007 [INFO ] [.b.modbus.internal.ModbusSlave:305 ] - ModbusSlave error getting responce from slave

Programms like modbuspoll bring the right Value.(32float)

If i delete the last line in my .cfg i get two registers with the right contense.

.items
/Modbus/
Group FF_Modbus “Modbus” (All)
Number MB_DT0 “DT0 [%d]” (FF_Modbus){modbus=“slave1:0”}
Number MB_DT1 “DT1 [%d]” (FF_Modbus){modbus=“slave1:1”}

event log:
2015-10-24 23:37:47 - MB_DT0 state updated to 17258
2015-10-24 23:37:48 - MB_DT1 state updated to 6554
2015-10-24 23:37:48 - MB_DT0 state updated to 17258
2015-10-24 23:37:48 - MB_DT1 state updated to 52429

so i can see it works but i cant get it like i want.

Sorry for my bad english.

Mike

Here is the part of the code that handles the float32 I’m not a java person unfortunatly.

	else if (type.equals(ModbusBindingProvider.VALUE_TYPE_FLOAT32)) {
		ByteBuffer buff = ByteBuffer.allocate(4);
		buff.put(registers[index * 2 + 0].toBytes());
		buff.put(registers[index * 2 + 1].toBytes());
		return new DecimalType(buff.order(ByteOrder.BIG_ENDIAN).getFloat(0));

Try %f for float

Number MB_DT0 “DT0 [%f]” (FF_Modbus){modbus=“slave1:0”

I got mine working that way.

.config

#ADAM 6060 12-Channel Digital I/O Module
modbus:tcp.slave2.connection=192.168.1.106:502
modbus:tcp.slave2.type=coil
modbus:tcp.slave2.start=16
modbus:tcp.slave2.length=6
modbus:tcp.slave2.valuetype=bit
modbus:tcp.slave3.connection=192.168.1.106:502
modbus:tcp.slave3.type=discrete
modbus:tcp.slave3.start=0
modbus:tcp.slave3.length=5
modbus:tcp.slave3.valuetype=bit
modbus:tcp.slave5.connection=192.168.1.106:502
modbus:tcp.slave5.type=input
modbus:tcp.slave5.start=10
modbus:tcp.slave5.length=2
modbus:tcp.slave5.valuetype=float32

.item

Number Fan1RPM_H "Compressor Exaust Fan RPM high [%f]" (modbus_raw,modbus) {modbus="slave5:0"}

thanks a lot,
now it works verry good.
Mike

awesome I added the information to the wiki

ps. can you add [SOLVED] to the beginning of the title.

Hallo,
Next problem, now i use Openhab on Raspberry pi2, every thing works fine, but Modbus Binding shows that:
2016-01-02 08:01:50.129 [DEBUG] [i.modbus.io.ModbusRTUTransport] - Sent: 01 03 20 20 00 02 ce 01
2016-01-02 08:01:50.631 [ERROR] [i.modbus.io.ModbusRTUTransport] - Last request: 01 03 20 20 00 02 ce 01
2016-01-02 08:01:50.633 [ERROR] [i.modbus.io.ModbusRTUTransport] - failed to read: Error reading response
2016-01-02 08:01:50.637 [INFO ] [.b.modbus.internal.ModbusSlave] - ModbusSlave error getting responce from slave
2016-01-02 08:02:00.639 [TRACE] [pi.modbus.net.SerialConnection] - Got Port Identifier
2016-01-02 08:02:00.653 [TRACE] [pi.modbus.net.SerialConnection] - Got Serial Port
2016-01-02 08:02:00.658 [TRACE] [pi.modbus.net.SerialConnection] - i/o Streams prepared
2016-01-02 08:02:00.660 [DEBUG] [i.modbus.io.ModbusRTUTransport] - Sent: 01 03 20 20 00 02 ce 01
2016-01-02 08:02:01.162 [ERROR] [i.modbus.io.ModbusRTUTransport] - Last request: 01 03 20 20 00 02 ce 01
2016-01-02 08:02:01.167 [ERROR] [i.modbus.io.ModbusRTUTransport] - failed to read: Error reading response
2016-01-02 08:02:01.168 [ERROR] [w.m.io.ModbusSerialTransaction] - execute try 1 error: I/O exception - failed to read
2016-01-02 08:02:01.170 [DEBUG] [i.modbus.io.ModbusRTUTransport] - Sent: 01 03 20 20 00 02 ce 01
2016-01-02 08:02:01.673 [ERROR] [i.modbus.io.ModbusRTUTransport] - Last request: 01 03 20 20 00 02 ce 01
2016-01-02 08:02:01.675 [ERROR] [i.modbus.io.ModbusRTUTransport] - failed to read: Error reading response
2016-01-02 08:02:01.677 [ERROR] [w.m.io.ModbusSerialTransaction] - execute try 2 error: I/O exception - failed to read
2016-01-02 08:02:01.678 [DEBUG] [i.modbus.io.ModbusRTUTransport] - Sent: 01 03 20 20 00 02 ce 01
2016-01-02 08:02:02.181 [ERROR] [i.modbus.io.ModbusRTUTransport] - Last request: 01 03 20 20 00 02 ce 01
2016-01-02 08:02:02.182 [ERROR] [i.modbus.io.ModbusRTUTransport] - failed to read: Error reading response
2016-01-02 08:02:02.186 [INFO ] [.b.modbus.internal.ModbusSlave] - ModbusSlave error getting responce from slave
2016-01-02 08:02:12.188 [TRACE] [pi.modbus.net.SerialConnection] - Got Port Identifier
2016-01-02 08:02:12.201 [TRACE] [pi.modbus.net.SerialConnection] - Got Serial Port
2016-01-02 08:02:12.205 [TRACE] [pi.modbus.net.SerialConnection] - i/o Streams prepared
2016-01-02 08:02:12.207 [DEBUG] [i.modbus.io.ModbusRTUTransport] - Sent: 01 03 20 20 00 02 ce 01

I use a CH-340 USB to RS485 converter

Mike

It might be related to this issue. What kind of binding configuration you are having?

Ok, i tested Modbus Binding 1.7.1 and 1.8.?
Mike

Yes you can test with those but please note that the linked issue is still unsolved. If you can paste your config here it is easier to know if this is something new or the old issue. Thanks

openhab.cfg

modbus:poll=10000
modbus:serial.slave1.connection=/dev/ttyUSB0:9600:8:even:1:rtu
modbus:serial.slave1.type=holding
modbus:serial.slave1.id=1
modbus:serial.slave1.start=8192
modbus:serial.slave1.length=2
modbus:serial.slave1.valuetype=float32

and i tried this on Raspberry with an rs485 shield:

modbus:poll=10000
modbus:serial.slave1.connection=/dev/ttyAMA0:9600:8:even:1:rtu
modbus:serial.slave1.type=holding
modbus:serial.slave1.id=1
modbus:serial.slave1.start=8192
modbus:serial.slave1.length=2
modbus:serial.slave1.valuetype=float32

Items:
/Modbus/
Group FF_Modbus “Modbus” (All)
Number MB_DT0 “Spannung [%.0f V]” (FF_Modbus){modbus=“slave1:0”}

Thanks Mike

Thanks @moe_hutz for the configuration. You have only one slave configured in modbus? So this might be different issue…

What I can say is that “Error reading response” comes from getting EOF from the serial connection (when trying to read response to the request). Are you sure you have the correct serial port parameters?

Yes, I think the parameters are the right one. On Windows it works very fine.

I know this is a lot to ask but can you try to test the connection using some other tool, for example this python tool? If some other tools/software works (on the linux), then it means the openhab modbus binding has issue.

Also, have you verified the device address (/dev/ttyAMA0 or /dev/USB0)?

hallo,
sorry for my late answer,
on minimalmodbus i can access to the slave.

Mike

This debug -
2016-01-02 08:01:50.129 [DEBUG] [i.modbus.io.ModbusRTUTransport] - Sent: 01 03 20 20 00 02 ce 01
doesn’t seem to match up with config -
modbus:serial.slave1.start=8192
modbus:serial.slave1.length=2

8192 is 20 00 in hex, I’d expect to see a send 01 03 20 00 00 02 … …

Hallo Rossko57,
the send is OK, Openhab on Windows and this Parameters work verry fine