Node.js 串口读写包 node-serialport

码农软件 · 软件分类 · Node.js 扩展 · 2019-04-14 23:28:18

软件介绍

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.

本文地址:https://codercto.com/soft/d/3602.html

JUnit Recipes中文版

JUnit Recipes中文版

陈浩等译 / 电子工业 / 2006-9 / 69.00元

《JUnit Recipes中文版:程序员实用测试技巧》主要介绍了在Java开发中使用JUnit进行单元测试的各种方法、原则、技巧与实践。本书出自开发一线专家之手,本着实用的原则,涵盖各类Java开发中应用JUnit的实用技巧,内容丰富、全面深入;无论对于需要应用JUnit进行单元测试的一线Java开发人员,还是JUnit入门、进阶者,本书都是一本不可多得的实用指南。这本书介绍了大量的JUnit实......一起来看看 《JUnit Recipes中文版》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具