Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Mihini/serial
< Mihini
SERIAL port
Variable
local sched = require 'sched'
local log = require 'log'
local serial = require 'serial'
local serial_port ="/dev/ttyACM0"
local serial_config={parity="none",flowcontrol="none", numDataBits=8,numStopBits = 1, baudRate=9600}
local serial_dev
serial.open(port, config) Creates and returns a new serial device instance.
local function configSerial() serial_dev=serial.open(serial_port,serial_config) end
serialdev:close() :Closes the serial library instance. serialdev:write(buffer) Writes buffer to the serial port serialdev:read(pattern) :Reads data from the serial port
local function main()
configSerial()
while(true) do
data=serial_dev:read('*l') //Description Below
if(data~=nil) then
print(data)
end
end
end
'*a' for reads the whole file, starting at the current position.On end of file, it returns the empty string. '*n' reads a number; this is the only format that returns a number instead of a string. '*l'reads the next line (skipping the end of line), returning nil on end of file. This is the default format.
sched.run(main) sched.loop()