LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to calculate checksum for serial communication

hello everyone, i am trying to find out checksum for my serial communication using NI VISA. I am sending 1 byte data, 1 byte checksum of that data over UART communications... i would liek to save just the data to a file w/o the 

checksum,

 

the algo i would like to use is

  1. init a counter to 0, read 1 byte data using NI VISA read, change the increment the counter to 1
  2. read next byte using VISA read, this shud be the checksum sent my micro-controller, 
  3. if checksum is correct, send an ACK to uC, remove the checksum byte, save only the data byte... 

can anyone suggest me logic/snapshot of how to achieve this?

Thanks,

 

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 1 of 11
(11,488 Views)

Hi LV_Enthu,

 

I would read 2 bytes from the serial port and then do the 3rd step. Why bother with reading 2 bytes seperately?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(11,482 Views)

hello GerdW, currently I am using the serial port property "Read Bytes at Port", and that way I am reading the entire bytes how many ever occurs at the serial port... so are you suggesting instead of using this property, have a constant (i.e. 2 number of bytes to read ) from NI Visa Read? that will probably

make the whole communication very slow...

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 3 of 11
(11,473 Views)
You said you wanted to read one byte at a time. Why would that be faster.
0 Kudos
Message 4 of 11
(11,468 Views)

Dennis_Knutson, no, what i meant was to analyze 1 byte at time of all the in-coming stream of data... sorry for the confusion... for example, if the incoming stream is 

0xAA 0xBB 0xCC 0xDD 0xEE 0xFF 0x11 and so on... my labview code should be such that it should understand that 0xAA is data byte and 0xBB is checksum byte and it shud just sav 0xAA to a file... i hope this clarifies 

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 5 of 11
(11,463 Views)
It clarifies nothing. How do you know which byte is data and which is the checksum? Or is the whole point an attempt to synch? If so index one byte at a time. Perform the checksum calculation and compare it to the next byte. When you have a match, you have achieved sync and then adjust the number of bytes to read.
0 Kudos
Message 6 of 11
(11,459 Views)

Dennis_Knutson,

yes, the whole point is to sync, actually, i am having issues with bytes being lost, i am having a baud rate of 921600, hence, i wanted to add some kind of error check, just to make sure no bytes are being lost...

what you just described below is what i intend to achieve, can you please post a snippet/code to help me understand? it would be really greatful if u can do that...

 

thanks,

 

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 7 of 11
(11,456 Views)
So you want to double the number of byes? Why don't you use hardware handshaking?

Sorry, I don't have LabVIEW on my phone.
0 Kudos
Message 8 of 11
(11,453 Views)

helo, i dnt have the optino of hardware handshaking.. i am not using that... i think i will have to double the number of bytes if i want to send 1 byte cheksum for every byte... thanks for your inputs

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 9 of 11
(11,448 Views)

hello, i think i have implemented what i wanted ... however, 1 last issue... i am observing that labview is reading the data twice of the serial port... for example..

the actual data is :

 

0x120x280x04; however, labview is reading 0x12 0x12 0x28 0x28 0x04 0x04.... i think that labviw clock is way faster than my uC clock, and before uC is sendin new data, labview is reading watever is in its internal buffer.. no matter if it is updated by uC or not... 

 

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 10 of 11
(11,439 Views)