我正在尝试学习如何将值引入PLC槽python ModBus模块中,我目前正在尝试做的只是读取线圈1的值,以检查其 True 或< strong> false ,所以我正在使用
order_ready = client.read_coils(0, 1)
print(order_ready)
并将其作为响应 ReadBitResponse(8)怎样从读取线圈中获得“ 真”值
答案 0 :(得分:1)
您可以使用ReadCoilResponse
属性通过响应bits
访问各个线圈。有关响应的更多信息,请参见here
order_ready = client.read_coils(0, 1)
if not order_ready.isError():
#response.bits would return a list (multiple of 8) of booleans each bit representing the output of one coils
# In your case accessing 1st element should give the actual value
order_ready = order_ready.bits[0]
else:
# Handle error