tasanen Posted November 14, 2023 Report Share Posted November 14, 2023 Hi, I am pretty noob in Unitronics and Modbus, but I am trying my best to learn on the go. We have a V1210 with modbus configured and I am trying to read holding registers from there as I would like to get this data to my linux server every 1-2 seconds. I have tried to follow https://pymodbus.readthedocs.io/en/latest/source/client.html official documentation and create a .py for collecting the data. It seems that I am able to get the connection successfully and also my read request (modbus code 3) is sent successfully, but V1210 is responding with non-standard response, which is not recognised as Modbus protocol by my python client or Wireshark. I try to give all relevant information, but please ask more if my problem is not clear or detailed enough for giving answers. Modbus is working normally between this V1210 and other V1210:s we have with same connection details. I have tried to also use 40321 directly in the code, but it has the same results, and according to my understanding of pymodbus we should use 320. If anyone has example code of pymodbus client read holding registers towards V1210 I would appreciate a lot to receive it! My modbus config in V1210: Network ID: 255 Port 20257 Error I get: DEBUG:pymodbus.logging:Connection to Modbus server established. Socket ('IP of PLC', 59772) DEBUG:pymodbus.logging:Current transaction state - IDLE DEBUG:pymodbus.logging:Running transaction 1 DEBUG:pymodbus.logging:SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0x9d 0x80 0x0 0x1 DEBUG:pymodbus.logging:New Transaction state "SENDING" DEBUG:pymodbus.logging:Changing transaction state from "SENDING" to "WAITING FOR REPLY" DEBUG:pymodbus.logging:Transaction failed. (Modbus Error: [Invalid Message] Incomplete message received, expected at least 8 bytes (6 received)) DEBUG:pymodbus.logging:Processing: DEBUG:pymodbus.logging:Getting transaction 1 DEBUG:pymodbus.logging:Changing transaction state from "PROCESSING REPLY" to "TRANSACTION_COMPLETE" Register Values: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] Incomplete message received, expected at least 8 bytes (6 received) My python code: import logging from pymodbus.client import ModbusTcpClient from pymodbus.exceptions import ModbusIOException # Configure logging for pymodbus logging.basicConfig() log = logging.getLogger('pymodbus') log.setLevel(logging.DEBUG) # Unitronics Modbus TCP configuration details PLC_IP_ADDRESS = "IP of the PLC" PLC_PORT = 20257 UNIT_ID = 255 # Network ID TIMEOUT = 10 # Timeout in seconds (100 units of 10 ms each) RETRIES = 3 # Number of retries # Create a Modbus TCP client client = ModbusTcpClient(PLC_IP_ADDRESS, port=PLC_PORT, timeout=TIMEOUT, retries=RETRIES) # Connect to the PLC client.connect() # Reading holding registers corresponding to MI320 to MI322 START_ADDRESS = 320 # Start at MI320 (Modbus address 40321) REGISTER_COUNT = 3 # Read MI320 to MI322 (3 registers) try: # Read holding registers response = client.read_holding_registers(START_ADDRESS, REGISTER_COUNT, unit=UNIT_ID) # Check if response is an error if response.isError(): print("Error reading registers:", response) else: register_values = response.registers print("Register Values:", register_values) except ModbusIOException as e: print("Modbus IO error:", e) except Exception as e: print("General error:", e) finally: # Close the client connection client.close() Link to comment Share on other sites More sharing options...
MVP 2023 Joe Tauser Posted November 14, 2023 MVP 2023 Report Share Posted November 14, 2023 The default port for Modbus TCP is 502. You do have to initialize it in your PLC code. Can you upload your PLC program so we can see what you've done? Joe T. Link to comment Share on other sites More sharing options...
tasanen Posted November 14, 2023 Author Report Share Posted November 14, 2023 43 minutes ago, Joe Tauser said: The default port for Modbus TCP is 502. You do have to initialize it in your PLC code. Can you upload your PLC program so we can see what you've done? Joe T. Hi Joe, Here is the requested image from the start of the program. We do have Modbus also in the port 502 and response from that port is identical to the one in 20257. I have been requested to use port 20257, although I don't think it matters too much which one I use. I have help from our side for building the program, but I do not have help for Modbus or pymodbus. -Tasanen Link to comment Share on other sites More sharing options...
MVP 2023 Joe Tauser Posted November 14, 2023 MVP 2023 Report Share Posted November 14, 2023 OK, that network needs to be broken into about four separate simpler networks. The compiler is probably having a nervous breakdown. What is the purpose of MB 100? Normally just Init the sockets and run the configs just once at power-up. I think you're way over-complicating this. Are you configuring two Modbus IP ports because you want to have a Master and a Slave in the same unit? Joe T. Link to comment Share on other sites More sharing options...
Fernando Castro Posted November 15, 2023 Report Share Posted November 15, 2023 11 hours ago, tasanen said: Hi Joe, Here is the requested image from the start of the program. We do have Modbus also in the port 502 and response from that port is identical to the one in 20257. I have been requested to use port 20257, although I don't think it matters too much which one I use. I have help from our side for building the program, but I do not have help for Modbus or pymodbus. -Tasanen First of all this rung is awful. No offense to you but visilogic is not a FBD programming, is ladder logic with some function blocks, Visilogic is kind of old and I wouldn't try to push everything on a single rung Which memory addres are you trying to read from the PLC? To make sure you are doing the correct math for the client modbus addresing. Link to comment Share on other sites More sharing options...
Fernando Castro Posted November 15, 2023 Report Share Posted November 15, 2023 Also always test your modbus communication with something like modbuss poll or modbus master simulator radzio it is free an you just install it on the computer, the modbus configuration is intuitive, and you will be able to test if the issue is on modbus py or on the PLC side. Link to comment Share on other sites More sharing options...
pascal Posted July 24 Report Share Posted July 24 maybe a little late, but just for knowing : you send byte 0+1 = identifier (can be anything) (0x0 0x1) byte 2+3 = always 0x0 0x0 byte 4+5 = length of the rest of the telegram (0x0 0x6, means still 6 bytes to send) byte 6 = slave adres (0x0 means adres 255) (I know....it's modbus) byte 7 : function code (0x3 -> read holding register) byte 8 + 9 : adress of start of holding register to read (0x9d80 = adres 40320.... -> maybe this is the mistake ?) byte 10 + 11 : number of registers to read (0x0 0x1 -> means 1 register or 2 bytes) in your python program, you ask 3 registers starting from 40321 (see figure below) but when I see what you are sending, it's not what you asked... Link to comment Share on other sites More sharing options...
pascal Posted July 25 Report Share Posted July 25 Tasanen, I've found something else what could be the problem.... you want to read MI320 of an V1210, you have to read from adres 320 (or 321...) and not 40321.... A V1210 is an enhanced vision PLC, so when you look into the help file, there you can find the correct adress ranges for communicating modbus Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now