27 lines
636 B
Python
27 lines
636 B
Python
from pyModbusTCP.client import ModbusClient
|
|
|
|
print("modbus test")
|
|
|
|
# Настройки клиента Modbus
|
|
MODBUS_SERVER_HOST = "192.168.70.55" # IP-адрес Modbus-сервера
|
|
MODBUS_SERVER_PORT = 502
|
|
|
|
client = ModbusClient(
|
|
host=MODBUS_SERVER_HOST,
|
|
port=MODBUS_SERVER_PORT,
|
|
unit_id=11,
|
|
# debug=True
|
|
)
|
|
client.open()
|
|
|
|
addr = 2
|
|
light = client.read_coils(addr, 1)
|
|
print("состояние лампочки", light)
|
|
|
|
print("пишем противоположное", not light[0])
|
|
client.write_single_coil(addr, not light[0])
|
|
|
|
print("теперь состояние", client.read_coils(addr, 1))
|
|
|
|
client.close()
|