void Run()
        {
            m_eng.Start();
            m_eng.OnMessage += new _DBG.MessageEventHandler(OnMessage);
            m_eng.Stop();
            m_eng = null;
        }
        void OnMessage(_WP.IncomingMessage msg, string text)
        {
            txtRead.Text = text;//Console.write(text);
        }
为什么用consoleapplication: Console.write(text);数据就可以显示,可换成windowapplication要怎么改呢?

解决方案 »

  1.   


    不能在 不是创建该控件的线程中 访问该控件void OnMessage(_WP.IncomingMessage msg, string text)
      {
          txtRead.BeginInvoke(delegate(){txtRead.Text=text;});     //txtRead.Text = text;//Console.write(text);
      }
      

  2.   

    txtRead.BeginInvoke(delegate(){txtRead.Text=text;});
    good
      

  3.   

    从USB数据线(UART)拿数据,用consoleapplication已经可以工作了,可以换去windowapplication吗?
    using System;
    using System.IO;
    using System.Text;
    using System.Collections;
    using System.Reflection;
    using System.Threading;
    using System.Diagnostics;using _DBG = Microsoft.SPOT.Debugger;
    using _WP = Microsoft.SPOT.Debugger.WireProtocol;namespace Microsoft.SPOT.Tools
    {
        class SerialDump
        {
            _DBG.Engine m_eng;
            bool m_fUsb = true;
              SerialDump() //连接USB
            {
                _DBG.PortDefinition pd = null;
                string port = null;
                if (m_fUsb)
                {
                    _DBG.PortDefinition[] ports = _DBG.AsyncUsbStream.EnumeratePorts();                if (port == null)
                    {
                        if (ports.Length == 0)
                        {
                            System.Console.WriteLine("No Usb SPOT device is present");                        throw new ApplicationException();
                        }
                        else if (ports.Length == 1)
                        {
                            pd = ports[0];
                        }
                        else
                        {
                            System.Console.WriteLine("More than one USB SPOT device is present");
                            System.Console.WriteLine("To dump data from a specific device, choose your device from the list below and execute:");
                            System.Console.WriteLine("  serialdump -usb <device> ");
                            System.Console.WriteLine("");                        //
                            // More than one usb device attached; dump list so user can choose
                            //
                            for (int i = 0; i < ports.Length; ++i)
                            {
                                System.Console.WriteLine("Device " + i + ": " + ports[i].DisplayName);
                            }                        throw new ApplicationException();
                        }
                    }
                    else
                    {
                        foreach (_DBG.PortDefinition pd2 in ports)
                        {
                            if (port.Equals(pd2.DisplayName))
                            {
                                pd = pd2;
                                break;
                            }
                        }
                    }
                }                        m_eng = new _DBG.Engine(pd);//link
            }
    //提取数据 下面的codewindowapplication要怎么改?
            void Run()
            {
               m_eng.Start();         
                m_eng.OnMessage += new _DBG.MessageEventHandler(OnMessage);            Console.WriteLine("####### PRESS RETURN TO EXIT #######");
                Console.ReadLine();            m_eng.Stop();
                m_eng = null;
            }
     void OnMessage(_WP.IncomingMessage msg, string text)
            {
             console.write(text);// 显示数据
            }
     static void Main(string[] args)
            {
                try
                {
                    SerialDump o = new SerialDump();                o.Run();//WINDOWN application 也可以这样吗?
                }
                catch (ApplicationException)
                {
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0}", e.ToString());
                }
            }
      

  4.   

     Console只能在控制台使用,换成windowapplication的话,看你要显示在什么地方了。
      

  5.   

    MessageBox.Show( " ");  
    Debug.Write