It always returns this: raise IOError('No communication with the instrument (no answer)') Instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 1) # port name, slave address (in decimal)Įnergy = instrument.read_register(10, 1) # Registernumber, number of decimals Instrument.mode = minimalmodbus.MODE_RTU # rtu or ascii mode #instrument.address # this is the slave address number ='/dev/ttyUSB0' # this is the serial port name When I use MinimalModbus and run the anycodings_raspberry-pi following codeï¼ #!/usr/bin/env python Modbus_tk.exceptions.ModbusInvalidResponseError: Response length is invalid 0 19:24:39,291 DEBUG modbus.execute MainThread įile "build/bdist.linux-x86_64/egg/modbus_tk/utils.py", line 39, in new The parameters such as port, baudrate, anycodings_raspberry-pi bytesize,parity,and stopbits were set anycodings_raspberry-pi correctly, but it always returns this: 19:24:34,282 INFO modbus_rtu._init_ MainThread RtuMaster /dev/ttyUSB0 is opened Logger.error("%s- Code=%d" % (e, e.get_exception_code())) (master.execute(1, cst.READ_HOLDING_REGISTERS, 0, 49)) t_verbose(True) #print some more log prints for debug purpose t_timeout(5.0) #Change the timeout value/Defines a timeout on the MAC layer Master = modbus_rtu.RtuMaster(serial.Serial(port="/dev/ttyUSB0", baudrate=9600, bytesize=8, parity='N', stopbits=1, xonxoff=0)) Logger = modbus_tk.utils.create_logger("console") #add logging capability import logging import modbus_tk import modbus_tk.defines as cst import modbus_tk.modbus_rtu as modbus_rtu When I use modbus_tk 0.5.7 and run the anycodings_raspberry-pi following codeï¼ import sys import serial I have tried the anycodings_raspberry-pi modbus_tk 0.5.7 and MinimalModbus to anycodings_raspberry-pi implement the communication under Modbus-RTU anycodings_raspberry-pi protocol. I used a RS232/USB adapter and a RS485/RS232 anycodings_raspberry-pi adapter to link the meter and the USB port anycodings_raspberry-pi on the Raspberry Pi. I am trying to use a Raspberry Pi 3B (run anycodings_raspberry-pi Ubuntu Mate 16.04 operating system)as a anycodings_raspberry-pi Master to read values from an electric anycodings_raspberry-pi energy meter which supports Modbus-RTU anycodings_raspberry-pi protocol.
0 Comments
Leave a Reply. |