May-07-2017, 05:18 AM
hello friends
i want to communicate between raspberry and a microcontroller(xmega32) that transmit and recieve its information by ascii modbus protocol on its serial
so i installed pymodbus3 on the raspberry and wrote the following program...
i want to communicate between raspberry and a microcontroller(xmega32) that transmit and recieve its information by ascii modbus protocol on its serial
so i installed pymodbus3 on the raspberry and wrote the following program...
import serial import pymodbus3 from pymodbus3.pdu import ModbusRequest from pymodbus3.client.sync import ModbusSerialClient as ModbusClient #initialize a serial RTU client #instance from pymodbus3.transaction import ModbusRtuFramer import logging logging.basicConfig() log = logging.getLogger() log.setLevel(logging.DEBUG) #count= the number of registers to read #unit= the slave unit this request is targeting# #address= the starting address to read from# client= ModbusClient(method = "ascii", port="/dev/ttyAMA0",stopbits = 1, bytesize = 8, parity = 'N', baudrate= 57600, timeout=2) #Connect to the serial modbus server# connection = client.connect() print (connection) ##.Starting add, num of reg to read, slave unit# result= client.read_holding_registers(0x00,3,unit= 0x05) print(result) #Closes the underlying socket connection# client.close()i got this error
Error:DEBUG:pymodbus3.transaction:Running transaction 1
Traceback (most recent call last):
File "/home/pi/start/serial/modbus/pymodbuss3/firss.py", line 24, in <module>
result= client.read_holding_registers(0x00,3,unit= 0x05)
File "/home/pi/pymodbus3/client/common.py", line 117, in read_holding_registers
return self.execute(request)
File "/home/pi/pymodbus3/client/sync.py", line 82, in execute
return self.transaction.execute(request)
File "/home/pi/pymodbus3/transaction.py", line 70, in execute
'Server responded with bad response'
pymodbus3.exceptions.ModbusIOException: Modbus Error: [Input/Output] Server responded with bad response
why? i saw the raspberry tx output by laptop..the transmitted string was:050300000003F5 in your oponion what is the problem? i think the problem is due to the end of ascii frame(/r , /n)(10,13 hex)..micro don't understand the end of the frame...how can i include (/r , /n)(10,13 hex) by commands of pymodbus3 module