docs » hs.serial
Communicate with external devices through a serial port (most commonly RS-232).
Powered by ORSSerialPort. Thrown together by @latenitefilms.
Copyright (c) 2011-2012 Andrew R. Madsen (andrew@openreelsoftware.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- Functions - API calls offered directly by the extension
- availablePortNames
- availablePortPaths
- deviceCallback
- Constructors - API calls which return an object, typically one that offers API methods
- newFromName
- newFromPath
- Methods - API calls which can only be made on an object returned by a constructor
- baudRate
- callback
- close
- dataBits
- isOpen
- name
- open
- parity
- path
- sendData
- shouldEchoReceivedData
- stopBits
- usesDTRDSRFlowControl
- usesRTSCTSFlowControl
| Signature | hs.serial.availablePortNames() -> table |
|---|---|
| Type | Function |
| Description | Returns a table of currently connected serial ports names. |
| Parameters |
|
| Returns |
|
| Signature | hs.serial.availablePortPaths() -> table |
|---|---|
| Type | Function |
| Description | Returns a table of currently connected serial ports paths. |
| Parameters |
|
| Returns |
|
| Signature | hs.serial.deviceCallback(callbackFn) -> none |
|---|---|
| Type | Function |
| Description | A callback that's triggered when a serial port is added or removed from the system. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Signature | hs.serial.newFromName(portName) -> serialPortObject |
|---|---|
| Type | Constructor |
| Description | Creates a new hs.serial object using the port name. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Signature | hs.serial.newFromPath(path) -> serialPortObject |
|---|---|
| Type | Constructor |
| Description | Creates a new hs.serial object using a path. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Signature | hs.serial:baudRate([value], [allowNonStandardBaudRates]) -> number | serialPortObject |
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Gets or sets the baud rate for the serial port. |
| Parameters |
- value - An optional number to set the baud rate.
- [allowNonStandardBaudRates] - An optional boolean to enable non-standard baud rates. Defaults to
false.
- If a value is specified, then this method returns the serial port object. Otherwise this method returns the baud rate as a number
- This function supports the following standard baud rates as numbers: 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 230400.
- If no baud rate is supplied, it defaults to 115200.
| Signature | hs.serial:callback(callbackFn) -> serialPortObject |
|---|---|
| Type | Method |
| Description | Sets or removes a callback function for the hs.serial object. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Signature | hs.serial:close() -> serialPortObject |
|---|---|
| Type | Method |
| Description | Closes the serial port. |
| Parameters |
|
| Returns |
|
| Signature | hs.serial:dataBits([value]) -> number | serialPortObject |
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Gets or sets the number of data bits for the serial port. |
| Parameters |
- value - An optional number to set the number of data bits. It can be 5 to 8.
- If a value is specified, then this method returns the serial port object. Otherwise this method returns the data bits as a number.
- The default value is 8.
| Signature | hs.serial:isOpen() -> boolean |
|---|---|
| Type | Method |
| Description | Gets whether or not a serial port is open. |
| Parameters |
|
| Returns |
|
| Signature | hs.serial:name() -> string |
|---|---|
| Type | Method |
| Description | Returns the name of a hs.serial object. |
| Parameters |
|
| Returns |
|
| Signature | hs.serial:open() -> serialPortObject | nil |
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Opens the serial port. |
| Parameters |
- None
- The
hs.serialobject ornilif the port could not be opened.
| Signature | hs.serial:parity([value]) -> string | serialPortObject |
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Gets or sets the parity for the serial port. |
| Parameters |
- value - An optional string to set the parity. It can be "none", "odd" or "even".
- If a value is specified, then this method returns the serial port object. Otherwise this method returns a string value of "none", "odd" or "even".
| Signature | hs.serial:path() -> string |
|---|---|
| Type | Method |
| Description | Returns the path of a hs.serial object. |
| Parameters |
|
| Returns |
|
| Signature | hs.serial:sendData(value) -> none |
|---|---|
| Type | Method |
| Description | Sends data via a serial port. |
| Parameters |
|
| Returns |
|
| Signature | hs.serial:shouldEchoReceivedData([value]) -> boolean | serialPortObject |
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Gets or sets whether the port should echo received data. |
| Parameters |
- value - An optional boolean.
- If a value is specified, then this method returns the serial port object. Otherwise this method returns a boolean.
- The default value is
false.
| Signature | hs.serial:stopBits([value]) -> number | serialPortObject |
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Gets or sets the number of stop bits for the serial port. |
| Parameters |
- value - An optional number to set the number of stop bits. It can be 1 or 2.
- If a value is specified, then this method returns the serial port object. Otherwise this method returns the number of stop bits as a number.
- The default value is 1.
| Signature | hs.serial:usesDTRDSRFlowControl([value]) -> boolean | serialPortObject |
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Gets or sets whether the port should use DTR/DSR Flow Control. |
| Parameters |
- value - An optional boolean.
- If a value is specified, then this method returns the serial port object. Otherwise this method returns a boolean.
- The default value is
false.
| Signature | hs.serial:usesRTSCTSFlowControl([value]) -> boolean | serialPortObject |
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Gets or sets whether the port should use RTS/CTS Flow Control. |
| Parameters |
- value - An optional boolean.
- If a value is specified, then this method returns the serial port object. Otherwise this method returns a boolean.
- The default value is
false.