Welcome! Log In Create A New Profile

Advanced

Python Checksum Implementation

Posted by CharlesDesign 
Python Checksum Implementation
August 09, 2018 06:45AM
Hi All,

I'm writing a custom host using pySerial.

I'm not familiar with the checksum algorithm, can someone provide me with either a pseudo code or a snippet?

Many thanks,
Charles

Edited 1 time(s). Last edit at 08/09/2018 06:45AM by CharlesDesign.
Re: Python Checksum Implementation
August 09, 2018 07:15AM
still haven't learnt how to google huh?
Re: Python Checksum Implementation
August 09, 2018 07:24AM
Be my guest and find a Python implementation of the Marlin checksum on the host side.

Printcore is the only implementation I've found but I've not managed to extract the essence of the checksum function.

Edited 1 time(s). Last edit at 08/09/2018 07:25AM by CharlesDesign.
Re: Python Checksum Implementation
August 09, 2018 07:48AM
You didnt look very hard...

The definition [reprap.org]

code is there in C, really easy to understand

and from printcore.py
def _checksum(self, command):
        return reduce(lambda x, y: x ^ y, map(ord, command))

eg of where its used
            prefix = "N" + str(lineno) + " " + command
            command = prefix + "*" + str(self._checksum(prefix))

Edited 1 time(s). Last edit at 08/09/2018 07:50AM by Dust.
Re: Python Checksum Implementation
August 09, 2018 08:18AM
Thanks for sharing Dust, my assumption of the checksum is as follow:

1. Set line number to zero -> M110 N0
2. Send command in the following format: [N(line number) (Gcode command) *(output of checksum function)]
----Input to checksum function is simply [N(line number) (Gcode command)]
3. If 'ok' is recieved then send next line, if 'rs' is received then try sending line again

Is this correct?

What's a reasonable amount of times to try? What's to be done after?

Edited 1 time(s). Last edit at 08/09/2018 08:18AM by CharlesDesign.
Re: Python Checksum Implementation
August 09, 2018 08:35AM
basically yes

but there are a bunch more possible responses see [reprap.org]

Number of retries is up to you...
Re: Python Checksum Implementation
August 10, 2018 04:18AM
Many thanks Dust.

Could you explain what exactly Gcoder.py does?
Re: Python Checksum Implementation
August 10, 2018 05:00AM
It simulates in memory a print of the gcode, displays the dimensions, layers, how much filament is used and estimated print time.
Sorry, only registered users may post in this forum.

Click here to login