Coder Social home page Coder Social logo

lua-serial's Introduction

ul_serial

Lua serial port library

Serial port communication functions for Lua. For timing functions requires function os.delay_us(us) (in ul_time module).

  • Compilation with gcc (Linux) or MinGW-gcc (Windows):
    • make
  • Cross-compilation in Linux:
    • 32-bit target: make COMSPEC=command
    • 64-bit target: make COMSPEC=command PROCESSOR_ARCHITECTURE=AMD64 CPU=k8

Examples:

  • Get list of available ports: ports = io.Serial:getPorts()
  • After calling getPorts() list of system ports stored to io.Serial.ports variable: ports = io.Serial.ports
  • Open port and set parameters. Port can be port's name or number (starting at 1):
    • p = io.Serial{port='/dev/ttyUSB0', baud=9600,bits=8,stops=0,parity='n'}
    • or p = io.Serial:open{5}:baud(1200):bits(8):stops(2):parity('e'):DTR(0):RTS(1)
  • Set parameters:
    • p:config{baud=1200,bits=8,stops=2,parity='e',DTR=0,RTS=1}
    • or using method chaining: p:baud(1200):bits(8):stops(2):parity('e'):DTR(0):RTS(1)
  • Get number of bytes waiting in receive buffer: n = p:available()
  • Read all received data (as string): p:read()
  • Wait for reception of at least 64 bytes, with 100ms timeout, receive data on success:
    to = p:waitRX(64, 100)
    if to == 0 then
    	print('Timeout occured...')
	else
		data = p:read()
	end
  • Transmit string of bytes: p:write(string)
  • Wait all data to send: p:drainTX() or p:waitTX()
  • Close port: p:close()

lua-serial's People

Contributors

petr-kk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.