The UART (Universal asynchronous receiver/transmitter) module allows configuration of and communication over the UART serial port. The default setup for the uart is controlled by build-time settings.
Rs232 = require( 'luars232 ') -- Linux -- port_name = '/dev/ttyS0' -- (Open)BSD -- port_name = '/dev/cua00' -- Windows port_name = 'COM1 ' local out = io. Stderr -- open port local e, p = rs232. Open(port_name) if e ~= rs232.
RS232_ERR_NOERROR then -- handle error out: write( string.format( 'can't open serial port '%s', error: '%s' n ', port_name, rs232. Error_tostring(e))) return end -- set port settings assert(p: set_baud_rate(rs232. RS232_BAUD_115200) == rs232. RS232_ERR_NOERROR) assert(p: set_data_bits(rs232. RS232_DATA_8) == rs232. RS232_ERR_NOERROR) assert(p: set_parity(rs232.
RS232_PARITY_NONE) == rs232. RS232_ERR_NOERROR) assert(p: set_stop_bits(rs232. RS232_STOP_1) == rs232. RS232_ERR_NOERROR) assert(p: set_flow_control(rs232. RS232_FLOW_OFF) == rs232. RS232_ERR_NOERROR) out: write( string.format( 'OK, port open with values '%s' n ', tostring(p))) -- read with timeout local read_len = 1 -- read one byte local timeout = 100 -- in miliseconds local err, data_read, size = p: read(read_len, timeout) assert(e == rs232. RS232_ERR_NOERROR) -- write without timeout err, len_written = p: write( 'test ') assert(e == rs232.
RS232_ERR_NOERROR) -- write with timeout 100 msec err, len_written = p: write( 'test n ', timeout) assert(e == rs232. RS232_ERR_NOERROR) -- close assert(p: close() == rs232. RS232_ERR_NOERROR) • Copy lines • Copy permalink • Go.
UART Module Since Origin / Contributor Maintainer Source 2014-12-22 The (Universal asynchronous receiver/transmitter) module allows configuration of and communication over the UART serial port. The default setup for the uart is controlled by build-time settings. The default rate is 115,200 bps. In addition, auto-baudrate detection is enabled for the first two minutes after platform boot. This will cause a switch to the correct baud rate once a few characters are received.
[*]Press Flash Start Button. Sp flash tool mt6572 rom i9060. [*]Insert USB Cable & Wait For Flash 100% Done. [*]Charge Battery Minimum 50% Up. [*] Setup Android USB Cable Vcom Driver.
Auto-baudrate detection is disabled when uart.setup is called. Note Due to limitations of the ESP8266, only UART 0 is capable of receiving data. Syntax uart.on(method, [number/end_char], [function], [run_input]) Parameters • method 'data', data has been received on the UART • number/end_char • if n=0, will receive every char in buffer • if n. Note Bytes sent to the UART can get lost if this function re-configures the UART while reception is in progress. Syntax uart.setup(id, baud, databits, parity, stopbits[, echo]) Parameters • id UART id (0 or 1). • baud one of 300, 600, 1200, 2400, 4800, 9600, 19200, 31250, 38400, 57600, 74880, 115200, 230400, 256000, 460800, 921600, 1843200, 3686400 • databits one of 5, 6, 7, 8 • parity uart.PARITY_NONE, uart.PARITY_ODD, or uart.PARITY_EVEN • stopbits uart.STOPBITS_1, uart.STOPBITS_1_5, or uart.STOPBITS_2 • echo if 0, disable echo, otherwise enable echo (default if omitted) Returns configured baud rate (number) Example -- configure for 9600, 8N1, with echo uart.setup(0, 9600, 8, uart.PARITY_NONE, uart.STOPBITS_1, 1) uart.getconfig() Returns the current configuration parameters of the UART. Syntax uart.getconfig(id) Parameters • id UART id (0 or 1).
Returns Four values as follows: • baud one of 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 74880, 115200, 230400, 256000, 460800, 921600, 1843200, 3686400 • databits one of 5, 6, 7, 8 • parity uart.PARITY_NONE, uart.PARITY_ODD, or uart.PARITY_EVEN • stopbits uart.STOPBITS_1, uart.STOPBITS_1_5, or uart.STOPBITS_2 Example print (uart.getconfig(0)) -- prints 9600 8 0 1 for 9600, 8N1 uart.write() Write string or byte to the UART. Syntax uart.write(id, data1 [, data2.]) Parameters • id UART id (0 or 1). String or byte to send via UART Returns nil Example uart.write(0, 'Hello, world n').