hello I am currently working on a MFC from Alicat using Pymodbus and I keep encountering this error
Successfully connected to the Modbus server
Reading Mass Flow from address 1209
Unexpected number of registers received at address 1209. Expected 2, got 0
Failed to read Mass Flow from address 1209
Reading Device Status from address 1201
Unexpected number of registers received at address 1201. Expected 2, got 0
Failed to read Device Status from address 1201
Reading Pressure from address 1203
Unexpected number of registers received at address 1203. Expected 2, got 0
Failed to read Pressure from address 1203
Reading Temperature from address 1205
Unexpected number of registers received at address 1205. Expected 2, got 0
Failed to read Temperature from address 1205
Reading Volumetric Flow from address 1207
Unexpected number of registers received at address 1207. Expected 2, got 0
Failed to read Volumetric Flow from address 1207
I am using the provided data from the Bulletin and im still getting this error.
This is the code im using to troubleshoot(Ive taken off the IP address of the MFC):
from pymodbus.exceptions import ModbusException
import time
def read_registers(client, address, count=2):
try:
response = client.read_holding_registers(address, count, unit=1)
if not hasattr(response, 'registers'):
print(f"Error reading registers at address {address}: {response}")
return None
if len(response.registers) != count:
print(f"Unexpected number of registers received at address {address}. Expected {count}, got {len(response.registers)}")
return None
return response.registers
except ModbusException as e:
print(f"ModbusException reading registers at address {address}: {e}")
return None
except Exception as e:
print(f"General Exception reading registers at address {address}: {e}")
return None
def main():
client = ModbusTcpClient('') # Replace with your MFC IP address
if not client.connect():
print("Unable to connect to the Modbus server")
return
else:
print("Successfully connected to the Modbus server")
addresses = {
'mass_flow': 1209,
'device_status': 1201,
'pressure': 1203,
'temperature': 1205,
'volumetric_flow': 1207
}
while True:
for name, address in addresses.items():
print(f"Reading {name.replace('_', ' ').title()} from address {address}")
registers = read_registers(client, address)
if registers is not None:
print(f"{name.replace('_', ' ').title()}: {registers}")
else:
print(f"Failed to read {name.replace('_', ' ').title()} from address {address}")
time.sleep(10)
client.close()
if __name__ == "__main__":
main()
I tried going over the manual and other sources to find the registers but they are all the same.
Johnny Trevino is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.