Closed anshulpaigwar closed 7 years ago
This look like a communication error. Did you check that the serial port is correctly opened and that data is sent to the slave?
I had the same problem, what helped was to add a line after connecting to the arduino where you wait two seconds, because the arduino resets after opening the port. This should work. You can also put a capacitor between the reset pin and ground on your arduino.
`import serial
import time import modbus_tk import modbus_tk.defines as cst from modbus_tk import modbus_rtu
PORT = "COM6"
def main(): """main""" logger = modbus_tk.utils.create_logger("console")
try:
#Connect to the slave
master = modbus_rtu.RtuMaster(
serial.Serial(port=PORT, baudrate=19200, bytesize=8, parity='N', stopbits=1, xonxoff=0)
)
master.set_timeout(0.5)
master.set_verbose(True)
logger.info("connected")
time.sleep(2)
logger.info(master.execute(1, cst.READ_HOLDING_REGISTERS,0,16))
except modbus_tk.modbus.ModbusError as exc:
logger.error("%s- Code=%d", exc, exc.get_exception_code())
if name == "main": main()`
@g0lln3r I encountered the same problem and you way solved it, thank you very much for share
i have encountered the same error but unfortunately this did not help me
I am trying to communicate with Arduino Uno (slave) using modbus-tk from my PC (master) with following code:
I am getting following error: modbus_tk.exceptions.ModbusInvalidResponseError: Response length is invalid 0
I have tested my Arduino code with Qmodbus and it is working absolutely fine but and getting proper response. But I am unable to solve the error with modbus-tk. Hope someone could help me. thanks in advance.