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

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

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

        无法在 Windows 10 IoT 中使用 SerialDevice.ReadTimeout

        Unable to use SerialDevice.ReadTimeout in Windows 10 IoT(无法在 Windows 10 IoT 中使用 SerialDevice.ReadTimeout)
      2. <i id='Migqz'><tr id='Migqz'><dt id='Migqz'><q id='Migqz'><span id='Migqz'><b id='Migqz'><form id='Migqz'><ins id='Migqz'></ins><ul id='Migqz'></ul><sub id='Migqz'></sub></form><legend id='Migqz'></legend><bdo id='Migqz'><pre id='Migqz'><center id='Migqz'></center></pre></bdo></b><th id='Migqz'></th></span></q></dt></tr></i><div id='Migqz'><tfoot id='Migqz'></tfoot><dl id='Migqz'><fieldset id='Migqz'></fieldset></dl></div>

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

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

                  <tbody id='Migqz'></tbody>
                  本文介绍了无法在 Windows 10 IoT 中使用 SerialDevice.ReadTimeout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 Raspberry Pi 2 上的 Windows 10 IoT 上实现 ModBus 主控.我正在使用外部 USB 转 RS-232 适配器,因为内部串行端口是为内核调试保留的.

                  I'm trying to implement a ModBus master on Windows 10 IoT on a Raspberry Pi 2. I'm using an external USB to RS-232 adapter since the internal serial port is reserved for Kernel Debugging.

                  串行端口正在工作.我的问题主要是关于阅读时的超时.

                  Serial port is working. My question is mainly about timeout when reading.

                  这是我的代码:

                  // Initialization
                  serialDevice.ReadTimeout = new TimeSpan(0, 0, 0, allowedTimeBetweenBytes);
                  serialDataReader.InputStreamOptions = InputStreamOptions.Partial;
                  
                  // Reading
                  uint bytesRead = await serialDataReader.LoadAsync(MaxBufferSize); // 256
                  // Now use ReadBytes to get actual bytes
                  

                  由于串行端口 RX 输入上没有可用的字节,我希望 LoadAsync 方法在等待后返回 0.不幸的是,它永远不会回来.(好吧,它确实在收到 256 个字节后返回,但这不是我想要的)

                  With no bytes awailable at the serial port RX input, I'm expecting the LoadAsync method to return 0 after wait. Unfortunately, it never returns. (Ok, it DOES return after 256 bytes are received, but that is not what I want)

                  由于 ModBus 大量使用超时,我不知道如何实现它.我什至不确定我能做到...

                  Since ModBus intensively uses timeouts, I am not sure how to implement it. I am not even sure I could do it...

                  是否有人已经在 Windows 10 IoT 串行端口上使用了超时功能?

                  Does anyone already used timeouts on Windows 10 IoT serial ports?

                  推荐答案

                  是的,我也无法正常工作.我不确定 SerialDevice 类在内部实际使用了 ReadTimeout 的位置.但我确实通过将超时复制到 CancellationTokenSource 最终得到了一些工作.

                  Yeah, I couldn't get this working either. I'm not sure where ReadTimeout is actually used by the SerialDevice class internally. But I did end up getting something working by copying the timeout to a CancellationTokenSource.

                  您可以在以下示例中看到它的使用情况,我为旧系列 Mettler Toledo PS 60 运输秤编写,其中 deviceSerialDevice.至少在我的情况下似乎有效.

                  You can see it in use in the following example I wrote for an old serial Mettler Toledo PS 60 shipping scale, where device is an instance of SerialDevice. Seems to work in my case, at least.

                  using (var writer = new DataWriter(device.OutputStream))
                  {
                      writer.WriteString("W
                  ");
                  
                      using (var cts = new CancellationTokenSource(device.WriteTimeout))
                      {
                          await writer.StoreAsync().AsTask(cts.Token);
                      }
                  
                      writer.DetachStream();
                  }
                  
                  using (var reader = new DataReader(device.InputStream))
                  {
                      using (var cts = new CancellationTokenSource(device.ReadTimeout))
                      {
                          var read = await reader.LoadAsync(12).AsTask(cts.Token);
                  
                          if (read >= 12)
                          {
                              var data = reader.ReadString(12);
                              reader.DetachStream();
                  
                              return ExtractWeightChangedEventArgs(data);
                          }
                      }
                  }
                  

                  这篇关于无法在 Windows 10 IoT 中使用 SerialDevice.ReadTimeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='1GKA3'></tfoot>
                  2. <i id='1GKA3'><tr id='1GKA3'><dt id='1GKA3'><q id='1GKA3'><span id='1GKA3'><b id='1GKA3'><form id='1GKA3'><ins id='1GKA3'></ins><ul id='1GKA3'></ul><sub id='1GKA3'></sub></form><legend id='1GKA3'></legend><bdo id='1GKA3'><pre id='1GKA3'><center id='1GKA3'></center></pre></bdo></b><th id='1GKA3'></th></span></q></dt></tr></i><div id='1GKA3'><tfoot id='1GKA3'></tfoot><dl id='1GKA3'><fieldset id='1GKA3'></fieldset></dl></div>
                      <legend id='1GKA3'><style id='1GKA3'><dir id='1GKA3'><q id='1GKA3'></q></dir></style></legend>

                          <tbody id='1GKA3'></tbody>

                            <bdo id='1GKA3'></bdo><ul id='1GKA3'></ul>

                            <small id='1GKA3'></small><noframes id='1GKA3'>