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.
Difference between revisions of "Mihini/serial"
< Mihini
(Created page with "== SERIAL port == '''Variable''' local sched = require 'sched' local log = require 'log' local serial = require 'serial' local serial_port ="/dev/ttyACM0" local...") |
|||
Line 16: | Line 16: | ||
serialdev:close() :Closes the serial library instance. | 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 | serialdev:read(pattern) :Reads data from the serial port | ||
Latest revision as of 08:00, 11 March 2015
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()