COM Devices - me2d13/luamacros GitHub Wiki
Added 19 Sept 2015
Some implemenations of LUAMacros may use the assistance of a COM device for expanding it's functionality.
This usually becomes helpful when working with Arduino and other IoT devices
-- 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)
Sending data
lmc_send_to_com('C3', 'Hello world')
Receive data
lmc_set_handler('C3',function(comVal)
print('Have data from COM3: ' .. comVal)
end)
As a callback, this runs is triggered when data arrives
Data will be split into different packets based on a buffer or timer (set by the host or device), or we can use a splitter via LUAMacros
lmc_set_com_splitter('C3', 'a')
This overides the default split based on packets, and instead will use the provided string as a splitter.