Mar 22, 2018 - Serial(port='COM13', baudrate=9600) as s: # open serial port print('Read. Then I run my Python test script that I posted in the first post here,.
How would I go about viewing a list of COM ports in use without the use of Device Manager?
I don't want to install any software either. Is there a possible way to do this through the command line?
MarmstrongMarmstrong
7 Answers
In the command prompt use
mode
Used without parameters,
mode
displays all the controllable attributes of the CON
(console) and the available COM
devices (and LPT
as well). Accepts
/?
switch for basic help: mode /?
JosefZJosefZ
In the command prompt use:
OR
In PowerShell:
OR
Hope this helps.
vembutechvembutech
I know the question has been answered, but this is another method.
In command prompt, use:
in windows Vista and up. Lists your ports and which device they are.
chgport
in windows Vista and up. Lists your ports and which device they are.
Thomas LarsenThomas Larsen
Using
mode
most of the time I don't see the devices that are not connected. I prefer to use this solution with Python:
So I can see anything plugged in even if the connection is closed.
serial.tools.list_ports is from package pyserial.
G MG M
wmic https://docs.microsoft.com/en-us/windows/desktop/wmisdk/wmic is a windows command line utility to get system information.
If your serial port is virtual created by some driver through USB connection, use this example to get details about these serial ports.
GLamprosGLampros
The snippet below lists serial ports into the $PORTS variable
PORTS=
/c/Windows/System32/mode.com | grep Status.*COM | awk '{ print $4 }' | sed s/://
echo -n 'Programming (echoing) ports: 'for aa in $PORTS; do echo -n $aadoneecho '
Peter GlenPeter Glen
You can also run the following from cmd.exe prompt
And here is an open source utility to do the same and more:https://todbot.com/blog/2012/03/02/listcomports-windows-command-line-tool-for-usb-to-serial/
![Python Check Serial Port Available Python Check Serial Port Available](http://archive.fabacademy.org/archives/2017/fablabspinderihallerne/students/63/pictures/week16/python_720x450.jpg)
lithiumheadlithiumhead
protected by Community♦Feb 2 at 20:37
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?
Not the answer you're looking for? Browse other questions tagged command-lineserial-portcom-port or ask your own question.
I am using a script in Python to collect data from a PIC microcontroller via serial port at 2Mbps.
The PIC works with perfect timing at 2Mbps, also the FTDI usb-serial port works great at 2Mbps (both verified with oscilloscope)
Im sending messages (size of about 15 chars) about 100-150x times a second and the number there increments (to check if i have messages being lost and so on)
On my laptop I have Xubuntu running as virtual machine, I can read the serial port via Putty and via my script (python 2.7 and pySerial)
The problem:
- When opening the serial port via Putty I see all messages (the counter in the message increments 1 by 1). Perfect!
- When opening the serial port via pySerial I see all messages but instead of receiving 100-150x per second i receive them at about 5 per second (still the message increments 1 by 1) but they are probably stored in some buffer as when I power off the PIC, i can go to the kitchen and come back and im still receiving messages.
Here is the code (I omitted most part of the code, but the loop is the same):
Anyone knows why pySerial takes so much time to read from the serial port till the end of the line?Any help?
I want to have this in real time.
Thank you
Vasco BaptistaVasco Baptista
3 Answers
You can use
inWaiting()
to get the amount of bytes available at the input queue.Then you can use
read()
to read the bytes, something like that:Why not to use
readline()
at this case from Docs:You are waiting for the timeout at each reading since it waits for eol. the serial input Q remains the same it just a lot of time to get to the 'end' of the buffer, To understand it better: you are writing to the input Q like a race car, and reading like an old car :)
Kobi KKobi K
You need to set the timeout to 'None' when you open the serial port:
This is a blocking command, so you are waiting until you receive data that has newline (n or rn) at the end:line = ser.readline()
Once you have the data, it will return ASAP.
Fabian MeierFabian Meier
From the manual:
Possible values for the parameter timeout: … x set timeout to x seconds
and
readlines(sizehint=None, eol='n') Read a list of lines, until timeout. sizehint is ignored and only present for API compatibility with built-in File objects.
Note that this function only returns on a timeout.
So your
readlines
will return at most every 2 seconds. Use read()
as Tim suggested.mswmsw