

-- 程序使用MG400编写
-- Version: Lua 5.3.5
resultCreate,id = ModbusCreate('192.168.1.6', 502, 1)
Sync()
if (resultCreate)==0 then
Sync()
print('连接成功')
SetCoils(id,1000,#{1,1,1,1,1},{1,1,1,1,1})
Sync()
print('写入成功')
while true do
if GetCoils(id,1009,1)[1] == 1 then
break
end
Sleep(50)
end
SetCoils(id,1000,#{0,0,0,0,0},{0,0,0,0,0})
M1000 = GetCoils(id,1000,1)[1]
M1001 = GetCoils(id,1001,1)[1]
M1002 = GetCoils(id,1002,1)[1]
M1003 = GetCoils(id,1003,1)[1]
M1004 = GetCoils(id,1004,1)[1]
Sync()
print(M1000)
else
Sync()
print('创建主站失败')
end
Sync()
print('程序结束')
Comments NOTHING