Minimalmodbus I can read data, but i cannot write it (RTU)

661 Views Asked by At

I´m using minimalmodbus python library to communicate my Raspberry Pi with "Spacelogic Thermostat TC900" (RTU).

I have no problem reading the data, but when I try to write on it, the console shows the next error:

No communication with the instrument (no answer)

From my point of view, this error has no sense, because if I can read, I must have communication with the instrument.

minimalmodbus homepage: https://minimalmodbus.readthedocs.io/en/stable/index.html

minimalmodbus write_bits page: https://minimalmodbus.readthedocs.io/en/stable/apiminimalmodbus.html?highlight=write_bits#minimalmodbus.Instrument.write_bits

My code:

#imports
import minimalmodbus
import serial

#instr creation
instr = minimalmodbus.Instrument('/dev/ttyUSB0', 1)

#instr config
instr.serial.baudrate = 9600
instr.serial.timeout = 1
instr.mode = minimalmodbus.MODE_RTU
instr.serial.parity = serial.PARITY_ODD
instr.serial.bytesize = 8
instr.serial.stopbits = 1
instr.debug = True

try:
    print("READ:")
    print(instr.read_bits(4, 3, functioncode=1))
except Exception as e:
    print("Error reading coil: " , e)

try:
    print("WRITE")
    instr.write_bits(5, [True,False])
except Exception as e:
    print("Error writing Coil: " , e)

Console output:

READ:
MinimalModbus debug mode. Will write to instrument (expecting 6 bytes back): '\x01\x01\x00\x04\x00\x03=Ê' (01 01 00 04 00 03 3D CA)
MinimalModbus debug mode. Clearing serial buffers for port /dev/ttyUSB0
MinimalModbus debug mode. No sleep required before write. Time since previous read: 25577762.09 ms, minimum silent period: 4.01 ms.
MinimalModbus debug mode. Response from instrument: '\x01\x01\x01\x04PK' (01 01 01 04 50 4B) (6 bytes), roundtrip time: 42.5 ms. Timeout for reading: 1000.0 ms.

[0, 0, 1]
WRITE
MinimalModbus debug mode. Will write to instrument (expecting 8 bytes back): '\x01\x0f\x00\x05\x00\x02\x01\x01ÓW' (01 0F 00 05 00 02 01 01 D3 57)
MinimalModbus debug mode. Clearing serial buffers for port /dev/ttyUSB0
MinimalModbus debug mode. Sleeping 1.98 ms before sending. Minimum silent period: 4.01 ms, time since read: 2.03 ms.
MinimalModbus debug mode. Response from instrument: '' () (0 bytes), roundtrip time: 1001.8 ms. Timeout for reading: 1000.0 ms.

Error writing Coil:  No communication with the instrument (no answer)

I tried pymodbus too, but the same happened, I only could read data.

I thought the error could be on the thermostat, but I used Modbus Poll to write on it and I had no problem.

0

There are 0 best solutions below