如何在串行发送数据字节后设置间歇时间? [英] How Do I Set Interbyte Timing After Sending Bytes Of Data Serially?

查看:85
本文介绍了如何在串行发送数据字节后设置间歇时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是通过设备从COM端口串行发送数据到USB,我需要实现间歇时序吗?谁能解释我怎么能实现呢?

I am sending data serially across the device from COM port to USB, and i need to implement interbyte timing? Could anyone explain me how can this be implemented?

推荐答案

这很复杂 - 因为串口端口类是由Windows缓存的,串口本身(通常)是由缓冲的它的驱动程序,硬件通常也有几个字节的缓冲区。为了使生活更加复杂,串行输出流被有效缓冲,因为数据(以及它的相关启动,停止和奇偶校验位)一次输出一位,提供另一层缓冲。



您可以在宏观范围内完成 - 使用某种形式的计时器,这样您只能加载每秒n字节的SerialPort实例 - 但它很笨拙。

你可以通过改变停止位(1,1.5或2)的数量来实现微观规模,这会增加少量的每个字符延迟 - 但是你不能通过这种方式添加很多东西。



到底想要得到什么?
That's complicated - because the Serial port class is buffered by Windows, the serial port itself is (normally) buffered by it's driver, and the hardware generally has a couple of bytes worth of buffer in it as well. And to make life even more complicated, the serial output stream is effectively buffered because the data (and it's associated start, stop, and parity bits) is output one bit at a time, providing another layer of buffering.

You can do it on a macro scale - using a timer of some form so that you can only load the SerialPort instance with "n bytes per second" - but it's clumsy.
And you can do it on a micro scale by altering the number of stop bits (1, 1.5 or 2) which will add a small amount of "per character" delay - but you can't add a lot that way.

What exactly are you trying to get?


这篇关于如何在串行发送数据字节后设置间歇时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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