From dbd1a3153635e05c26addc160b99deec438e5be8 Mon Sep 17 00:00:00 2001 From: xbolshe Date: Fri, 9 Oct 2015 04:20:04 +0300 Subject: [PATCH] uart.js: Rewrite of example to show more functionality Signed-off-by: Eugene Bolshakov Signed-off-by: Brendan Le Foll --- examples/javascript/uart.js | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/examples/javascript/uart.js b/examples/javascript/uart.js index 55437d8..a3a96e5 100644 --- a/examples/javascript/uart.js +++ b/examples/javascript/uart.js @@ -1,6 +1,6 @@ /* - * Author: Brendan Le Foll - * Copyright (c) 2015 Intel Corporation. + * Author: Eugene Bolshakov + * Copyright (c) 2015 Eugene Bolshakov * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -23,6 +23,32 @@ */ var m = require('mraa'); //require mraa - +console.log('MRAA Version: ' + m.getVersion()); u = new m.Uart(0) -console.log(u.getDevicePath()) + +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"); + +u.setBaudRate(115200); +u.setMode(8, 0, 1); +u.setFlowcontrol(false, false); +sleep(200); + +console.log("First write-read circle:"); + +u.writeStr("test\n"); +sleep(200); +console.log(u.readStr(6)); +sleep(200); + +console.log("Second write-read circle:"); + +u.writeStr("2nd test\n"); +sleep(200); +console.log(u.readStr(10)); -- 2.7.4