我正在使用 SerialPort 类与外部设备进行通信.我以每秒 300 波特的速度开始通信,但是在初始握手"之后,我必须切换到设备指定的波特率(通常为 9600 Bps).
I am using SerialPort class to communicate with an external device. I start the communication at 300 Baud per second however after the initial "handshake" I have to switch to a Baud rate specified by the device (usually 9600 Bps).
我在提高波特率后尝试继续通信没有成功,但我不知道为什么.这引出了我的问题:改变波特率的正确方法是什么?可以在连接打开时完成,还是我应该先关闭连接?
I have been unsuccessful in my attempts to continue communicating after I increase Baud rate however I am not sure why. That leads me to my question: What is the proper way of changing the Baud rate? Can it be done while the connection is open, or should I close the connection first?
我无法在文档中找到有关此的任何信息...
I have been unable to find any information about this in the documentation...
我都尝试过,但都没有成功,这让我觉得我一定错过了一些明显的东西.
I have tried both and have been unsuccessful in both ways, which made me think that I must be missing something obvious.
原来你可以在 SerialPort.BaudRate 打开的时候改变它.但是@Groo 在回答中提到的 SerialPort.DiscardInBuffer 是一个很好的提示!
It turns out you can change SerialPort.BaudRate while it is open. But the SerialPort.DiscardInBuffer that is mentioned in answer by @Groo is a good tip!
这篇关于连接打开时更改 SerialPort 的 BaudRate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!