c# SerialPort WriteTimeout 使用? [英] c# SerialPort WriteTimeout Use?

查看:202
本文介绍了c# SerialPort WriteTimeout 使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过串行端口与电路通信,想知道是否应该设置写入超时?

I am communicating with a circuit via serial port and was wondering if I should set a write timeout?

有人可以举例说明为什么/如何使用它吗?我理解读取超时的意义(例如,我刚刚发送了一个命令,我应该在 250 毫秒内收到响应)但并没有真正看到写入超时的原因.在一台非常老的电脑上,发送一个字符串需要超长的时间?

Could someone give an example of why/how it would be used? I understand the point of a read timeout (e.g. I just sent a command, I should receive a response in under 250ms) but don't really see the reasoning of a write timeout. On a really old computer it takes a super long time to send a character string?

谢谢.

推荐答案

如果您使用硬件握手,则在​​达到正确的握手引脚状态之前不会写入字节.因此,您可能会超时等待其他设备发出信号表明它已准备好接收更多数据,表明其末尾缓冲区已满,或者该设备只是离线.如果您关闭了硬件 hadshaking,或者将它跳接到串行端口(RTS 到 CTS),那么您可能超时的唯一时间是将字节写入设备的速度更快,它们可以通过线路发送.最终,您将填满输出缓冲区并阻塞(假设您没有使用 async io).如果驱动程序无法以足够快的速度清除缓冲区,并且超时设置过短,则您的写入可能会超时.

If you are using hardware handshaking, the bytes will not be written untill the proper handshaking pin states have been reached. So you could time out waiting for the other device to signal that it is ready for more data, idicating a buffer full at its end, or the device is simply off line. If you have hardware hadshaking turned off, or have it jumpered out on the serial port (RTS to CTS), then the only time you could possibly time out is writing bytes to the device faster that they can be sent over the line. Eventually you will fill up the output buffers and block (assuming that you are not using async io). If the driver can not clear the buffers fast enough, you could time out on your write, if you have the time out set too short.

这篇关于c# SerialPort WriteTimeout 使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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