ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

4-Bit CRC Algorithm Conversion

Solved!
Go to solution

Hello,

 

I am very new to programming in LabVIEW and have been tasked with writing an algorithm in LabView2019 that uses the polynomial 0x13 (x^4+x^1+1). I have tried to duplicate the algorithm from https://forums.ni.com/t5/LabVIEW/Computing-CRC/m-p/825331/highlight/true#M375052 but substituting my data without success.

 

Could someone please help me convert the following code from Python, I have been stuck on this for the past several days and I need to move forward. Thank you for your help in advance:

 

"""Global Variables --> FOR TESTING ONLY <--"""
bitstring = '10000010'
polynomial_key = '10011'
initial_filler = '1'
value_check = '0111'


def crc_calculation(bit_string, bitstring_key, filler):
"""Calculates the CRC with the use of fillers"""
bitstring_key = bitstring_key.lstrip('0') # Strips all leading zeros
bit_length = len(bit_string) # Length of bitstring
# Length of polynomial bistring and subtracts one, multiplied by filler
# 0 - adds 0's to the end of the bitstring length - 1
# 1 - adds 1's to the end of bitstring length - 1
add_padding = (len(bitstring_key) - 1) * filler
padded_array = list(bit_string + add_padding) # Adds initial padding values to the end of bitstring
while '1' in padded_array[:bit_length]:
cur_shift = padded_array.index('1')
for i in range(len(bitstring_key)):
# XOR Operation => compares polynomial_bitstring to the current array
padded_array[cur_shift + i] = str(int(bitstring_key[i] != padded_array[cur_shift + i]))
return ''.join(padded_array)[bit_length:]

print(crc_calculation(bitstring, polynomial_key, initial_filler))

 

0 Kudos
Message 1 of 4
(1,196 Views)

Well, if you tried, you must have come up with a vi, although not working. Why not posting what you've done, so we can point out what you did wrong?

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 4
(1,160 Views)
Solution
Accepted by topic author LV2019_Newb

@LV2019_Newb wrote:

Hello,

 

I am very new to programming in LabVIEW and have been tasked with writing an algorithm in LabView2019 that uses the polynomial 0x13 (x^4+x^1+1). I have tried to duplicate the algorithm from https://forums.ni.com/t5/LabVIEW/Computing-CRC/m-p/825331/highlight/true#M375052 but substituting my data without success.

 

Could someone please help me convert the following code from Python, I have been stuck on this for the past several days and I need to move forward. Thank you for your help in advance:

 

"""Global Variables --> FOR TESTING ONLY <--"""
bitstring = '10000010'
polynomial_key = '10011'
initial_filler = '1'
value_check = '0111'


def crc_calculation(bit_string, bitstring_key, filler):
"""Calculates the CRC with the use of fillers"""
bitstring_key = bitstring_key.lstrip('0') # Strips all leading zeros
bit_length = len(bit_string) # Length of bitstring
# Length of polynomial bistring and subtracts one, multiplied by filler
# 0 - adds 0's to the end of the bitstring length - 1
# 1 - adds 1's to the end of bitstring length - 1
add_padding = (len(bitstring_key) - 1) * filler
padded_array = list(bit_string + add_padding) # Adds initial padding values to the end of bitstring
while '1' in padded_array[:bit_length]:
cur_shift = padded_array.index('1')
for i in range(len(bitstring_key)):
# XOR Operation => compares polynomial_bitstring to the current array
padded_array[cur_shift + i] = str(int(bitstring_key[i] != padded_array[cur_shift + i]))
return ''.join(padded_array)[bit_length:]

print(crc_calculation(bitstring, polynomial_key, initial_filler))

 


May be you have to use the given VI "AIT - Utility - CRC - CRC.vi" from linked message something like this:

Screenshot 2024-12-18 10.37.01.png

Isn't?

 

Message 3 of 4
(1,153 Views)

Thank you very much for your help. I now see where I was making the mistake.

0 Kudos
Message 4 of 4
(1,124 Views)