Skip to content
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

pyserial 3.4 with Python 2.17.13 under Windows 10 #258

Open
mbarzanti opened this issue Aug 3, 2017 · 8 comments · May be fixed by #669
Open

pyserial 3.4 with Python 2.17.13 under Windows 10 #258

mbarzanti opened this issue Aug 3, 2017 · 8 comments · May be fixed by #669

Comments

@mbarzanti
Copy link

I'm using pyserial 3.4 with Python 2.17.13 under Windows 10.
When open COM5 port, I obtained the following error.
Same source, same pyserial, same python versions, runs correctly under Windows 7 and 8.1

Traceback (most recent call last):
File "NAPOSend1.0.py", line 327, in
r = sendfile(NAPOport, PATHNAME, os.path.getsize(PATHNAME))
File "NAPOSend1.0.py", line 116, in sendfile
ser = Serial('COM5', 115200, timeout=10, writeTimeout=0)
File "build\bdist.win-amd64\egg\serial\serialwin32.py", line 31, in init
File "build\bdist.win-amd64\egg\serial\serialutil.py", line 240, in init
File "build\bdist.win-amd64\egg\serial\serialwin32.py", line 78, in open
File "build\bdist.win-amd64\egg\serial\serialwin32.py", line 222, in _reconfig
ure_port
serial.serialutil.SerialException: Cannot configure port, something went wrong.
Original message: WindowsError(87, 'Incorrect Parameter.')

@BrendanSimon
Copy link
Contributor

There are quite a few people that have this issue. I've googled long and hard but cannot find an answer.

I have a Virtual Com Port installed (COM90 <=> COM91 loopback) and my pyserial (Win10) app can connect ok to it.

I have a real device on COM3, but my serial app wont connect and I get the serial.serialutil.SerialException: Cannot configure port, something went wrong. Original message: WindowsError(87, 'Incorrect Parameter.') exception.

Another program written in C/C++ (Embarcadero aka C++Builder) can connect to COM3 fine.

So what do we make of that? The standard Win 10 Microsoft driver must be OK since the C/C++ app talks to it fine. The only thing that doesn't talk to it is the pyserial app, but the pyserial app works fine with COM90 (which uses a different driver, by the Virtual Com Port provider).

My guess it's something to do with the Python mappings to the Windows system calls, but where ???

@BrendanSimon
Copy link
Contributor

BrendanSimon commented Jun 6, 2018

I've investigated this issue further. The Embarcadero C++ app does work, however when I debug it I can see that the call to SetCommState() fails (returns false), but the code doesn't check the return code and keeps on going as if everything is ok (and I guess it is in some respects because the comms works).

So I edited the pySerial source to not raise an exception if SetCommState() returns False and now I can talk to my device using pySerial. YAY !!! :)

So the question is why does SetCommState() fail with an ERROR_INVALID_PARAMETER. All the parameters passed in the DCB structure seem correct/valid to me.

Either it's bug in the Microsoft driver on Win 10, or maybe it's something to do with the USB descriptor/configuration info which the driver uses to check what parameters can be set?

@BrendanSimon
Copy link
Contributor

OK. So it looks like the Win 10 CDC drivers are more thorough and more fussy than Win 7 (and prior presumably).

I was using an STM32 controller with in-built USB peripheral and the ST provided driver software, and the driver software does not return the correct comm parameter settings after they have been set (i.e. they are set to 115200, 8, N, 1 but do not reply with same values when read back).

I made a change so that the set values are cached and the same values returned when reading them back and SetCommState() no longer returns an error on Win 10, and thus PySerial does not raise an exception and my app is happy. :)

You may find a similar solution for your issue @mbarzanti ?

For my situation I can't fix the problem in the devices that are already out in customers hands (the bootloader firmware is not field upgradeable) so am going to start a new issue with a couple of PySerial modification proposals.

@BrendanSimon
Copy link
Contributor

I opened #362 to discuss or get some advice on changes to PySerial to work better with Windows 10.

@pengshulin
Copy link

pengshulin commented Apr 16, 2020

"caches the set values" sounds a good idea. Thanks a lot, I'll try it.
I tried, it really works.

@sane-tanmay
Copy link

@BrendanSimon How can I cache these set values ?

@HarithaSeddik
Copy link

@BrendanSimon How can I cache these set values ?

If you found out how please do not hesitate to share

@pengshulin
Copy link

I meant the device firmware response to USB-CDC Control request from PC: it needs to cache LINECODING settings (baud rate/format/parity/data bits), or PC may suggest "the device has some error" and pyserial will raise exception in windows. I guess WINDOWS may write and readback and compare the settings and I did not found that problem in Ubuntu.
I modified my firmware to confirm the difference (test in stm32f4/CDC chip).

@foldl foldl linked a pull request Oct 14, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants