Python Forum
Server responded with bad response
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Server responded with bad response
#1
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...

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
Reply
#2
Quote:the transmitted string was:050300000003F5
what were you expecting?
Reply
#3
(May-07-2017, 05:28 AM)Larz60+ Wrote:
Quote:the transmitted string was:050300000003F5
what were you expecting?

i must be able to get a response from a micro...but i don't get anything
Reply
#4
Is this a serial connection?
if so, is it RS232, I2c ...

For RS232, using putty to start is a good idea.
That way you can establish two way communications
and know exactly what baud rate, parity, number of stop bits, etc.
This will make writing the driver so much easier.
Otherwise, If your connection didn't work, you could spend a long time trying to debug perfectly good code.
Reply
#5
(May-11-2017, 12:56 PM)Larz60+ Wrote: Is this a serial connection?
if so, is it RS232, I2c ...

For RS232, using putty to start is a good idea.
That way you can establish two way communications
and know exactly what baud rate, parity, number of stop bits, etc.
This will make writing the driver so much easier.
Otherwise, If your connection didn't work, you could spend a long time trying to debug perfectly good code.

i directly connected micro tx,rx to raspberry rx,tx...the logic level of micro rx,tx voltages are 3.3volts
what do you mean the driver?
the programmer of the micro has told baudrate,parity and stop bit...they are known
Reply
#6
Baud-rate, parity, etc. is part of a protocol.
One side cannot communicate with the other if they don't match.
The data being transferred is a stream of bits that is being pushed out of the transmitting side at a certain speed (baud rate),
which has to be matched on the receiving end in order for communications to be correctly established.
The same with stop bits and parity, which are part of the framing of the data, and must be the same on both ends.Simply connecting
one side to the other, although necessary is only part of what has to be done.
Also keep in mind that for duplex (two way) communications, the transmit of side data 1 must be connected to the receive side of the other,
unless that's done by internal switching.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020