Search code examples
pythonmodbus

how to extracting data from pymodbus?


I have a simple program to retrive data from modbus, and I want to extract it..

from pyModbusTCP.client import ModbusClient

c = ModbusClient(host="192.168.1.64", port=502, auto_open=True)
regs = c.read_holding_registers(0, 4)
print (regs) 

output:

[ 1 , 23 , 21 , 42 ]

how to extract output to variable like

a = 1
b = 23
c = 21
d = 42

Can anyone help me?


Solution

  • You can access a list item with numeric list indices, starting at 0:

    l = [ 1 , 23 , 21 , 42 ]
    
    a = l[0]
    b = l[1]
    c = l[2]
    d = l[3]
    

    But if you do not know something that basic, you should read a book on Python first.