Files
mraa/examples/javascript/uart.js
Thomas Ingleby 170bdd104f spdx: add spdx tags to most files
Large change that removes the duplicated MIT notice withe a spdx tag

Signed-off-by: Thomas Ingleby <thomas.ingleby@intel.com>
2019-05-23 10:09:12 -07:00

40 lines
811 B
JavaScript

/*
* Author: Eugene Bolshakov <pub@relvarsoft.com>
* Copyright (c) 2015 Eugene Bolshakov
*
* SPDX-License-Identifier: MIT
*/
"use strict";
const mraa = require('mraa'); //require mraa
console.log('MRAA Version: ' + mraa.getVersion());
let uart = new mraa.Uart(0);
console.log("Note: connect Rx and Tx of UART with a wire before use");
function sleep(delay) {
delay += new Date().getTime();
while (new Date() < delay) {}
}
console.log("Set UART parameters");
uart.setBaudRate(115200);
uart.setMode(8, 0, 1);
uart.setFlowcontrol(false, false);
sleep(200);
console.log("First write-read circle:");
uart.writeStr("test\n");
sleep(200);
console.log(uart.readStr(6));
sleep(200);
console.log("Second write-read circle:");
uart.writeStr("2nd test\n");
sleep(200);
console.log(uart.readStr(10));