python minimalmodbus write_registers() writes wrong value to certain register

38 views Asked by At

I tried to write a list of values [123,456,555,452,6121] using the write_registers() function of the minimalmodbus library using Python.
The registers start from register id 40184.
I got the error response ' No communication with the instrument (no answer)'. When I tried reading the values it returned [123, 0, 555, 452, 6121] as the output.

My code:

 import minimalmodbus
 import serial
 import time

 instrument = minimalmodbus.Instrument('COM10',1)  
 instrument.serial.baudrate = 19200
 instrument.serial.parity = serial.PARITY_NONE
 instrument.serial.bytesize = 8
 instrument.serial.stopbits = 1
 instrument.serial.timeout = 10
 instrument.mode = minimalmodbus.MODE_RTU
 instrument.serial.timeout = 0.05

 try:
    values=[123,456,555,452,6121]
    instrument.write_registers(40184, values)
   
 except Exception as e:
     print(f"Error: {e}")
0

There are 0 answers