简体   繁体   English

串口通讯

[英]serial port communication

HI all, 大家好,

I am doing serial port communication program. 我正在做串口通讯程序。 How do I achieve the following. 我如何实现以下目标。

  1. Need to know number bytes available for reading. 需要知道可读取的数字字节。
  2. Flushing 冲洗

Note: I am creating File with Overlapped option. 注意:我正在创建“文件重叠”选项。

thanks in advance 提前致谢

~ Johnnie 〜约翰尼

You are trying to query the number of bytes available first, and then read them. 您正在尝试先查询可用的字节数,然后再读取它们。 The standard way would be to just allocate a buffer (say 1000 chars), then call ReadComm() which tells you how many bytes were actually used (eg less than or equal to 1000). 标准方法是只分配一个缓冲区(例如1000个字符),然后调用ReadComm()来告诉您实际使用了多少个字节(例如,小于或等于1000)。

You can flush the buffer of serial io using FlushFileBuffers() (http://msdn.microsoft.com/en-us/library/aa364439%28VS.85%29.aspx) but since you want asynchronous IO, you probably only want to do that when you have written to a file and then want to move the file (certainly not on every call to WriteComm()). 您可以使用FlushFileBuffers()(http://msdn.microsoft.com/zh-cn/library/aa364439%28VS.85%29.aspx)刷新串行io的缓冲区,但是由于要使用异步IO,您可能只希望当您已写入文件然后想要移动文件时 (一定不是在每次调用WriteComm()时),您都可以执行此操作。

More info: 更多信息:

http://msdn.microsoft.com/en-us/library/ms810467.aspx http://msdn.microsoft.com/en-us/library/ms810467.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM