Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Mihini/serial

< Mihini
Revision as of 08:00, 11 March 2015 by Niranjan.babu.in.bosch.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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()

Back to the top