Raspi Serial is part of the Raspi.js suite that provides access to UART ports, either the built-in port or a USB add-on port.
If you have a bug report, feature request, or wish to contribute code, please be sure to check out the Raspi IO Contributing Guide.
First, be sure that you have installed raspi.
Install with NPM:
npm install raspi-serial
Warning: this module requires GCC 4.8 or newer. This means that you should be running Raspbian Jessie or newer, released in September of 2015.
var raspi = require('raspi');
var Serial = require('raspi-serial').Serial;
raspi.init(function() {
var serial = new Serial();
serial.open(() => {
serial.write('Hello from raspi-serial');
serial.on('data', function(data) {
process.stdout.write(data);
});
});
});
Constant | Description |
---|---|
DEFAULT_PORT | The port ID of the default serial port, equals `"/dev/ttyAMA0"` |
PARITY_NONE | Use no parity, one of five possible values for the parity property in the constructor options |
PARITY_EVEN | Use even parity, one of five possible values for the parity property in the constructor options |
PARITY_ODD | Use odd parity, one of five possible values for the parity property in the constructor options |
PARITY_MARK | Use mark parity, one of five possible values for the parity property in the constructor options |
PARITY_SPACE | Use space parity, one of five possible values for the parity property in the constructor options |
Instantiates a new Serial instance with the given options, defaulting to the built-in UART port. Check the wiring information wiki for more information.
Arguments:
Argument | Type | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options (optional) | Object | The configuration options. | ||||||||||||||||||
|
The serial port tied to this instance
Type: String
The baud rate tied to this instance
Type: String
The number of data bits tied to this instance
Type: String
The number of stop bits tied to this instance
Type: String
The parity tied to this instance
Type: String
Write the given data to the serial port.
Arguments:
Argument | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
data | Buffer | String | The data to write to the port | ||||||
cb (optional) | Function | The callback to call once writing is complete | ||||||
|
Returns: None
Flushes the serial port.
Arguments:
Argument | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
cb (optional) | Function | The callback to call once writing is complete | ||||||
|
Returns: None
Fired whenever data is received on the serial port.
Callback Arguments:
BufferArgument | Type | Description |
---|---|---|
data | The data read from the serial port. |
The MIT License (MIT)
Copyright (c) 2016 Bryan Hughes (bryan@nebri.us)
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.