In the script you can register COM device, send some data to it and register some callbacks when data is received.
Register
Code: Select all
-- add COM port (with default config values) as device
-- 1st param: logical name
-- 2nd param: port name
lmc_add_com('C3', 'COM3')
-- add COM port (with full config) as device
-- 1st param: logical name
-- 2nd param: port name
-- 3rd param: baud rate
-- 4th param: data bits (8, 7 , 6, 5)
-- 5th param: parity ('N', 'O', 'E', 'M', 'S')
-- 6th param: stop bits (1,2)
lmc_add_com('C4', 'COM4', 1200, 6, 'E', 2)
Send
Sending is quite simple, just send string to serial port by command:
Code: Select all
lmc_send_to_com('C3', 'Hello world')
Receive
Receive is little more complicated. Wait.... it's not, it has just additional feature.
You can read data from COM port with simple callback as one could expect
Code: Select all
lmc_set_handler('C3',function(comVal)
print('Have data from COM3: ' .. comVal)
end)
So what's the feature? I was told you can have sometimes difficulty to keep serial data in logical groups. Sounds complicated... The callback is triggered for bunch (you can call it packet) of data which arrives to COM port. The length can be influenced by buffers at device or host (PC) side or some timer - whatever. The point is you logical group of data can be separated between 2 or more callbacks. This is the situation when you can set splitter which is character that divides your logical part of data.
Code: Select all
lmc_set_com_splitter('C3', 'a')