Disable DTR in pyserial from code

前端 未结 4 1509
無奈伤痛
無奈伤痛 2020-12-02 02:13

I\'m trying to use pyserial to send data to an arduino. But when I open the COM port it sets DTR low and resets the board. However, I have my arduino code setup such that I

4条回答
  •  醉梦人生
    2020-12-02 02:26

    The method you describe seems to be the most common fix for this problem that I've seen - so I suspect that there's no simpler software-based solution. You can of course manually change the state of the DTR line using ser.setDTR(level) - however I haven't tried this specifically in the case of the Arduino autoreset, and I suspect that even toggling the line immediately after opening the serial port may not be fast enough to prevent the reset.

    The other options I can see that you have available would be to prevent the autoreset of the Arduino in hardware (see here), or to change your code slightly so that you allow the Arduino to reboot after initially making the serial connection, and then when you manually trigger your serial receive mode send an initial signal from the Arduino to show that it is now ready to receive data. Or alternatively you could include a modified version of the pySerial library with your script.

提交回复
热议问题