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

Python3 fixes #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Python3 fixes #11

wants to merge 2 commits into from

Conversation

timstr
Copy link

@timstr timstr commented May 15, 2024

Convert the code to run as Python3, since Python2 has been unsupported for over 4 years.

Most of the fixes involve serial.Serial.read and struct.pack now returning a bytes object instead of a string. I've tested a few of the commands on my GMC-500+ and in a Python3 interpreter with the -b flag which additionally warns about comparing str to bytes (an easy pitfall otherwise).

I also went ahead and simplified many cases of e.g.:

if s == '' and len(s) < 7:

to just:

if len(s) < 7:

I have not tested all the available commands, but I can confirm that reading data off the device and into a CSV file is working. I do notice some artifacts at the tail end of the flash memory dump, there's a long run of CPS=255 which I assume is from a parsing error. I don't know if this behaviour is present before these Python3 fixes.

Copy link
Owner

@chaim-zax chaim-zax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look fine, only one question (see remarks). Thanks!

@@ -40,7 +40,7 @@
DEFAULT_CONFIGURATION_SIZE = 0x100 # 256 byte
DEFAULT_VERBOSE_LEVEL = 2

EOL = '\n'
EOL = b'\n'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This symbol doesn't seem to be in use now, why change it?

break

value = print_data(f_out, data_type, data, size=2,
cpm_to_usievert=cpm_to_usievert)
f_out.write(value + EOL)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous remark on line 43.

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 this pull request may close these issues.

None yet

2 participants