c# SerialPort WriteTimeout Use?

孤街浪徒 提交于 2019-12-11 02:52:59

问题


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

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?

Thanks.


回答1:


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.



来源:https://stackoverflow.com/questions/7745941/c-sharp-serialport-writetimeout-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!