I am using a RS485 to USB module to connect a thermocouple module to my computer. I installed a CH340 driver and the device appears in the device manager.
I ordered the RS485 to USB module of Amazon and only have very limited instructions how to read the information from the thermocouple.
The communication happens via Modbus. I got the communication configuration from the product site, but am not having success with getting any readings using pymodbus. This is the code I am using.
from pymodbus.client import ModbusSerialClient as ModbusClient
client = ModbusClient(
method='rtu', # bitsize = 8 -> likely rtu
port='COM4',
baudrate=9600, -> data sheet
parity='N', -> check digit = none
stopbits=1, -> data sheet
bytesize=8, -> data sheet
timeout=5 -> guessing
)
# Connect to the Modbus server
client.connect()
# Modbus configuration
device_address = 1 -> device address = 1 from data sheet
register_address = 0 -> register address = 0x01 from data sheet
number_of_reads = 1 -> data sheet
# Read the holding registers
response = client.read_holding_registers(register_address, number_of_reads, unit=device_address)
# Check if the read was successful
if response.isError():
print(client.connected)
print(f"Error reading from Modbus device: {response}")
else:
# Extract and process the temperature value
register_value = response.registers[0] # Get the first register value
temperature = register_value / 10.0 # Convert to temperature
print(f"Temperature: {temperature:.1f} °C")
However I don’t get any readouts. I only receive the following error message:
Error reading from Modbus device: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 4 bytes (0 received)
Does anybody have an idea what I might be doing wrong in my approach with pymodbus?
Thanks!
Sharper415 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.