一点一点地读取一个保持寄存器 Siemens
Read an holding register bit by bit Siemens
我需要用 python 一点一点地读取 Siemens 1200 保持寄存器,在网上搜索我发现 PyModbus 是一个很好的库,但是有了它我只能读取这样的保持寄存器整数而不是逐位。
这是代码:
from pymodbus.client.sync import ModbusTcpClient
client = ModbusTcpClient('x.y.z.w', port=xxx)
result = client.write_registers(1, [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) # write some register
results = client.read_holding_registers(0, 50) # read the first fifty register like int
print("0-50", results.registers)
results = client.read_holding_registers(50, 50) # read the last fifty register like int
print("50-100:", results.registers)
client.close()
有人有什么提示吗?
from pymodbus.client.sync import ModbusTcpClient
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.constants import Endian
CLP_MB = ModbusTcpClient(['IP'], port=502)
adress_Tag=1
adress_Tag=int(adress_Tag)
size=50
value = CLP.read_coils(adress_Tag, size, unit=0)
#last part
value_bit_0 = int(value.bits[0])
value_bit_1 = int(value.bits[1])
.....
you can use a for loop to automation this last part
我需要用 python 一点一点地读取 Siemens 1200 保持寄存器,在网上搜索我发现 PyModbus 是一个很好的库,但是有了它我只能读取这样的保持寄存器整数而不是逐位。
这是代码:
from pymodbus.client.sync import ModbusTcpClient
client = ModbusTcpClient('x.y.z.w', port=xxx)
result = client.write_registers(1, [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) # write some register
results = client.read_holding_registers(0, 50) # read the first fifty register like int
print("0-50", results.registers)
results = client.read_holding_registers(50, 50) # read the last fifty register like int
print("50-100:", results.registers)
client.close()
有人有什么提示吗?
from pymodbus.client.sync import ModbusTcpClient
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.constants import Endian
CLP_MB = ModbusTcpClient(['IP'], port=502)
adress_Tag=1
adress_Tag=int(adress_Tag)
size=50
value = CLP.read_coils(adress_Tag, size, unit=0)
#last part
value_bit_0 = int(value.bits[0])
value_bit_1 = int(value.bits[1])
.....
you can use a for loop to automation this last part