I have a problem that might seem really easy for people used to working with serial interfaces, but it is the first time for me.
We want to automate our temperature-dependent probe station by using a temperature controller (CB100 / CB400 / CB500 / CB700 / CB900 series by RKC Instruments: https://www.rkcinst.co.jp/english/download-center/?dc_cat=15#). The controller is connected to a master Dell OptiPlex5060 small tower (https://www.dell.com/en-us/work/shop/desktops-all-in-one-pcs/optiplex-5060-small-form-factor/spd/optiplex-5060-desktop/cto01o5060sffus) running Windows 10 Pro (version 1903, build 18362.267) through a RS485 to USB adapter.
The device appears in device manager ('COM3' port), with hopefully the correct drivers installed (see this screenshot). Also, the device settings were matched between the controller and master computer to the following values (port settings in device manager):
- Baudrate = 9600;
- Bitsize = 8;
- Parity = None;
- Stop bits = 1
I think I got the device correctly connected by using the pymodbus library with the following code:
Connect to RS485 device - pymodbus
#Import useful modules
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
#For the first test, I manually read the configuration from the
#the controller display and hard-code the values in the script.
d_port='COM3' #Device address
commspeed={} #Communication speed
commspeed_table={
'0':2400,
'1':4800,
'2':9600,
'3':19200,
}
commspeed['flag']='2'
commspeed['value']=commspeed_table[commspeed['flag']]
bitconf={} #Bit configuration
bitconf_table={
'0':(8,'N',1),
'1':(8,'N',2),
'2':(7,'E',1),
'3':(7,'E',2),
'4':(7,'O',1),
'5':(7,'O',2),
}
bitconf['flag']='0'
bitconf['size'],bitconf['parity'],bitconf['stopbit']=\
bitconf_table[bitconf['flag']]
intime={}
intime['flag']='5'
intime['value']=round(int(intime['flag'])*1.666,0)
def main():
modbus=ModbusClient(method='ascii',port='COM3',\
baudrate=commspeed['value'],stopbits=bitconf['stopbit'],\
bytesize=bitconf['size'],parity=bitconf['parity'],\
timeout=1)
modbus.connect()
if __name__ == "__main__":
main()
However, when I try to read it with this code (the address of the device is 001Hex):
r = modbus.read_holding_registers(0x0001,1)
print(r)
I get this error:
Modbus Error: [Input/Output] Modbus Error: [Invalid Message] Incomplete message received, expected at least 5 bytes (1 received).
Could anyone help with suggesting where is the mistake? What is the minimal working code for making modbus work? Why it seems to be so difficult to find quick online resources?
Thank you very much, any help is highly appreciated!
read_holding_registers
has 3 parameters;read_holding_registers(address, count, unit)
and theunit
parameter defaults to0x00
? Perhaps you are reading from device with 'address'0x00
instead? – Bosz