用SerialPort.Write 写串口数据的问题

zyleon 2007-09-05 06:07:48
SerialPort.Write函数写串口数据后,怎么样才能判断数据是否已经全部写到输出缓冲区里面了呢,这个函数应该不是阻塞的吧,发现write后,立即就返回了,但实际上串口还有一些数据没有写进去,怎么样才能知道数据已经全部写到输出缓冲区里面了呢
...全文
891 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
liyunpeng_111 2007-12-10
  • 打赏
  • 举报
回复
自已连自己bytetoread()看看接受缓存就可以了
owennol 2007-09-12
  • 打赏
  • 举报
回复
加标志位

你在另外一头Read的时候,只有读到标志位时,才停止读取
nwgogogo 2007-09-12
  • 打赏
  • 举报
回复
用wirteLine试试
Avoid 2007-09-12
  • 打赏
  • 举报
回复
如果数据量大的话,更改wirtetimeout的值
zyleon 2007-09-12
  • 打赏
  • 举报
回复
我跟踪了下,没写完就返回了
Avoid 2007-09-12
  • 打赏
  • 举报
回复
返回了就表明写入了。

默认写入超时为500毫秒
lljfl 2007-09-12
  • 打赏
  • 举报
回复
你用BytesToWrite==0试试
zyleon 2007-09-12
  • 打赏
  • 举报
回复
没有人知道吗
zyleon 2007-09-12
  • 打赏
  • 举报
回复
up
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

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧