0

I copied this code into the pymodbus documentation:

from pymodbus.client.sync import ModbusSerialClient

client = ModbusSerialClient(
    method='rtu',
    port='com3',
    baudrate=9600,
    timeout=3,
    parity='N',
    stopbits=1,
    bytesize=8
)

if client.connect():  # Trying for connect to Modbus Server/Slave
        '''Reading from a holding register with the below content.'''
    res = client.read_input_registers(address=0, count=3, unit=1)

    if not res.isError():
        print(res)
        print(res.registers)
    else:
        print(res)

else:
    print('Cannot connect to the Modbus Server/Slave')

In case I'm reading a temperature sensor, in modscan the response I have is 27C°

The answer I'm getting is this: ReadInputRegistersResponse (3) [1, 4, 1]

The answer doesn't mean anything to me, do I have to convert the answer?

  • hello Fabio, three questions: are you reading the same register numbers with modscan?, are you sure you have to be reading input registers and not holding registers? what is your temperature sensor brand and model? – Marcos G. Oct 08 '21 at 09:26
  • @MarcosG. Answering: 1) yes, it is the same register modscan is reading. 2)Yes, I'm reading the input registers. 3) I don't have such information. – Fabio Martins Oct 10 '21 at 18:45
  • Hello. I see... why are you reading three registers then? and how are you getting the 27 degrees in modscan? as a single register with value integer 27? – Marcos G. Oct 13 '21 at 06:17
  • @MarcosG. So, in this part: res = client.read_input_registers (address = 0, count = 3, unit = 1) is seeking to read all registers starting at address 0. I've never worked with this, so it's for him to send me the value of 27, without needing any conversion, right? If so, I'll check where I'm going wrong, the addresses, test them one by one and etc.. – Fabio Martins Oct 19 '21 at 14:46
  • Sorry Fabio, I have no idea what you mean. My question was: Where are you reading the 27 degrees? from a display on the sensor itself or through Modbus? If you are using some other Modbus tool, then are you reading registers 0, 1 and 2? The easiest thing to do is to read the sensor's manual, you should find the register numbers and how to convert then should any kind of conversion be needed – Marcos G. Oct 20 '21 at 15:20
  • it is the Modscan that is reading the value of 27Cº – Fabio Martins Oct 21 '21 at 00:31
  • Yes, that part I got... I mean, would it be too much to ask for you to explain **how you are setting up Modscan**? Maybe just a screenshot – Marcos G. Oct 22 '21 at 10:00
  • @MarcosG. follows modscan image. Thanks. [! Image Modscan](https://imgbox.com/9nRrnzbl) – Fabio Martins Nov 09 '21 at 20:30
  • Hello Fabio, that's what I wanted to see. I don't understand why you have `address=0` on your code, in *modscan* you are reading register 4001, have you tried changing to `address=0x4001`? – Marcos G. Nov 10 '21 at 06:28
  • @MarcosG. [image-error](https://imgbox.com/w2wk3weL) – Fabio Martins Nov 11 '21 at 16:25
  • hello Fabio, now you are getting an `Illegal Address` error, I think you need to write the register address in hex instead of dec, maybe try writing `0x4001`? – Marcos G. Nov 12 '21 at 17:44
  • @MarcosG. I tried it that way too. And it gave the same error. I think there might be some problem with the RS485 to USB converter.. But ModScan is using the same converter... I can't understand :-( – Fabio Martins Nov 13 '21 at 18:02
  • hello Fabio, I have no other advice. For sure your converter is working, and it sure looks like you are addressing the wrong register, but how or why: no idea. You'll have to give it another go yourself. Good luck. – Marcos G. Nov 14 '21 at 07:56

0 Answers0