I am trying to read data from a server device using python. I feel like my code should be doing something but it gives me this error:
Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 4 bytes (0 received)
I’m very sure all of the parameters are correct.
Here is the code I’m trying.
from pymodbus.client import ModbusSerialClient as ModbusClient
# Configure the client with a timeout
client = ModbusClient(
method='rtu',
port='COM4',
stopbits=1,
bytesize=8,
parity='E',
baudrate=115200,
timeout= 1 # Timeout in seconds
)
# Connect to the client
connection = client.connect()
if connection:
print("Port Opened...")
else:
print("Failed to open port")
client.close()
exit(1)
# Define the address and quantity to read
address = 36
quantity = 1
# Read holding registers
response = client.read_holding_registers(address, quantity, unit= 0) # Specify the correct unit
if not response.isError():
print("Read values:", response.registers)
else:
print("Failed to read:", response)
# Close the connection
client.close()
New contributor
William Laham is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.