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

  2. <small id='yX9CV'></small><noframes id='yX9CV'>

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

      为什么访问com端口被拒绝?

      why is access to com port denied?(为什么访问com端口被拒绝?)
    1. <small id='ZDOZa'></small><noframes id='ZDOZa'>

        <tfoot id='ZDOZa'></tfoot>
          <bdo id='ZDOZa'></bdo><ul id='ZDOZa'></ul>
          <legend id='ZDOZa'><style id='ZDOZa'><dir id='ZDOZa'><q id='ZDOZa'></q></dir></style></legend>

            • <i id='ZDOZa'><tr id='ZDOZa'><dt id='ZDOZa'><q id='ZDOZa'><span id='ZDOZa'><b id='ZDOZa'><form id='ZDOZa'><ins id='ZDOZa'></ins><ul id='ZDOZa'></ul><sub id='ZDOZa'></sub></form><legend id='ZDOZa'></legend><bdo id='ZDOZa'><pre id='ZDOZa'><center id='ZDOZa'></center></pre></bdo></b><th id='ZDOZa'></th></span></q></dt></tr></i><div id='ZDOZa'><tfoot id='ZDOZa'></tfoot><dl id='ZDOZa'><fieldset id='ZDOZa'></fieldset></dl></div>
                <tbody id='ZDOZa'></tbody>

                本文介绍了为什么访问com端口被拒绝?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                代码:

                static void Main(string[] args)
                {
                    Console.WriteLine("Memory mapped file reader started");
                
                    using (var file = MemoryMappedFile.OpenExisting("AIDA64_SensorValues"))
                    {
                        using (var readerz = file.CreateViewAccessor(0, 0))
                        {
                            var bytes = new byte[567];
                            var encoding = Encoding.ASCII;
                            readerz.ReadArray<byte>(0, bytes, 0, bytes.Length);
                
                            File.WriteAllText("C:\myFile.txt", encoding.GetString(bytes));
                
                            var readerSettings = new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Fragment };
                            using (var reader = XmlReader.Create("C:\myFile.txt", readerSettings))
                            {
                                while (reader.Read())
                                {
                                    using (var fragmentReader = reader.ReadSubtree())
                                    {
                                        if (fragmentReader.Read())
                                        {
                
                                            reader.ReadToFollowing("value");
                                            SerialPort port = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
                                            port.Open();
                                            port.Write(reader.ReadElementContentAsString() + ",");
                                        }
                                    }
                                }
                            }    
                        }
                    }
                
                    Console.WriteLine("Press any key to exit ...");
                    Console.ReadLine();
                }
                

                它读取共享内存,将该共享内存写入文件,然后使用 xml 阅读器打开同一个文件并拆分 xml,因为它有多个根,然后在每个新拆分 xml 上获取节点的值并通过串行发送.它在第一个拆分 xml 上工作,它的节点通过串行发送,然后它停止并在尝试将第二个节点写入串行时拒绝访问 com 端口消息.

                it reads shared memory, writes that shared memory to file, then the same file is opened with xml reader and splits xml since it has multiple roots, then gets the value of a node on each new split xml and sends over serial. it works on the first split xml and its node is sent over serial then it stops with a access is denied to com port message on attempt for writing second node to serial.

                我有另一个使用相同序列码制作的应用程序,它运行良好(我只是累了它然后关闭它.)......所以它很奇怪.

                i have another app i made with same serial code and it works fine(i just tired it then closed it.)... so its strange.

                推荐答案

                一个串口只能打开一次.但是您的代码在 while 循环中有 Open() 调用.这仅适用于第一次通过循环,第二次通过 kaboom.@cdhowie 的解决方案也不起作用,SerialPort 有一个文档警告的怪癖(又名错误).在 Dispose() 或 Close() 调用之后让工作线程退出需要时间.时间量未指定且不可预测.

                You can open a serial port only once. But your code has the Open() call inside the while loop. That will only work for the first pass through the loop, kaboom on the 2nd pass. @cdhowie's solution doesn't work either, SerialPort has a quirk (aka bug) that the documentation warns about. It needs time to let a worker thread exit after the Dispose() or Close() call. The amount of time is unspecified and unpredictable.

                真正的解决方案很简单,只需将 Open() 调用移到 while 循环之前.

                The real solution is simple, just move the Open() call before the while loop.

                这篇关于为什么访问com端口被拒绝?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                How to store delegates in a List(如何将代表存储在列表中)
                How delegates work (in the background)?(代表如何工作(在后台)?)
                C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)

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

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

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

                          <tbody id='MG00t'></tbody>

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