改变的SerialPort的波特率,而连接已打开 [英] Change SerialPort's BaudRate while connection is open

查看:1288
本文介绍了改变的SerialPort的波特率,而连接已打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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的波特率,而连接已打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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