node.js 读取 USB 端口信号 [英] node.js to read usb port signals

查看:124
本文介绍了node.js 读取 USB 端口信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 npm 为 node.js 安装了 serialport 模块.(npm install serialport).现在我想通过我的电脑的 USB 端口从我的 android 手机发送一些消息到节点应用程序(假设节点可以读取串口信号).以前有人这样做过吗?

I have installed serialport module for node.js using npm.(npm install serialport). Now I would like to send some messages from my android phone to node application via usb port of my computer(assuming node can read serial port signals). Has anyone done this before?

提前致谢.

推荐答案

为什么,是的,这当然是可行的.serialport 包主页 本身列出了大量示例.

Why, yes, it's certainly doable. There's a plenty of examples listed at the serialport package homepage itself.

您的 node.js 应用程序将以...开头

Your node.js application will start with...

var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/tty-usbserial1");

serialPort.on('data', function(data) { /* processing data */ });

这篇关于node.js 读取 USB 端口信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆