X-600M Users Manual
Appendix G: Lua Scripts
end
end
-- wait 1 second
sleep(1000)
end
The following example demonstrates how to use the tcp functions described above to send and
receive a table of bytes using tcp.
-- connect to server and send a message every second
-- keep track of connection state. 0 = not connected, 1 = connected
connected = 0
reqPacket = {0x40, 0x01, 0x00, 0x0C, 0xC8, 0x00, 0x00, 0x99, 0x01, 0x02, 0x03,
0x04}
enableDebug()
while true do
-- try to connect
if connected == 0 then
print("Connecting")
rc = tcpConnect("192.168.1.152", 65430, 3000)
if rc == 1 then
print(" Connected")
connected = 1
end
end
-- if connected send message
if connected == 1 then
print("Send message")
rc = tcpSend(reqPacket)
print("Sent "..rc.." bytes")
-- if send succeeded then read back the response
if rc > 0 then
rc = tcpRecv()
if rc > 0 then
data = responseGetBytes(0, rc)
print("Data ")
for k, v in pairs( data ) do
print(string.format("%x",v))
end
end
end
-- close the connection
print("Close connection")
tcpClose()
connected = 0
end
-- wait 1 second
sleep(1000)
end
enableDebug()
This function will enable the debug console. The print function will output to the debug console when
debugging is enabled. This is useful for debugging, but during actual use of the X-600M, debugging
mode should be disabled. The debugging console is disabled whenever settings are committed.
Xytronix Research & Design, Inc.
Page 133
Содержание X-600M
Страница 1: ...X 600MTitle Page Goes Here...
Страница 6: ...X 600M Users Manual Page 4 Xytronix Research Design Inc...
Страница 99: ...X 600M Users Manual Setup Pages Xytronix Research Design Inc Page 97...
Страница 116: ...Appendix B Installing New Firmware X 600M Users Manual Page 114 Xytronix Research Design Inc...