12-17-2024 10:34 PM
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))
Solved! Go to Solution.
12-18-2024 02:33 AM
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?
12-18-2024 03:39 AM
@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:
Isn't?
12-18-2024 09:29 AM
Thank you very much for your help. I now see where I was making the mistake.