什么是的SerialPort写缓存的目的是什么? [英] What is the purpose of the SerialPort write buffer?

查看:197
本文介绍了什么是的SerialPort写缓存的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从外面的SerialPort对象,似乎没有什么区别什么写缓冲区的大小,以及是否是满的。

From outside SerialPort object, it seems to make no difference what the size of the write buffer is, and whether or not it is full.

使用同步写, write方法阻塞,直到所有数据已发送和缓冲区是空的。

Using synchronous writing, the write method blocks until all the data has been sent and the buffer is empty.

使用异步写入,数据被排队,并计划继续在持续。不调用回调方法直到写操作完成并且数据不在缓冲液中。

Using async writing, the data is queued and the program continues on going. The callback method is not called until the write operation is completed and the data is out of the buffer.

的serialport对象的行为似乎是相同的,不管如何多的数据在缓冲器和缓冲器是否已满。没有错误似乎当写缓冲区已满的情况发生。

The behavior of the serialport object seems to be the same regardless of how much data is in the buffer and whether or not the buffer is full. No errors seem to happen when the write buffer is full.

那么,为什么能够检查BytesToWrite和WriteBufferSize呢?有没有什么办法的SerialPort行为不同,当写缓冲区已满?

So, why be able to check BytesToWrite and WriteBufferSize at all? Is there any way that SerialPort behaves differently when the write buffer is full?

推荐答案

C#的的SerialPort。 BytesToWrite 属性对应的非托管的Win32被描述为 COMSTAT.cbOutQue 字段:

The C# SerialPort.BytesToWrite property corresponds to the unmanaged Win32 COMSTAT.cbOutQue field which is described as:


  • 要对所有的写操作发送剩余用户数据的字节数。此值将为零的非重叠写入。

这似乎在暗示你可以观察到写缓冲,因为它是用发送被消耗异步写入写完整的回调被调用之前。

This seems to suggest you could observe the write buffer being consumed as it is sent with async writing before the write complete callback is called.

这篇关于什么是的SerialPort写缓存的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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