crc method for a serial driver for fiscal cash register

MRAB python at mrabarnett.plus.com
Wed Mar 15 18:31:05 EDT 2017


On 2017-03-15 18:18, Bogdan Radu Bolchis wrote:
> hi,
>   i'm developing a Point Of Sale app in python for my company, and we need to integrate the fiscal cash register driver in python. The original driver is only for windows and no longer supported, we want to switch to Linux. We managed to find the serial protocol, but the sent data is followed by a CRC.
>
>   Can someone help me building a CRC function according to the manufacturer data?
>
> Here is what i have:
>
> ALGORITHM FOR CRC CALCULATION
>
> The two CRC bytes are calculated according to the formula x^15 + 1. In the calculation are included all data bytes plus the byte for block end. Every byte passes through the calculation register from teh MSB to LSB.
> Three working bytes are used - S1, S0 and TR
> S1 - Most significant byte from the CRC ( it is transmitted immediatelly after END)
> S0 - Least significant byte from the CRC ( It is transmitted after S1)
> TR - the current transmitted byte in the block.
>
> The CRC is calculated as follows:
> 1. S1 and S0 are zeroed
> 2. TR is loaded with the current transmitted byte. The byte is transmitted.
> 3. Points 3.1 and 3.2 are executed 8 times:
> 3.1. S1, S0 and TR are shifted one bit to the left.
> 3.2. If the carry bit from S1 is 1, the MSB of S1 and LSB of S0 are inverted.
> Points 2 and 3 are executed for all bytes, included in the calculation of the CRC - from the first byte after BEG up to and including byte END.
> 4. TR is loaded with 0 and point 3 is executed
> 5. TR is loaded with 0 and point 3 is executed
> 6. Byte S1 is transmitted
> 7. Byte S0 is transmitted
>
[snip]
Step 3 is a little unclear.

Step 3.1 says to shift TR, but step 3.2 says to check the carry bit 
after shifting S1, which is zero initially, therefore the carry bit will 
be clear, therefore S1 and S0 won't have any bits inverted and will stay 
zero.

In summary, the CRC won't be affected by the data _at all_.

And how about a few examples for checking the algorithm?



More information about the Python-list mailing list