First off, I don't know when you sleep or rest, but I appreciate your help in this matter.
I have tried many things many different ways and am getting more lost as I go. I cant find any manual or direction as to what command instructions and the relevant arguments are required to read the card. I might be using the wrong commands or even wrong code as I have mixed and jumbled things as I have experimented. Like I said I think i'm just getting more lost
I have a small program that tries to read only the discrete inputs but I get the same type of errors.
This is what gets returned when I run the following program:
Connected to Modbus device.
Error reading inputs: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 2 bytes (0 received)
Here is the python code:-
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
# Configure Modbus client
client = ModbusClient(
method='rtu',
port='/dev/ttyAMA0', # Replace with your serial port
baudrate=38400, # Match the card's baud rate
parity='N',
stopbits=1,
bytesize=8,
timeout=1
)
# Connect to the device
if client.connect():
print("Connected to Modbus device.")
# Replace `slave_id` and `input_register` with the specific addresses
slave_id = 1 # Modbus ID of your input card
input_register = 1 # Starting register of the inputs
try:
# Read 16 discrete inputs
response = client.read_discrete_inputs(input_register, 16, unit=slave_id)
if response.isError():
print(f"Error reading inputs: {response}")
else:
print(f"Input states: {response.bits}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
client.close()
else:
print("Failed to connect to Modbus device.")