从串口接收数据后出现问题 [英] Problem after recieveing data from serial port

查看:152
本文介绍了从串口接收数据后出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



以下是我通过串口接收数据的代码



Hi all

Below is the code through which i am receiving data from serial port

public void com2()
        {
            try
            {
                clear();
                ////L034.0W045.5H009.5CS02.12K                

                if (serial_2.IsOpen)
                {
                    serial_2.Close();
                }
                //Sets up serial port
                serial_2.PortName = ConfigurationManager.AppSettings["port1"].ToString();
                serial_2.BaudRate = Convert.ToInt32(ConfigurationManager.AppSettings["BaudRate"].ToString());
                //serial.Handshake = System.IO.Ports.Handshake.None;
                serial_2.Parity = Parity.None;
                serial_2.DataBits = 8;
                serial_2.StopBits = StopBits.One;
                serial_2.ReadTimeout = 3000;
                serial_2.WriteTimeout = 3000;
                serial_2.DtrEnable = true;
                serial_2.RtsEnable = true;
                if (!serial_2.IsOpen)
                {
                    serial_2.Open();
                }
                p = true;
                serial_2.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(Recieve_1);
                //serial_2.Close();
            }
            catch (Exception ex)
            {
               // MessageBox.Show("Closing COM4", "Essae", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.Cancel);
            }
        }





键盘通话代码





Keyboard calling code

private void txtphno_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
    try
    {
        App._KeyCode = txtphno.Text;
        //App._inputfor = "Enter phone number";
        Keyboard key = new Keyboard();
        key.Owner = this;
        key.ShowDialog();
        txtphno.Text = App._KeyCode;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Essae", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.Cancel);
    }
}







public Keyboard()
      {
          InitializeComponent();
          this.Top = 768 - this.Height;
          this.Left = 0;
      }





但问题是来自端口的数据不断,我在屏幕上有一个我的应用程序的键盘。我在textbox1_previewmouseup事件中调用它。

但是当我触摸文本框时,我的应用程序正在被绞死。



如果我关闭设备并尝试,它正常工作(即键盘显示)。



请大家提出一些建议。



需要进一步的信息请告诉。



谢谢



but the problem is the data keep on coming from the port, i m having one on screen keyboard for my application.i am calling that in textbox1_previewmouseup event.
but when i am touching the textbox, my application is getting hanged.

if i turn off the device and try, it's working properly(i.e keyboard is showing).

Please need some suggestion from you all.

any further information needed please tell.

Thank you

推荐答案

这篇关于从串口接收数据后出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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