Closed StevenLau6 closed 7 years ago
I have solved my problem by using a more expensive USBtoRS485 connector. The problem took me a lot of time to try different library and different code. It turns out that the adapter "QinHeng Electronics HL-340 usb-serial" that I bought works well on windows but does not work with Linux. It can achieve send and receive message on Linux, but it just can`t support Modbus communication.
So I suggest you buy a more expensive connector, and it may save your a lot of time and energy.
That`s all, thank you!
On the contrary, it worked perfectly with QinHeng Electronics HL-340 for me. i will upload my project later.
Please try code.
self.inst = modbus_rtu.RtuMaster(serial.Serial(port=com, baudrate=9600, bytesize=8, parity='N', stopbits=1, xonxoff=0))
self.inst.set_timeout(timeout)
self.inst.set_verbose(True)
I am trying to use a Raspberry Pi 3B as a Master to read values from an electric energy meter which supports Modbus-RTU protocol. I used a RS232/USB adapter and a RS485/RS232 adapter to link the meter and the USB port on the Raspberry Pi. When I run the following code:
The port, baudrate, bytesize,parity,and stopbits were set correctly, but it always returns this:
And then I use the same serial transmission line to link the meter and the laptop, and use a debugging tool running on Windows XP, which was developed by the manufacturer of the meter. The debugging tool sends the same Request (1-3-0-0-0-49-132-30) as before, but the debugging tool can get correct Responses. (Maybe it's because it ignored some incorrect Responses and keep on send Requests regularly) I have tried many times, but the Raspberry Pi never gets a Response, and always returns the same error information.
I am new to Modbus and serial communication, so any help would be appreciated.