New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No possible way to set dtr and rts state during method open. #729
Comments
In the above code, where you set the ser.dtr etc, when I look at the output of the DTR and RTS pins on a max connected to a CH340 USB to serial device, I still see the DTR and RTS go high for 20 ms when the port opens before they get forced low. So the problem might be bigger than just missing in the open function call. |
Try a second time - I notice the first call when you reboot your PC (or connect a new device) does that. From then on, it behaves. I notice the code for mpremote and pyboard on micropython already implements the same workaround when they detect windows (with a comment about ES32 and ESP8266 RTS issues), so it appears to also have solved the problem for other people on other devices as well. On a philosophical topic instead now though: since there does exist dtr and rts state-setting "methods", it does seem to be an obvious oversight that someone forgot to allow those to be set inside the constructor. The code which opens the port has to make a decision about whether "high" or "low" should be the initial state for those pins - but without any way for us to tell it. |
I get what you are saying about constructor has to choose something. I'm looking at the posix code that is used on mac, linux, unix. I'm not how different the windows is as I don't have an easy way to test that. I could be wrong but it looks like the code has to open a socket, then it can call an ioctl on that socket to set the values of RTS / DTR. As soon as the sockets opens, the lines seem to go high. I can't see any way of setting them before the open call. The ioctl can then set them low or high. When the socket is closed, it looks like the default behavior is to set them low but it might be the case that if the "HUPCL" ( no hangup on close ) options is set correctly that they can stay high after the socket closes. This would keep them from going low again when the device gets opened again. I know on the ESP32, most people use a two transistor circuit for this. You can see it in the thread on https://forum.micropython.org/viewtopic.php?t=4607 Anyways, just poking around on this and trying to sort it out and I hope there is some way to control the RTS and DTR when the open happens but no idea what it is. |
I'm in Ubuntu under WSL1 on Windows, so I wonder if my experience is different to plain linux ? Can you explain what you mean by "socket" ? (Did you mean "Device" instead?). Here's what perplexity thinks: https://www.perplexity.ai/search/C-code-in-4ELrwOKlQ1yLK42leua5Dw?s=c |
This works, and properly sets the pin state:-
However, the below does not work, and is the closest possible method doing the same as the above, except, it does not allow any users to set dtr/rts state (both default to 1 on windows, which generates unwanted MCU resets when trying to connect to arduino/esp32/etc devices)
ser = serial.Serial('/dev/ttyS9', baudrate=115200, interCharTimeout=1, rtscts=0, dsrdtr=0) # fails (sets pins unwantedly)
The above method needs to add "dtr" and "rts" kwargs to allow users to specify the initial state for those pins.
The text was updated successfully, but these errors were encountered: