1. <small id='7T13H'></small><noframes id='7T13H'>

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

      • <bdo id='7T13H'></bdo><ul id='7T13H'></ul>

      Arduino 的 Pyserial 问题 - 适用于 Python shell 但不适用于程序

      时间:2023-07-23
          <tbody id='2jYEt'></tbody>

          <legend id='2jYEt'><style id='2jYEt'><dir id='2jYEt'><q id='2jYEt'></q></dir></style></legend>

              <bdo id='2jYEt'></bdo><ul id='2jYEt'></ul>

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

              1. <small id='2jYEt'></small><noframes id='2jYEt'>

                本文介绍了Arduino 的 Pyserial 问题 - 适用于 Python shell 但不适用于程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                好的,所以我很肯定我的 Arduino 电路和它的代码是正确的.我知道这一点,因为当我使用 Arduino IDE 中内置的串行监视器并发送H"时,LED 会亮起,而当我发送L"时,LED 会关闭.

                All right, so I am positive my Arduino circuit is correct and the code for it. I know this because when I use the serial monitor built into the Arduino IDE and send 'H' an LED lights up, when I send 'L' that LED turns off.

                现在我做了一个 Python 程序

                Now I made a Python program

                import serial
                ser = serial.Serial("COM4",9600)
                ser.write("H")
                

                当我运行代码时,LED 会闪烁一秒钟然后又熄灭.但是,当我在 shell 中分别执行这些行时,它的工作原理就像它应该做的那样.

                When I run the code the LED blinks on for a second then goes back off. However when I do each of these lines separately in the shell it works just like it is supposed to.

                有什么想法吗?

                推荐答案

                当你打开串口时,这会导致 Arduino 重置.由于 Arduino 需要一些时间来启动,所有输入都进入 bitbucket(或者可能进入引导加载程序,上帝知道它会做什么).如果你插入一个睡眠,你等待 Arduino 出现所以你的序列号.这就是它以交互方式工作的原因;您正在等待软件启动所需的 1.5 秒.

                When you open the serial port, this causes the Arduino to reset. Since the Arduino takes some time to bootup, all the input goes to the bitbucket (or probably to the bootloader which does god knows what with it). If you insert a sleep, you wait for the Arduino to come up so your serial code. This is why it works interactively; you were waiting the 1.5 seconds needed for the software to come up.

                我确认打开串口会重置我的Arduino Uno;我闪烁了一个程序,该程序将使 setup() 例程中的 LED 闪烁——调用 open("/dev/ttyACM0") 足以触发重置.恕我直言,这是串行支持中令人困惑且未记录的问题.

                I confirmed that opening the serial port resets my Arduino Uno; I flashed a program which will blink the LED from the setup() routine -- calling open("/dev/ttyACM0") was sufficient to trigger the reset. This is IMHO a confusing and undocumented wrinkle in the serial support.

                这篇关于Arduino 的 Pyserial 问题 - 适用于 Python shell 但不适用于程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:PySerial:如何在串行线上发送 Ctrl-C 命令 下一篇:Python中枚举串口(包括虚拟端口)的跨平台方法是什么?

                相关文章

                <tfoot id='HYNWy'></tfoot>

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

                1. <small id='HYNWy'></small><noframes id='HYNWy'>

                    • <bdo id='HYNWy'></bdo><ul id='HYNWy'></ul>