相关文章推荐
I want to get the value of the LED of the Arduino running in the following PLC program using Modbus RTU (Serial),
but I can't get it because I don't know the "register address" and "Modbus function code".
If anyone knows how to solve this, please let me know.
The Python program used is as follows.
import minimalmodbus

# Set the serial port and Modbus address of the microcontroller
instrument = minimalmodbus.Instrument('COM3', 1) 
instrument.serial.baudrate = 115200  # Set the baud rate
instrument.serial.bytesize = 8      # Set the data bits to 8
instrument.serial.parity = minimalmodbus.serial.PARITY_NONE  # Set parity
instrument.serial.stopbits = 1      # Set the stop bits
instrument.mode = minimalmodbus.MODE_RTU  # Set Modbus RTU mode

try:
    read_value = instrument.read_register(__adress??__, functioncode=__function???__, signed=True)
    print(read_value)
except Exception as e:
    print("Error:", str(e))

instrument.serial.close()
I ran the python you taught me, but I can't communicate. I don't know why communication is not possible, so if there is an error in the program, please let me know.

I tried the code below.
- For the address, modbus slave ID (1) was used.
- The number of coils was only blink_led, so I set it to 1.
>>> from pymodbus.client import ModbusSerialClient as ModbusClient
>>> client = ModbusClient(method = "rtu", port="COM3", baudrate= 115200, timeout=0.1)
>>> client.connect()
True
>>> client.read_coils(1,1)
ModbusIOException('[Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 4 bytes (0 received)')
Thank you for letting me know.
Communication is not possible even after changing the function code.
I executed adress and function code with all patterns from 0 to 9, but the same error occurred.
I couldn't find a solution even after looking on the web and YouTube...
The microcontroller I'm using is Arduino UNO, could that be the cause?
>>> from pymodbus.client import ModbusSerialClient as ModbusClient
>>> client = ModbusClient(method = "rtu", port="COM3", baudrate= 115200, timeout=2)
>>> client.connect()
True
>>>
>>> rr = client.read_coils(1, 3)
>>> rr.bits
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'ModbusIOException' object has no attribute 'bits'
I checked for errors using isError(), but it seems that there are still errors.
The error message was "ModbusIOException('[Input/Output] No Response received from the remote slave/Unable to decode response')".
Was there anyone else who had similar problems communicating?
If you have ever encountered someone who was unable to communicate in the same way, how did that person solve this problem?
If your URL is correct, you'll see an image preview here. Large images may take a few minutes to appear. Remember: Using others' images on the web without their permission may be bad manners, or worse, copyright infringement.
 
推荐文章