<bdo id='fZ571'></bdo><ul id='fZ571'></ul>

      <tfoot id='fZ571'></tfoot>
      1. <i id='fZ571'><tr id='fZ571'><dt id='fZ571'><q id='fZ571'><span id='fZ571'><b id='fZ571'><form id='fZ571'><ins id='fZ571'></ins><ul id='fZ571'></ul><sub id='fZ571'></sub></form><legend id='fZ571'></legend><bdo id='fZ571'><pre id='fZ571'><center id='fZ571'></center></pre></bdo></b><th id='fZ571'></th></span></q></dt></tr></i><div id='fZ571'><tfoot id='fZ571'></tfoot><dl id='fZ571'><fieldset id='fZ571'></fieldset></dl></div>
      2. <small id='fZ571'></small><noframes id='fZ571'>

        <legend id='fZ571'><style id='fZ571'><dir id='fZ571'><q id='fZ571'></q></dir></style></legend>

        COM 端口无法打开 Unity

        时间:2023-11-10
        1. <i id='Gwvgc'><tr id='Gwvgc'><dt id='Gwvgc'><q id='Gwvgc'><span id='Gwvgc'><b id='Gwvgc'><form id='Gwvgc'><ins id='Gwvgc'></ins><ul id='Gwvgc'></ul><sub id='Gwvgc'></sub></form><legend id='Gwvgc'></legend><bdo id='Gwvgc'><pre id='Gwvgc'><center id='Gwvgc'></center></pre></bdo></b><th id='Gwvgc'></th></span></q></dt></tr></i><div id='Gwvgc'><tfoot id='Gwvgc'></tfoot><dl id='Gwvgc'><fieldset id='Gwvgc'></fieldset></dl></div>
        2. <legend id='Gwvgc'><style id='Gwvgc'><dir id='Gwvgc'><q id='Gwvgc'></q></dir></style></legend><tfoot id='Gwvgc'></tfoot>

            <small id='Gwvgc'></small><noframes id='Gwvgc'>

                <bdo id='Gwvgc'></bdo><ul id='Gwvgc'></ul>
                    <tbody id='Gwvgc'></tbody>
                  本文介绍了COM 端口无法打开 Unity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 arduino 板将串行数据传送到 Unity.我使用电路板附带的读取模拟电压样本和调试日志中愉快地显示的输出进行了这项工作.

                  但是,现在当我运行 Unity 时,出现以下错误:

                  <块引用>

                  IOException:端口COM11"不存在.

                  我已将我的 COM 端口更改为各种数字,但它们都返回相同的错误.

                  我的串口读取代码是这样的:

                  SerialPort 流 = null;字符串数据=准备好";私有浮点数据定时器 = 2.0f;私人浮动 TimeToCheckStream = 0.1f;//每秒检查一次数据公共字符串 COMPort = "";公共 int 波特率 = 9600;无效唤醒(){流 = 新串行端口(COMPort,波特率);//原来是9600Debug.Log("初始化流");LogWriter writer = LogWriter.Instance;writer.WriteToLog(COMPort);}无效开始(){//LogWriter writer = LogWriter.Instance;//writer.WriteToLog("测试测试");如果(流!= null){if (stream.IsOpen)//如果已经打开则关闭{流.关闭();Debug.Log("关闭的流");}流.打开();Debug.Log("打开的流");}别的{Debug.Log("错误:未初始化的流");}}无效更新(){if(DataTimer < TimeToCheckStream){DataTimer += Time.deltaTime;}别的{数据定时器 = 0.0f;如果(流!= null){如果(流.IsOpen){//如果流是打开的,请在此处执行操作流.ReadLine();Debug.Log(stream.ReadLine().ToString());}}别的{Debug.Log("NULL 流");}}}无效的 OnGUI (){GUI.Label(新矩形(500,10,300,100),数据);}无效 OnApplicationQuit (){如果(流!= null){流.关闭();}}

                  我的 COM 端口突然决定自行关闭有什么原因吗?

                  解决方案

                  您可以访问您的 COM11 并将其替换为 \.COM11你必须写:

                  myPort=new SerialPort("\\.\COM11",9600);

                  看看 微软网站 p>

                  I'm using an arduino board to communicate serial data into Unity. I had this working using the read analog voltage sample that comes with the board and the output from that happily displayed in the debug log.

                  However, now when I run Unity i get the following error:

                  IOException: The port `COM11' does not exist.

                  I've changed my COM port to be a variety of numbers but they all come back with the same error.

                  My serial port reading code is thus:

                  SerialPort stream = null;
                  string data = "Ready";
                  
                  
                  private float DataTimer = 2.0f;
                  private float TimeToCheckStream = 0.1f; // check data every second
                  public string COMPort = "";
                  public int baudRate = 9600;
                  
                  
                  
                  void Awake ()
                  {       
                  
                      stream = new SerialPort(COMPort,baudRate); //originally 9600
                      Debug.Log ("Initialized stream");
                  
                      LogWriter writer = LogWriter.Instance;
                      writer.WriteToLog( COMPort);
                  }
                  
                  
                  
                  void Start ()
                  {
                  //  LogWriter writer = LogWriter.Instance;
                  //  writer.WriteToLog("Testing test");
                  
                          if ( stream != null )
                          {
                              if ( stream.IsOpen ) // close if already open
                              {
                                  stream.Close();
                                  Debug.Log ("Closed stream");
                              }
                  
                              stream.Open();
                              Debug.Log ("Opened stream");
                          }
                  
                          else
                          {
                              Debug.Log ("ERROR: Uninitialized stream");
                          }
                  
                  }
                  
                  
                  void Update ()
                  {
                  
                      if(DataTimer < TimeToCheckStream) 
                      {
                          DataTimer += Time.deltaTime;
                      } 
                      else
                      {
                          DataTimer = 0.0f;
                  
                          if ( stream != null )
                          {
                              if ( stream.IsOpen )
                              {
                                  // if stream is open do things in here
                                  stream.ReadLine();
                                  Debug.Log(stream.ReadLine().ToString());
                              }
                          }
                  
                          else
                          {
                              Debug.Log ("NULL stream");
                          }
                      }
                  }
                  
                  
                  
                  void OnGUI ()
                  {
                      GUI.Label ( new Rect(500,10,300,100), data );
                  }
                  
                  
                  
                  void OnApplicationQuit ()
                  {       
                  
                      if ( stream != null )
                      {
                          stream.Close();
                      }
                  }
                  

                  Is there any reason as to why my COM port would suddenly decide to close itself?

                  解决方案

                  You can access your COM11 with replacing it with \.COM11 You must write:

                  myPort= new SerialPort("\\.\COM11",9600);
                  

                  Take a look at Microsoft's Website

                  这篇关于COM 端口无法打开 Unity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:数据在通过串行端口传输期间损坏 下一篇:RtsEnable 或 DtrEnable 属性是否发送信号?

                  相关文章

                    <small id='DYiG4'></small><noframes id='DYiG4'>

                        <bdo id='DYiG4'></bdo><ul id='DYiG4'></ul>
                    1. <i id='DYiG4'><tr id='DYiG4'><dt id='DYiG4'><q id='DYiG4'><span id='DYiG4'><b id='DYiG4'><form id='DYiG4'><ins id='DYiG4'></ins><ul id='DYiG4'></ul><sub id='DYiG4'></sub></form><legend id='DYiG4'></legend><bdo id='DYiG4'><pre id='DYiG4'><center id='DYiG4'></center></pre></bdo></b><th id='DYiG4'></th></span></q></dt></tr></i><div id='DYiG4'><tfoot id='DYiG4'></tfoot><dl id='DYiG4'><fieldset id='DYiG4'></fieldset></dl></div>
                    2. <legend id='DYiG4'><style id='DYiG4'><dir id='DYiG4'><q id='DYiG4'></q></dir></style></legend>

                      <tfoot id='DYiG4'></tfoot>