ModBus library on LoPy : no data received from slave
-
Hello,
I am trying to read ModBus data from a slave using ModBus library. I am continuously getting error "OSError: no data received from slave". Below is the code I am using
######################### RTU SERIAL MODBUS #########################
uart_id = 0x01
modbus_obj = Serial(uart_id, pins=('P3', 'P4'))###################### READ HOLDING REGISTERS ##################
slave_addr=0x01
starting_address=0x110
register_quantity=10
signed=Trueregister_value = modbus_obj.read_holding_registers(slave_addr, starting_address, register_quantity, signed)
print('Holding register value: ' + ' '.join('{:d}'.format(x) for x in register_value))I tried reading the same slave from a ModBus master simulator and getting the expected data. But it is failing with the LoPy. Below is the error msg. Please check.
Traceback (most recent call last):
File "<stdin>", line 46, in <module>
File "/flash/lib/uModBus/serial.py", line 127, in read_holding_registers
File "/flash/lib/uModBus/serial.py", line 86, in _send_receive
File "/flash/lib/uModBus/serial.py", line 91, in _validate_resp_hdr
OSError: no data received from slaveRegards,
Sameer -
Hi this might be a silly question, but most MODBUS RTU devices are serial RS323 or RS485. I personally haven't seen any industrial modbus devices that use TTL.
I am pretty sure the serial UART on the ESP32 is TTL so it won't work with any RS232/RS485 devices with out something like a MAX3232
Cheers
Tim
-
@timh
Yes, it is TTL only.@SameerChouksey
you must use converter e.g.SN65HVD230- direct connection can brake your device as it is 3V3 levels device only. -
Hello,
Thanks for your prompt response. Yes, the device supports RS485 and I am using a Rs485 to TTL converter between PyCom board and the ModBus slave. Still getting same error.
Regards,
Sameer -
@sameerchouksey have you tried using TTL and a different library on something like a raspberry pi ?
One of things we have had issues with various serial modbus adaptors is the timeout for the read is too short, which typically gives you OSError: no data received from slave. For instance an ATLAS COPCO engine controller I couldn't get to work using modbus_tk, but could with PyModbus due to the way modbus_tk was handling serial timeouts (and I didn't then want to spend time debugging modbus_tk ;-)
The other obvious things are checking comms details and slave address which will also generally give you the same error.
You code example isn't showing baud etc...T
-
You can use something like that

Search for "XY-017 RS485" in google you'll find it everywhere starting less than $2 (on ebay for example)
-
Thanks for the support. I am able to read it with a potential divider circuit.
One query, how many registers can I read in one single call?? I am setting up register_quantity=10, but still I am able to read only one register at a time.
Regards
Sameer -
Oh I didn't know you could read a single register. That information missing from you post above.
Have you checked that the contiguous register range is valid (ie no holes).
We talk to a number of devices that have large holes in the register range . We can read multiple registers if we avoid the holes. ie registers 50 to 100 (decimal) might have two unused registers at 68 & 69. So we can't read from address 50 for a length of 50. We have read start register 50, length of 27, then from 70 with a length of 30.
Can you read 2 adjacent registers or are you limited to a single register?
Tim
-
@timh I tried reading 2 adjacent registers. But getting only one value.
There is no hole between two registers. You can see in the screenshot that I first reading register address 0x110 with register count as 2. And then I am reading register address 0x111. In the second call I can read the second register.
Please check the screenshot.

-
@sameerchouksey have you confirmed you can read multiple registers from this device using some other software/hardware other than pycom ?
T
-
@timh Yes. I have used Modbus Poll simulator and I can read 10 registers there.
Regards
Sameer -
@sameerchouksey this might be a long shot, but I would try using the original micropython modbus code.
The pycom modbus code is different and adds the signed option. (which I find strange because endianess is not a given in modbus (ie not defined) so can vary from platform to platform) which would be required to correctly interpret signed values. The original doesn't include this extra code. -
Hello,
I'm working on a modbus project using the pycom controller to read a few input registers. But there I get the same error as you Sameer and I'm not able to make the code run correctly.
What did you do that the code work?Regards,
Jancurrent code:
######################### RTU SERIAL MODBUS #########################
uart_id = 0x01
modbus_obj = Serial(uart_id, pins=('P3', 'P4'))###################### READ INPUT REGISTERS ##################
slave_addr=0x01
starting_address=0x04
register_quantity=2
signed=Trueregister_value = modbus_obj.read_input_registers(slave_addr, starting_address, register_quantity, signed)
print('Input register value: ' + ' '.join('{:d}'.format(x) for x in register_value))
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login