LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to select the last elements in a string

Solved!
Go to solution

Hi Guys

 

I am using UART RS232 protocol and i need to calculate the check sum. My data came in decimal and in the end it must be doubles to manipulate it. So my problem is, for example, the sum of all elemants is in decimal 1742 and in hex is 6CE and i wont only the last two elemants, CE that corresponds to 206 that is the result of my checksum. Can anyone help me? 

Thanks

0 Kudos
Message 1 of 23
(4,310 Views)

String%20last%20elements[1].png

 

What is the data type you'll receive?  If it's acceptable to convert it to an I16 (or, if it is I16) this will work.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 2 of 23
(4,296 Views)

split number

 

split number.png

 

edit: too late 😄

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 3 of 23
(4,286 Views)

Hello Jim and thanks for answer

 

My data came from an HMI device and in decimal. I'll show you an example:

 

123 123 160 54 111 103 110 108 107 109 108 108 100 100 100 100 0 0 1 4 5 0 0 0 0 0 0 7 96 1 0 0 0 0 0 10 51 1 0 0 51 1 1 23 12 0 206 125 125

 

The last third elemant is the Checksum. If i sum all the elemants from 160 (cmd) to the last cell before 206 (CKS) the result is 1742 (decimal) that correspond to 6CE has i told before, but is truncated to the 2 less significant digits CE that is 206. I will try the examples from you guys.

Thanks a lot                                                                                                                                                                                                                                     

0 Kudos
Message 4 of 23
(4,276 Views)

I think this is what you are going for.  Your main issue is that you want to use String To Byte Array.  Each of those numbers are bytes.  To treat them as bytes instead of ASCII characters.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 23
(4,247 Views)

i dont know if it fits to your req. because my input is array just sum them up and convert to string...

 

 Image90 Dec. 12 21.43.jpgstring.png



Thank you & Best regards
syrpimp

=======================================================
“You must continue to gain expertise, but avoid thinking like an expert." -Denis Waitley
0 Kudos
Message 6 of 23
(4,235 Views)

Thanks Syrpimp

 

My data came from HMI in decimal like the example that i show above. Each cell is a value. You used an array, but i think that i can't use it because it must be done automatically and the data field have variable length. 

 

The UART protocol frame has a start frame field that corresponds to two ‘{‘ characters and an end frame field that corresponds to two ‘}’. Additionally, besides the data field, that has variable length, it has a byte that corresponds to the command type and another that is the checksum. The following table illustrates the protocol.

 

 

Bytes considered in checksum

 

 

 

 

Command Data

 

 

Start Frame

Cmd
(hex)

Data0

Data1

Data2

Data3

Data4

Data5

Data6

Data…

CHK SUM

End Frame

{{

 

 

 

 

 

 

 

 

 

1 Byte CHK SUM (sum of all data bytes truncated to 1 byte)

}}

Fig. 1 UART communication protocol template

 

I receive data like this:

 

123 123 160 54 111 103 110 108 107 109 108 108 100 100 100 100 0 0 1 4 5 0 0 0 0 0 0 7 96 1 0 0 0 0 0 10 51 1 0 0 51 1 1 23 12 0 206 125

125

 

I'm trying explain my doubt the best way i can and i thank you all.

0 Kudos
Message 7 of 23
(4,209 Views)

I highly recommend viewing your string in Hex display and change your numbers here into hexidecimal.  Things will make a lot more sense.  Then go look at my post above.  It does exactly what you are asking for.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 23
(4,200 Views)

Hello again

 

I tried exactly has you told and the result isn't ok. See the attachment.

0 Kudos
Message 9 of 23
(4,190 Views)

Your input data isn't correct.  I can tell because it should be starting with 7B7B and end with 7D7D.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 23
(4,179 Views)