接收com端口数据时出错(c#.net) [英] error to receive com port data (c#.net)

查看:87
本文介绍了接收com端口数据时出错(c#.net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个用于接收COM端口数据并将其显示在数据网格中的C#应用​​程序.这是

I developed a c# application for receiving com port data and display it in data grid. which is

void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
               int bytes = comPort.BytesToRead;
               byte[] comBuffer = new byte[bytes];
               comPort.Read(comBuffer, 0, bytes)
               MainScreen._message = ByteToHex(comBuffer);//ByteToHex is method of convert data in hexa
                                                         //_message is variable and store data and i use it in another page  
}



该代码用于接收COM端口数据.

在这段代码中,它接收数据并将其显示到数据网格中,但是当我连续发送数据时,有时它没有接收到数据后,没有任何错误显示只是接收数据.有时我也得到安全处理已经关闭了,但不是每次我都得到那个错误.

请帮助我解决此问题.



this code is for receiving com port data.

in this code it receive data and display it into data grid but when i continuously sending data then after sometimes it does not receive data not any error show just receive data.some time i also get safe handled has been close but not every time i get that error.

please help me to solve this problem.

推荐答案

您提供的代码片段将起作用-您已经说过了.
您描述的问题与该代码无关-可能是任何事情.
您所连接的设备可能没话说了.
它可能正在等待您的回复.
上次传送时可能会说什么?我听不懂".

您需要查看应用程序正在执行g =做的事情,被连接到的事情等等的整个图片.

抱歉,我们甚至无法为您提供帮助.
The code fragment you have provided will work - you have said it does.
The problem you have described is unrelated to that code - it could be anything.
It could be that the device you are attached to has run out of things to say.
It could be waiting for you to reply.
It could have said "What? I don''t understand" to your last transmission.

You need to look at the whole picture of what you app is g=doing, is connected to, and so forth.

Sorry, but we cannot help you, even slightly.


我编写此代码来解决我的问题.


i write this code for solve my problem.


protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(false);
            
        }


这篇关于接收com端口数据时出错(c#.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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