From fe6d7499eb5e0920419829371c0e11f9af000499 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 30 Jun 2023 13:39:06 +0200 Subject: [PATCH] Disable DTR clearing on 1200-bps touch (only on Windows) (#2234) The reason why it was originally introduced: https://github.com/arduino/Arduino/pull/2709/commits/a6909bdb49d99253b4e684365e72e5dce31a49a7 Why we are removing it now? * Windows does preserve the state of the RTS/DTR bits on successive opening of the serial port. * The serial library used in the Arduino IDE 1.8.x has a bug when trying to set DTR=false, on successive opening of the port the DTR line is set back high by the USB serial driver. This works differently from the serial library we use in the Arduino CLI, that sets DTR=false for good and this change is preserved on the successive opening of the port. * Having the serial port left in a state with DTR=false may cause problems to tools uploading later. It may probably completely removed, but for now, to reduce the testing surface, it will be disabled only for Windows. --- arduino/serialutils/serialutils.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arduino/serialutils/serialutils.go b/arduino/serialutils/serialutils.go index dfb5bfe112d..7c6bac6ea98 100644 --- a/arduino/serialutils/serialutils.go +++ b/arduino/serialutils/serialutils.go @@ -17,6 +17,7 @@ package serialutils import ( "fmt" + "runtime" "strings" "time" @@ -37,10 +38,15 @@ func TouchSerialPortAt1200bps(port string) error { return errors.WithMessage(err, tr("opening port at 1200bps")) } - // Set DTR to false - if err = p.SetDTR(false); err != nil { - p.Close() - return errors.WithMessage(err, tr("setting DTR to OFF")) + if runtime.GOOS != "windows" { + // This is not required on Windows + // TODO: Investigate if it can be removed for other OS too + + // Set DTR to false + if err = p.SetDTR(false); err != nil { + p.Close() + return errors.WithMessage(err, tr("setting DTR to OFF")) + } } // Close serial port