Comments (4)
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.
from pyserial.
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'm using WSL1 on Windows 10N on a RoG laptop, and CH340USB ESP32CAM - the above fix solved all my rebooting and lockup problems.
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.
from pyserial.
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.
from pyserial.
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
from pyserial.
Related Issues (20)
- arduino serial communication strange problem HOT 1
- readinto performance
- ttyS0 gets filtered out of list_ports.comports() despite being a valid port on Raspberry Pi 4 HOT 1
- serial.serialutil.PortNotOpenError: Attempting to use a port that is not open
- RS485 POSIX ioctl flags are never cleared
- Import of imp breaks with Python 3.12 HOT 3
- multiple opening
- Update stable version in repo
- Windows fatal exception: stack overflow on serial.Serial with JLink CDC
- self.readline() not respecting self.timeout
- DTR and RST set at different times
- Loopback in less than 1ms HOT 1
- PySerial only working from interactive python, not from script in windows HOT 2
- pyserial stuck HOT 2
- TX stops after a few bytes - unless port is being read elsewhere HOT 3
- USB CDC/ACM: hangs on non implemented optional class-specific request codes in Win10 HOT 2
- Python 12 on windows no module named imp
- PySerial removing/adding bytes randomly
- Write method cause gap between bytes on Mac os HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyserial.