LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP Checksum Error

Hi,

 

I am trying to send some message to a device. There is a total of 2 sections of message. At the end of the message_A, there will be a checksum. Similar, at the end of message_B, there will be a checksum too.

 

I have attached the vi for message_A.Since labview don't automatically convert to little endian byte ordering, i did it manually. A total of five data will be send here in this vi. The first four data are all constant and are a 2byte data. The last is a 2byte checksum.

 

Now here is the problem i face. When i purely this message_A to the device, the device showed this error "message_B checksum is incorrect" and i fully understand that there is a need to send the two messages all together for the device to work. Then i added in the message_B part, which is too long and i did not attach here, and the error is now "message_A checksum is incorrect".

 

Therefore now i wish to know if there is anyway that i can type out the string data (that constants and checksum were converted to before the TCP send) to see if the format is correct? Because i find it strange here. When i send only message_A, the device indicates that message_B's checksum is incorrect = which means that in this particular case message_A's checksum is correct?? If that is the case, when i add in message_B part (even if this part is incorrect), it shouldn't indicate that message_A's checksum is incorrect right? I am very confuse. Please help if you understand what i mean and i can't disclosure what the device. Thank you. Any help/suggestion/advise to check on my vi is very much appreciated.

0 Kudos
Message 1 of 5
(3,315 Views)

You could use another PC to act as TCP client, and view the data your host sent.

0 Kudos
Message 2 of 5
(3,282 Views)

Instead of using the Typecast function, you can use the Flatten to String function.  The latter has an input to select the endianness of the data, so that you don't have to do it manually.  If you decide to use Flatten to String make sure to properly set the "Prepend array/string size" input correctly.

 

It looks like your checksum is the complement of the 16-bit sum of the inputs.  You can use the Not function to get the complement of an integer, rather than subtracting from 0 (the And and Or functions also work on integers).

 

To see what your data will look like, right-click on the string wire going into TCP Write and select Create>>Indicator.  You can then right-click on the newly-created indicator and select Hex Display.  You could also make a probe that displays hex strings.

0 Kudos
Message 3 of 5
(3,273 Views)

Hi all,

 

I have checked thoroughly and found that the problem is due to a typo in the user manual of the device therefore resulting in the computation of the wrong checksum.

 

However, i have two problems on the two messages that i need to send. I mentioned earlier that all the data in message_A are all 2 bytes constant data. But in message_B, there consists of data that are of 1 byte, 2 bytes and 8 bytes. In message_A, i have no problem by setting all the 5 data to I16. However, in message_B, for e.g. i have two data of 1 byte each, the value is 1 and 0 respectively. If i use I16 with hexa value 0100 then i have no problem. But  when i use two I8 with 1 and 0 hexa value, it generates an error. I also found that i need to make all the data size to be I16 in order not get a checksum error. How can i avoid this?

 

This is because all the data in message_A and message_B are wired to an array build function and then wired to the flatten to string function (before finally wired to the TCP write function). By using an array build function, does that means that the data that i want to build into an array all has to be of the same size, I16?

 

The second problem is that the first time i send both message over to the device is to initialize the device. In message_B where i need to send the dynamic values, during initialization, i set all to zero first. But after initialization, some (not all) of the data need not be zero (eg. array[20] = 0; array[21] = 55; array[22] = 30; array[23] = 0; array[24] = 99; etc). I used a for loop whereby for all the dynamic array data (array[0 to 25] i set to 0. How can i insert values to array 21, 22 and 24 in this case?

 

Please advise. Thank you.

0 Kudos
Message 4 of 5
(3,240 Views)

Yes, all data in an array must be the same type.  If you wire numerics of different sizes to Build Array, LabVIEW will cast the values to the largest type.  You can instead flatten each numeric individually and then using Concatenate Strings on them.

 

To initialize an array to all 0s, use the Initialize Array function.  Then use Replace Array Subset to replace the elements you need to replace.

0 Kudos
Message 5 of 5
(3,226 Views)