Ruff 1.2.0 Documentation
Table of Contents
UART#
A universal asynchronous receiver/transmitter, abbreviated UART /ˈjuːɑːrt/, is a computer hardware device that translates data between characters (usually bytes) in a computer and an asynchronous serial communication format that encapsulates those characters between start bits and stop bits.
Using a UART Interface in Driver#
Configuring driver.json
#
To use a UART interface in a driver, you need to have an input with type "uart"
in the driver.json
:
{
"models": [],
"inputs": {
"uart": {
"type": "uart",
"args": {
"baudRate": 57600,
"stopBits": 1,
"dataBits": 8,
"parity": "none",
"flowControl": "none"
}
}
}
}
In the JSON configuration above, the first "uart"
is just the name of the UART interface (you can change it to something else if you want to),
which will be used as the key to get the interface instance in the driver.
And the "type": "uart"
informs Ruff framework to distribute an UART interface instead of others.
Arguments#
boudRate
#
Baud rate, defaults to 57600
.
stopBits
#
Stop bits, defaults to 1
.
dataBits
#
Data bits, defaults to 8
.
parity
#
Parity, defaults to "none"
, could be either of "none"
, "odd"
or "even"
.
flowControl
#
Flow control, defaults to "none"
, could be either of "none"
, "hardware"
or "software"
.
Writing a Driver#
'use strict';
var driver = require('ruff-driver');
module.exports = driver({
attach: function (inputs) {
this._uart = inputs['uart'];
},
exports: {
writeTwice: function (data, callback) {
this._uart.write(data);
this._uart.write(data, callback);
},
readText: function (callback) {
this._uart.read(function (error, data) {
if (error) {
callback(error);
return;
}
callback(undefined, data.toString());
});
}
}
});
API References#
Methods#
read(callback)
#
Read incoming data (as Buffer
) from the interface.
write(data[, callback])
#
Write data to the interface.
- data: data to write, could be either a
Buffer
or astring
.