Universal Asynchronous Receiver/Transmitter(UART), is a common hardware interface and widely used for asynchronous communication of devices.
- To know more about UART, please visit here.
Prerequisites
- Please click here if you are not sure how to use Ruff to write apps.
- Visit Driver- Geting Started and Driver Model, if you know nothing about the driver development.
Using UART
Please read your datasheet to confirm the interface is GPIO.
Configuring driver.json
Please declare that your interface is UART in driver.json. The declaration should be inputs with UART as its type.{
...
"inputs": {
"uart": {
"type": "uart",
"args": {
"baudRate": 57600,
"stopBits": 1,
"dataBits": 8,
"parity": "none",
"flowControl": "none"
}
}
}
}
Interface Properties
The following properties is accepted for UART:
baudRate
- UART baud ratestopBits
- stop bitsdataBits
- data bitsparity
- set UART paritynone
- no parityodd
- odd parityeven
- even parity
flowControl
- how the flow control worksnone
- no flow controlhard
- hardware flow controlsoft
- software flow control
Writing a Driver
Reading Data
- The driver can read data from UART. Here is an example:
var data=0; |
Writing Data
The driver can also write data to UART. Here is an example:function writeContent(data, callback) {
uart.write(data, callback);
}
- Please visit UART API document for more details.
Application
The following example will demostrate how to write a driver with UART interface. An UART interface will be declared in driver.json, with 19200 Bd/s baud rate, 1 stop bits, 8 data bits, no parity, and no flow control."models": [
"waveshare-fingerprint"
],
"inputs": {
"uart": {
"type": "uart",
"args": {
"baudRate": 19200,
"stopBits": 1,
"dataBits": 8,
"parity": "none",
"flowControl": "none"
}
}
}
We will provide two menthods for this module - write text and read text:
- writeText, write text to UART
- readText, read text from UART
; |