robhagemans / pcbasic

PC-BASIC - A free, cross-platform emulator for the GW-BASIC family of interpreters
http://www.pc-basic.org
Other
396 stars 48 forks source link

Problem opening COM port: Not a valid parity b'N' #152

Closed Danitegue closed 2 years ago

Danitegue commented 2 years ago

Hello again Rob, I found this bug while trying the Brewer instrument software with your latest pip installed pcbasic version for python 3.x.

The launcher line I'm using is this one: Brewer C:\brw#072\Prog410>C:\Python38-32\python.exe -m pcbasic --interface=sdl2 --mount=Z:.,C:C:\,D: --current-device=Z --com1=PORT:COM14 --com2=stdio: --run=main.asc --quit=False -f=10 --shell="python C:\PCBREWER\Brw_functions.py" --debug=True --logfile=C:\Temp\pcbasic_brewer_log_072_20211029T205249Z.txt

PC-BASIC crash log

FATAL ERROR version 2.0.3 [v2.0.2-1-820-g6807f35bb 2020-09-26 16:10:49.837131] python 3.8.10 [32bit WindowsPE] platform Windows-10-10.0.19043-SP0 interface VideoSDL2, AudioSDL2 statement 9082 IF A$<>"p" THEN OPEN "com"+CP$+COMBR$+COMSET$ AS 7

files.py:94, open ports.py:70, open ports.py:261, set_params serialutil.py:336, parity ValueError: Not a valid parity: b'N'

This is a bug in PC-BASIC. Sorry about that. You can help improve PC-BASIC:

let me know if the full 48MB crash file is useful here, but I think this info is enough to find the bug

Best regards.

Marrin commented 2 years ago

PC-Basic's COMDevice._parse_params() arbeitet mit bytes, die Serial-API will da aber Zeichenketten (str) haben.

rbergen commented 2 years ago

What were the values of CP$, COMBR$ and COMSET$ when the error occurred?

Danitegue commented 2 years ago

b'CP$': b'$'[b'01adf6' b'1'] b'COMBR$': b'$'[b'05cc24' b':1200'] b'COMSET$': b'$'[b'12b024' b',n,8,1,rs,ds,cs,cd']

Danitegue commented 2 years ago

One possible solution I have found, is simply replace the line 104 of ports.py, function _parse_params():

from: parity = parity or b'E' to: parity = parity.decode('utf8') or 'E'

robhagemans commented 2 years ago

@Danitegue Thanks, that's consistent with what @Marrin suggested, that the issue is that PC-BASIC uses bytes here while serial uses str. Probably a hangover from the port to Python 3. I think it's OK as a workaround but the correct thing to do would probably be to change the internal parameter type in its entirety to use 'E' etc. without prefix, so that it uses bytes in Python 2 and str in Python 3.

I need to check what it does in Python 2, while that's now end-of-lifed I have maintained compatibility with both versions so far; it'll definitely be dropped in 2.1 but it seems harsh to drop Python 2 support randomly now.

Danitegue commented 2 years ago

Hello Rob, I have created a pull request, with this problem solved: https://github.com/robhagemans/pcbasic/pull/153

robhagemans commented 2 years ago

This is a duplicate of #125, resolved on develop branch.