mscomm32串口控件 和 node serialport

本文记录了作者在项目中使用mscomm32串口控件遇到的问题,包括JS如何发送16进制字节数组给串口以及oncomm事件触发问题。在寻求解决方案的过程中,作者尝试了使用串口监控软件、编写新的ActiveX控件,但遇到了注册控件、属性不被识别等问题。最后,通过使用Node.js作为串口通信的中间层,成功实现了需求,作者提供了相关测试demo的GitHub链接。
摘要由CSDN通过智能技术生成
近期做的一个项目需要在页面调用串口通信,于是选择了使用mscomm32这个控件,记录一下使用的过程。
控件的安装注册都没问题,按照教程调试时发现了2个问题,希望有大神帮忙解答一下:
1. JS没有所谓的字节数组,不知道如何将16进制的字节数组发给串口;
JS规范里面是有ArrayBuffer的,之前查mscomm32控件的时候看到的大部分都是好多年前的文章。
2.控件的oncomm事件只有1,也就是发送数据事件能触发。当我试图接收数据时oncomm事件2始终无法触发。
其他的状态为0,可是关于这个控件没有找到oncomm事件为0的描述。
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);   }); });串口配置:baudRatedataBitsstopBitsparityrtsctsxonxoffxanyflowControlbufferSizeparserencodingdataCallbackdisconnectedCallbackplatformOptions - 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 portfirmata Talk natively to Arduino using the firmata protocol.tmpad source - a DIY midi pad using infrared, arduino, and nodejs. Videoduino - 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值