1

There is a device that sends information using the Modbus protocol. I am using the following python code to receive the information of this device :

from pymodbus.client.sync import ModbusTcpClient,ModbusUdpClient
from pymodbus.transaction import ModbusRtuFramer as ModbusFramer

client = ModbusUdpClient("109.125.128.232", port=50450, framer=ModbusFramer)
success = client.connect()

print(success)

read = client.read_holding_registers(address=100, unit=2)

I get the following error :

Traceback (most recent call last):
  File "C:\Users\hossein\Desktop\modebuspool\modebus.py", line 9, in <module>
    read = client.read_holding_registers(address=100, unit=2)
  File "C:\Users\hossein\AppData\Local\Programs\Python\Python37\lib\site-packages\pymodbus\client\common.py", line 114, in read_holding_registers
    return self.execute(request)
  File "C:\Users\hossein\AppData\Local\Programs\Python\Python37\lib\site-packages\pymodbus\client\sync.py", line 109, in execute
    return self.transaction.execute(request)
  File "C:\Users\hossein\AppData\Local\Programs\Python\Python37\lib\site-packages\pymodbus\transaction.py", line 178, in execute
    broadcast=broadcast
  File "C:\Users\hossein\AppData\Local\Programs\Python\Python37\lib\site-packages\pymodbus\transaction.py", line 274, in _transact
    size = self._send(packet)
  File "C:\Users\hossein\AppData\Local\Programs\Python\Python37\lib\site-packages\pymodbus\transaction.py", line 309, in _send
    return self.client.framer.sendPacket(packet)
  File "C:\Users\hossein\AppData\Local\Programs\Python\Python37\lib\site-packages\pymodbus\framer\rtu_framer.py", line 263, in sendPacket
    timeout = start + self.client.timeout
TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'
endive1783
  • 827
  • 1
  • 8
  • 18

1 Answers1

0

Are you 100% certain you need to be using ModbusRtuFramer?

You should take this into account:

...
It should be noted that although you are not limited to trying whatever
would like, the library makes no guarantees that all framers with
all transports will produce predictable or correct results (for example
tcp transport with an RTU framer). However, please let us know of any
success cases that are not documented!
"""

There are some cases where you might need to send Modbus RTU frames over TCP (for instance some serial-to-Ethernet forwarders), see this thread for more details.

If you really want to use the Modbus RTU framer over TCP you might want to try instantiating your client like so:

client = ModbusTcpClient('x.y.z.w', port=yyy, timeout=10)

That should help you get rid of the TypeError: unsupported operand type(s) for +: 'float' and 'NoneType' error.

I have never tested this combination but according to this it should work.

Marcos G.
  • 3,371
  • 2
  • 8
  • 16