Community
cancel
Showing results for 
Search instead for 
Did you mean: 
镕镕徽_莫
Novice
1,218 Views

How to use node.js to write data into Uart Serial on Intel Edison board with Arduino Board.

Hello,I am a student from Central South University in China. I am studying using node.js module on Intel Edison board with Arduino.

I want to use the Uart Serial on Intel Edison Board,The node.js demo program is as follow:

var m = require('mraa'); //require mraa

console.log('MRAA Version: ' + m.getVersion());

rfid_UART = new m.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");

re1 = rfid_UART.setTimeout(1000,1000,1000);

console.log("res1:", "res1"+re1);

re2 = rfid_UART.setBaudRate(115200);

console.log("res2:", "res2"+re2);

re3 = rfid_UART.SetNonBlocking(false);

console.log("res3:", "res3"+re3);

re4 = rfid_UART.setFlowcontrol(false,false);

console.log("res4:", "res4"+re4);

<spa...

4 Replies
idata
Community Manager
101 Views

Hi,

Take a look at https://software.intel.com/en-us/node-js-templates-for-intel-xdk https://software.intel.com/en-us/node-js-templates-for-intel-xdk . Here you can see a node.js template that demonstrates how to instantiate the uart serial object. If this is not set correctly then it's likely other functions won't work as expected, such as the case with the functions you describe.

I've never tried to write a HEX value to UART. It seems the only functions available are write and writeStr, but I'm not sure how to write a HEX data. arfoll do you have any inputs?

Have you looked at the SetNonBlocking () function?

-Sergio

 

idata
Community Manager
101 Views

For sending hex values the serialport npm packet is a good choice:

https://www.npmjs.com/package/serialport serialport

you use a buffer holding the hex values:

var mybuf= new Buffer([0x7E, 0x40, 0x0E, 0x00, 0x01]);

serialPort.write(mybuf, function(err, results) { //Write data

console.log("err " + err);

console.log("results" + results);

});

Flo1991

镕镕徽_莫
Novice
101 Views

I have successfully read data from uart by using mraa(3.RE)

Thank you very much.

镕镕徽_莫
Novice
101 Views

I have successfully read data from uart by using mraa .

The right method is:

val = new Buffer("AA0003000100048E",'hex');

 

var t =

 

rfid_UART.write(val);

 

sleep(200);

 

console.log("res7:", val.toString('hex')

 

);

var res8 =

 

rfid_UART.dataAvailable(200);

 

sleep(200);

 

console.log("res8:",

 

"res8"+res8);

result =

 

rfid_UART.read(23);

 

sleep(200);

 

console.log("res9:",result.toString('hex'));

Maybe The API docunment author should update his API document :

http://iotdk.intel.com/docs/master/mraa/node/classes/uart.html http://iotdk.intel.com/docs/master/mraa/node/classes/uart.html

After reading document,I don't know length could be a Buffer:

Thank you a lot.
Reply