Per the manual of the device I want to communicate with, the message should be structured like this:
address, functioncode, 0, StartRegister, 0, NumRegs, crc-L, crc-H
meaning that if the address is 1, function code is 04, start register is 0, and the number of registers is 1, then the message should look like this:
1, 4, 0, 0, 0, 1, 0, 0
The last two on the right are reserved for the crc values which I already know how to calculate and append.
What is the correct method from minimalmodbus that I can use to send this message successfully?
This is the code I have so far. It doesn't work.
import minimalmodbus
import serial
instrument = minimalmodbus.Instrument('COM1', 1)
instrument.serial.port
instrument.serial.baudrate = 19200
instrument.serial.parity = serial.PARITY_EVEN
instrument.serial.bytesize = 8
instrument.serial.stopbits = 1
instrument.mode = minimalmodbus.MODE_RTU
instrument.serial.timeout = 1
data = [1, 4, 0, 0, 0, 1, 49, 202]
instrument.write(data)
respose = instrument.readline()
print (respose)
instrument.close()