微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

node-serialport Node.js 串口读写包

程序名称:node-serialport

授权协议: MIT

操作系统: 跨平台

开发语言: JavaScript

node-serialport 介绍

node-serialport 是一个 Node.js 的包,用来对串口数据进行读写操作。

基本示例代码

var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/tty-usbserial1", {
  baudrate: 57600
}, false); // this is the openImmediately flag [default is true]

serialPort.open(function (error) {
  if ( error ) {
    console.log('Failed to open: '+error);
  } else {
    console.log('open');
    serialPort.on('data', function(data) {
      console.log('data received: ' + data);
    });
    serialPort.write("ls\n", function(err, results) {
      console.log('err ' + err);
      console.log('results ' + results);
    });
  }
});

罗列所有串口:

var serialPort = require("serialport");
serialPort.list(function (err, ports) {
  ports.forEach(function(port) {
    console.log(port.comName);
    console.log(port.pnpId);
    console.log(port.manufacturer);
  });
});

串口配置:

  • baudrate

  • dataBits

  • stopBits

  • parity

  • rtscts

  • xon

  • xoff

  • xany

  • flowControl

  • bufferSize

  • parser

  • encoding

  • dataCallback

  • disconnectedCallback

  • platformOptions - sets platform specific options, see below.

目前已有很多项目在使用这个包进行串口处理:

  • Johnny-Five - Firmata based Arduino Framework.

  • Cylon.js - JavaScript Robotics, By Your Command.

  • node-l8smartlight (source) A node library to control the L8 Smartlight via Bluetooth or USB port

  • firmata Talk natively to Arduino using the firmata protocol.

  • tmpad source - a DIY midi pad using infrared, arduino, and nodejs. Video

  • duino - A higher level framework for working with Arduinos in node.js.

  • Arduino Drinking Game Extravaganza - AKA “The Russian” a hexidecimal drinking game for geeks by Uxebu presented at JSConf EU 2011.

  • Arduino controlling popcorn.js - Controlling a popcorn.js video with an Arduino kit.

  • Robotic JavaScript - The first live presentation of the node-serialport code set as presented at JSConf EU 2010.

  • devicestack - This module helps you to represent a device and its protocol.

  • reflecta A communication protocol that combines Arduino Libraries and NodeJS into an integrated system.

  • rc4pt-node - Control Popcorntime with an Infrared receiver and Arduino.

node-serialport 官网

https://github.com/voodootikigod/node-serialport

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐