pymodbus icon indicating copy to clipboard operation
pymodbus copied to clipboard

Print value in holding register in mode rtu

Open ghost opened this issue 12 years ago • 7 comments

Hello, I want to read and print the values stored in holding registers 00 to 03, and I succeeded with Modpoll, but when I tried with this code in python, the result is None ps: My python version is 2.7.3

!/usr/bin/env python

from pymodbus.client.sync import ModbusSerialClient as ModbusClient client=ModbusClient(method='rtu',port='/dev/ttyUSB0',baudrate=9600,timeout=1) client.connect()

response=client.read_holding_registers(0,4,unit=1) print response client.close()

Could you give a hand on this issue? tks in advance

ghost avatar Jul 30 '14 18:07 ghost

Are you actually desiring unit 1? Do you want to use register or address numbering? (0 based or 1 based?) What logging do you get when you use the logging from the examples?

On 07/30/2014 06:17 PM, Haoming Wang wrote:

Hello, I want to read and print the values stored in holding registers 00 to 04, and I succeeded with Modpoll, but when I tried with this code in python, the result is None

#!/usr/bin/env python

from pymodbus.client.sync import ModbusSerialClient as ModbusClient client=ModbusClient(method='rtu',port='/dev/ttyUSB0',baudrate=9600,timeout=1) client.connect()

response=client.read_holding_registers(0,4,unit=1) print response client.close()

Could you give a hand on this issue? tks in advance

— Reply to this email directly or view it on GitHub https://github.com/bashwork/pymodbus/issues/50.

karlp avatar Jul 30 '14 19:07 karlp

My device's slave id is 1, so I think 'unit' should be 1. According to the documentation, it is 0 based. I try this code today without changing anything, and the result is different, which is 'ReadRegisterResponse (4)', its type is :class 'pymodbus.register_read_message.ReadHoldingRegistersResponse'

I just add a sentence: "print response.getRegister(number of the register)" and I succeed in reading its value! Thanks for your help.

ghost avatar Jul 31 '14 13:07 ghost

Hello, I have successfully got the register values using code: code: ` import pymodbus import serial from pymodbus.pdu import ModbusRequest from pymodbus.client.sync import ModbusSerialClient as ModbusClient #initialize a serial RTU client instance from pymodbus.transaction import ModbusRtuFramer

#!/usr/bin/env python

#from pymodbus.client.sync import ModbusSerialClient as ModbusClient client=ModbusClient(method='rtu',port='/dev/ttyUSB0',baudrate=9600,timeout=1,parity='N') client.connect()

response=client.read_holding_registers(0004,6,unit=1) print response.getRegister(0); // This returns value of only one register print response.registers[0:] // This returns the response for whole length of registers client.close() ` hope it will be helpful.

tanmayee30 avatar May 23 '17 09:05 tanmayee30

I have used the same process above. But I have 3 slaves and having different sets of holding registers. I want to create an event on one slave that if one of its holding register is high it master should process it first and then it will process the rest slaves holding registers. How can i do it. Any help will be highly appreciated.

007-akash avatar May 25 '18 12:05 007-akash

@007-akash this is a closed issue, if you have a new issue, please make a new issue.

karlp avatar May 25 '18 13:05 karlp

What do u mean by closed issue. Is it solved already or cannot be solved?

007-akash avatar May 25 '18 14:05 007-akash

@007-akash You will have come with your own business logic to achieve what you are asking. You can refer to the example callback_server. It may not be something that is a solution right out of the box for your but atleast should give you some hints on how to go ahead. Again , as I said in the beginning (if I understand correctly) your query falls out of the scope of pymodbus . If you think this is something Pymodbus should support, request you to create a new issue with more details as the status of this issue is Closed.

dhoomakethu avatar May 25 '18 14:05 dhoomakethu