X-600M Users Manual
Appendix G: Lua Scripts
rc = serWrite("io.serialPort1", "Hello "..counter)
-- Check result, if less than 0 then something is wrong
-- close the serial port, wait 5 seconds and attempt to open it again
-- do this until the serial port is back up
if rc < 0 then
while rc <= 0 do
serClose("io.serialPort1");
sleep(5000)
rc = serOpen("io.serialPort1");
if rc > 0 then
serClearTXBuffer("io.serialPort1");
serClearRXBuffer("io.serialPort1");
end
end
end
-- increment the counter
counter = c 1
sleep(1000)
end
The second example demonstrates how to send a byte array over the serial port to a modbus device
with address 247. In this example, the serial port adapter has been configured to communicate with
a generic modbus device with two coils. A USB to RS485 serial adapter has been used. The
example will toggle the both coils on the modbus device once a second.
-- commands for turning both coils on and off
onCmd = {0xf7, 0x0f, 0x00, 0x00, 0x00, 0x02, 0x01, 0x03, 0x11, 0xf8}
offCmd = {0xf7, 0x0f, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x51, 0xf9}
-- loop forever
while true do
-- send on command and read back response
rc = serWrite("io.serialPort1", onCmd)
sleep(20)
data = serRead("io.serialPort1")
-- wait 1 second
sleep(1000)
-- send off command and read back response
rc = serWrite("io.serialPort1", offCmd)
sleep(20)
data = serRead("io.serialPort1")
-- wait 1 second
sleep(1000)
end
The third example demonstrates how to wait for data from the serial port.
Xytronix Research & Design, Inc.
Page 135
Содержание 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...