无法以115200波特连接到串行端口 [英] Cannot connect to serial port at 115200 baud

查看:111
本文介绍了无法以115200波特连接到串行端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个有趣的问题...我有一些软件可以使用大量计算机(超过100个)它使用.NET串口类连接到串口。该软件必须在115200连接才能使所有功能正常工作。现在通常没有问题。
但是,我有两台计算机无法连接115200.它们可以连接19200或9600而不是115200.此外,它们可以在115200与其他一些软件连接而没有问题!这是用串行
端口嗅探器查看时发生的事情:

I have a funny problem...I have some software that is working with lots of computers (over 100) It connects to a serial port using the .NET serial port class. The software must connect at 115200 for all the features to work. Now normally there is no issue. However, I have two computers that cannot connect at 115200. They can connect at 19200 or 9600 but not 115200. In addition, they can connect at 115200 with a few other pieces of software without issues! This is what is happening when looked at with a serial port sniffer:

 19200 Baud Trace:



[29/04/2018 19:05:26] - 打开端口COM3

[29/04/2018 19:05:26] - Open port COM3


[29/04/2018 19:05:26]更改波特率:19200

[29/04/2018 19:05:26]Changed baudrate: 19200


[29/04/2018 19:05:26]禁用RTS

[29/04/2018 19:05:26]Disabled RTS


[29/04/2018 19:05:26]禁用DTR

[29/04/2018 19:05:26]Disabled DTR


[29/04/2018 19:05:26]更改了行控制:Databits 8,Parity none,StopBits 1

[29/04/2018 19:05:26]Changed line control: Databits 8, Parity none, StopBits 1


[29/04/2018 19:05:26]更改流量控制:ControlHandShake 0x00,FlowReplace 0x00,XonLimit 55546,XoffLimit 55546

[29/04/2018 19:05:26]Changed flow control: ControlHandShake 0x00, FlowReplace 0x00, XonLimit 55546, XoffLimit 55546


[29/04/2018 19:05:26]更改波特率:19200

[29/04/2018 19:05:26]Changed baudrate: 19200


,这是115200

and this is at 115200

 115200 Baud trace:



[29/04/2018 19:10:43] - 打开端口COM3

[29/04/2018 19:10:43] - Open port COM3


[29/04/2018 19:10:43] - 关闭端口COM3

[29/04/2018 19:10:43] - Close port COM3


[29/04/2018 19:10:43] - 打开端口COM3

[29/04/2018 19:10:43] - Open port COM3


[29/04/2018 19:10:43] - 关闭端口COM3

[29/04/2018 19:10:43] - Close port COM3


有没有人有任何想法发生了什么?

Does anyone have any ideas what is happening?


这是代码:

Here is the code:

            port = new SerialPort(comport, baud);

            port.ReadTimeout = 20;
            port.Open();

推荐答案

嗨墓1818,

Hi tomb1818,

我建议你可以订阅
DataReceived Event
检查它是否正在激活。请设置
DTR

RTS
为true,如果连接的设备需要它们,它将不会传输数据。这里有一个示例参考。

I would suggest that you could subscribe to the DataReceived Event to check if it is firing at all. please set DTR and RTS to true, if the connected device needs them it will not transmit data. here is a sample for your reference.

static void Main(string[] args)
        {
            const int bufSize = 2048;
            Byte[] buf = new Byte[bufSize]; //To store the received data.
            string comport = "COM1";
            int baud = 115200;
            SerialPort port ;
            
            port = new SerialPort(comport, baud);
            port.DataReceived += port_OnReceiveDatazz; // Add DataReceived Event Handler
            port.DtrEnable = true;
            port.RtsEnable = true;
            port.ReadTimeout = 20;
            port.Open();
        }

        // My Event Handler Method
        private static void port_OnReceiveDatazz(object sender,
                                   SerialDataReceivedEventArgs e)
        {
            SerialPort spL = (SerialPort)sender;
            const int bufSize = 12;
            Byte[] buf = new Byte[bufSize];
            Console.WriteLine("DATA RECEIVED!");
            Console.WriteLine(spL.Read(buf, 0, bufSize));
        }

祝你好运,

张龙


这篇关于无法以115200波特连接到串行端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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