Respected fellow designers,
I am trying to use communicate with XMC4700 relax kit using MODBUS RTU.
I am using pymodbus python library.
I am able to write to the holding register that I confirm using Radzio tool.
However I am unable to read the data.
Kindly help.
I am using the DAVE example (non os RTU) without any modification except the address of slave set as "1".
***********Python Code*********
import struct
import binascii
import time
import logging
try:
from IPython import get_ipython
get_ipython().magic('clear')
get_ipython().magic('reset -f')
except:
pass
time.sleep(2)
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
from struct import *
from pymodbus.client import ModbusSerialClient
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
# Connection to device
client = ModbusSerialClient(
port="COM8",
baudrate=19200,
method="RTU",
timeout=0.9,
parity= 'N',
strict = False,
)
client.connect()
time.sleep(2)
log.debug("Write to a holding register and read back")
client.write_registers(10,11,unit=1)
client.write_registers(11,22,unit=1)
rq = client.write_register(12, 33, unit=1)
time.sleep(20)
rr = client.read_holding_registers(10, 1, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error
assert(rr.registers[0] == 10) # test the expected value
client.close()
print (rq)
print (rr)
*********Console Output*************
DEBUG:root:Write to a holding register and read back
DEBUG:pymodbus.logging:Current transaction state - IDLE
DEBUG:pymodbus.logging:Running transaction 1
DEBUG:pymodbus.logging:SEND: 0x0 0x10 0x0 0xa 0x0 0x1 0x2 0x0 0xb 0xea 0xad
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] No response received, expected at least 4 bytes (0 received))
DEBUG:pymodbus.logging:Retry on empty response - 1
DEBUG:pymodbus.logging:Changing transaction state from "WAITING_FOR_REPLY" to "RETRYING"
DEBUG:pymodbus.logging:Sleeping 0.3
DEBUG:pymodbus.logging:SEND: 0x0 0x10 0x0 0xa 0x0 0x1 0x2 0x0 0xb 0xea 0xad
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] No response received, expected at least 4 bytes (0 received))
DEBUG:pymodbus.logging:Frame - [b''] not ready
DEBUG:pymodbus.logging:Getting transaction 0
DEBUG:pymodbus.logging:Changing transaction state from "PROCESSING REPLY" to "TRANSACTION_COMPLETE"
DEBUG:pymodbus.logging:Current transaction state - TRANSACTION_COMPLETE
DEBUG:pymodbus.logging:Running transaction 2
DEBUG:pymodbus.logging:SEND: 0x0 0x10 0x0 0xb 0x0 0x1 0x2 0x0 0x16 0x2b 0x75
DEBUG:pymodbus.logging:Changing state to IDLE - Last Frame End - None Current Time stamp - 1683201916.432933
DEBUG:pymodbus.logging:New Transaction state "SENDING"
DEBUG:pymodbus.logging:Changing transaction state from "SENDING" to "WAITING FOR REPLY"
DEBUG:pymodbus.logging:No response received, Expected 8 bytes Received 0 bytes !!!!
DEBUG:pymodbus.logging:Changing transaction state from "WAITING FOR REPLY" to "PROCESSING REPLY"
DEBUG:pymodbus.logging:RECV:
DEBUG:pymodbus.logging:Retry on empty response - 1
DEBUG:pymodbus.logging:Changing transaction state from "WAITING_FOR_REPLY" to "RETRYING"
DEBUG:pymodbus.logging:Sleeping 0.3
DEBUG:pymodbus.logging:SEND: 0x0 0x10 0x0 0xb 0x0 0x1 0x2 0x0 0x16 0x2b 0x75
DEBUG:pymodbus.logging:New Transaction state "SENDING"
DEBUG:pymodbus.logging:Changing transaction state from "SENDING" to "WAITING FOR REPLY"
DEBUG:pymodbus.logging:No response received, Expected 8 bytes Received 0 bytes !!!!
DEBUG:pymodbus.logging:Changing transaction state from "WAITING FOR REPLY" to "PROCESSING REPLY"
DEBUG:pymodbus.logging:RECV:
DEBUG:pymodbus.logging:Frame - [b''] not ready
DEBUG:pymodbus.logging:Getting transaction 0
DEBUG:pymodbus.logging:Changing transaction state from "PROCESSING REPLY" to "TRANSACTION_COMPLETE"
DEBUG:pymodbus.logging:Current transaction state - TRANSACTION_COMPLETE
DEBUG:pymodbus.logging:Running transaction 3
DEBUG:pymodbus.logging:SEND: 0x0 0x6 0x0 0xc 0x0 0x21 0x88 0x0
DEBUG:pymodbus.logging:Changing state to IDLE - Last Frame End - None Current Time stamp - 1683201921.432023
DEBUG:pymodbus.logging:New Transaction state "SENDING"
DEBUG:pymodbus.logging:Changing transaction state from "SENDING" to "WAITING FOR REPLY"
DEBUG:pymodbus.logging:No response received, Expected 8 bytes Received 0 bytes !!!!
DEBUG:pymodbus.logging:Changing transaction state from "WAITING FOR REPLY" to "PROCESSING REPLY"
DEBUG:pymodbus.logging:RECV:
DEBUG:pymodbus.logging:Retry on empty response - 1
DEBUG:pymodbus.logging:Changing transaction state from "WAITING_FOR_REPLY" to "RETRYING"
DEBUG:pymodbus.logging:Sleeping 0.3
DEBUG:pymodbus.logging:SEND: 0x0 0x6 0x0 0xc 0x0 0x21 0x88 0x0
DEBUG:pymodbus.logging:New Transaction state "SENDING"
DEBUG:pymodbus.logging:Changing transaction state from "SENDING" to "WAITING FOR REPLY"
DEBUG:pymodbus.logging:No response received, Expected 8 bytes Received 0 bytes !!!!
DEBUG:pymodbus.logging:Changing transaction state from "WAITING FOR REPLY" to "PROCESSING REPLY"
DEBUG:pymodbus.logging:RECV:
DEBUG:pymodbus.logging:Frame - [b''] not ready
DEBUG:pymodbus.logging:Getting transaction 0
DEBUG:pymodbus.logging:Changing transaction state from "PROCESSING REPLY" to "TRANSACTION_COMPLETE"
DEBUG:pymodbus.logging:Current transaction state - TRANSACTION_COMPLETE
DEBUG:pymodbus.logging:Running transaction 4
DEBUG:pymodbus.logging:SEND: 0x0 0x3 0x0 0xa 0x0 0x1 0xa5 0xd9
DEBUG:pymodbus.logging:Changing state to IDLE - Last Frame End - None Current Time stamp - 1683201946.434835
DEBUG:pymodbus.logging:New Transaction state "SENDING"
DEBUG:pymodbus.logging:Changing transaction state from "SENDING" to "WAITING FOR REPLY"
DEBUG:pymodbus.logging:No response received, Expected 7 bytes Received 0 bytes !!!!
DEBUG:pymodbus.logging:Changing transaction state from "WAITING FOR REPLY" to "PROCESSING REPLY"
DEBUG:pymodbus.logging:RECV:
DEBUG:pymodbus.logging:Retry on empty response - 1
DEBUG:pymodbus.logging:Changing transaction state from "WAITING_FOR_REPLY" to "RETRYING"
DEBUG:pymodbus.logging:Sleeping 0.3
DEBUG:pymodbus.logging:SEND: 0x0 0x3 0x0 0xa 0x0 0x1 0xa5 0xd9
DEBUG:pymodbus.logging:New Transaction state "SENDING"
DEBUG:pymodbus.logging:Changing transaction state from "SENDING" to "WAITING FOR REPLY"
DEBUG:pymodbus.logging:No response received, Expected 7 bytes Received 0 bytes !!!!
DEBUG:pymodbus.logging:Changing transaction state from "WAITING FOR REPLY" to "PROCESSING REPLY"
DEBUG:pymodbus.logging:RECV:
DEBUG:pymodbus.logging:Frame - [b''] not ready
DEBUG:pymodbus.logging:Getting transaction 0
DEBUG:pymodbus.logging:Changing transaction state from "PROCESSING REPLY" to "TRANSACTION_COMPLETE"
Traceback (most recent call last):
File C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File f:\project_work\xmc4700_relax_projects\modbus_python_implementation\modbus_try_v05.py:51
assert(rq.function_code < 0x80) # test that we are not an error
AttributeError: 'ModbusIOException' object has no attribute 'function_code'
I believe that this issue is already being discussed in this thread
https://community.infineon.com/t5/XMC/MODBUS-communication-unable-to-read-holding-register-using-pyt...
We will continue our discussion in the original thread and I will go ahead and lock this thread.
Thanks and Regards,
Pradeep
I believe that this issue is already being discussed in this thread
https://community.infineon.com/t5/XMC/MODBUS-communication-unable-to-read-holding-register-using-pyt...
We will continue our discussion in the original thread and I will go ahead and lock this thread.
Thanks and Regards,
Pradeep