ode-serialport是一个Node.js的包,用来对串口数据进行读写操作。
基本示例代码:
var SerialPort = require("serialport").SerialPortvar serialPort = ew SerialPort("/dev/tty-usbserial1", { baudrate: 57600}, false); // this is the opeImmediately flag [default is true]serialPort.ope(fuctio (error) { if ( error ) { cosole.log('failed to ope: '+error); } else { cosole.log('ope'); serialPort.o('data', fuctio(data) { cosole.log('data received: ' + data); }); serialPort.write("ls\", fuctio(err, results) { cosole.log('err ' + err); cosole.log('results ' + results); }); }});罗列所有串口:
var serialPort = require("serialport");serialPort.list(fuctio (err, ports) { ports.forEach(fuctio(port) { cosole.log(port.comName); cosole.log(port.ppId); cosole.log(port.maufacturer); });});串口配置:
baudRate
dataBits
stopBits
parity
rtscts
xo
xoff
xay
flowCotrol
bufferSize
parser
ecodig
dataCallback
discoectedCallback
platformOptios-setsplatformspecificoptios,seebelow.
目前已有很多项目在使用这个包进行串口处理:
Johy-Five-FirmatabasedArduioFramework.
Cylo.js-JavaScriptRobotics,ByYourCommad.
ode-l8smartlight(source)AodelibrarytocotroltheL8SmartlightviaBluetoothorUSBport
firmataTalkativelytoArduiousigthefirmataprotocol.
tmpadsource-aDIYmidipadusigifrared,arduio,adodejs.Video
duio-AhigherlevelframeworkforworkigwithArduiosiode.js.
ArduioDrikigGameExtravagaza-AKA"TheRussia"ahexidecimaldrikiggameforgeeksbyUxebupresetedatJSCofEU2011.
Arduiocotrolligpopcor.js-Cotrolligapopcor.jsvideowithaArduiokit.
RoboticJavaScript-Thefirstlivepresetatiooftheode-serialportcodesetaspresetedatJSCofEU2010.
devicestack-Thismodulehelpsyoutorepresetadeviceaditsprotocol.
reflectaAcommuicatioprotocolthatcombiesArduioLibrariesadNodeJSitoaitegratedsystem.
rc4pt-ode-CotrolPopcortimewithaIfraredreceiveradArduio.
评论