From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

packet reading

    I have a question that any help would be very much appericated.  I have serial data coming thought my com port in packets.   Right now the data is coming in repeatedly and i need to sort out the information that i need and throw out the stuff i dont need.  The packet  is sent with a start delimiter and ends with a check sum so the only sure thing i can expect is to see a hex value of 7E at the start of every packet then there is a bunch of data that i dont need and then finally my AD conversion that i need to change in to a demical value.  Here is an example of a packet that i would recieve       

                7E 00 1C 83 56 78 22 00 05 06 00 03 FF 77

    the hex value in bold is the information i need from the packet and the other value i do not need.  I was looking into the serial visa and string vi but none of them seem to be very easy to do what i want it to do.  Please any help would be great and thank you in advance.

P.S.  the packet always has that many hex value in it just the values change except for the 7E
      
0 Kudos
Message 1 of 5
(3,000 Views)
It may be easier for you to deal with in bytes by converting the string that you get from the VISA Read to a byte array:


Don't know what the rest of your code is doing, so this is just a suggestion.

Message Edited by smercurio_fc on 07-17-2007 09:43 AM

0 Kudos
Message 2 of 5
(2,983 Views)

smercurio,

     thank you for your help but after trying your idea it didnt seem to work the way i was hoping there really isnt to much to my project it just opens the com port and reads when the read button is pushed i just need the information from the packet that i bolded in my last post.  I have found out that in a string indicator that reads hex the information it reads could look like this:

0028 387E 000C 8356 782E 0020 0018 367E

with that kind of string i dont know if that is the reason im not getting the right data out of the string as i would like with your solution What do you think about using scan string for token and set my token to be 7E

0 Kudos
Message 3 of 5
(2,962 Views)
My example was based on the assumption that the string you get will be in hex values as opposed to ASCII characters. Also, that's a different string. This string has 2 bytes between the sections you want. The previous one had 4. Again, assuming you're getting hex values as opposed to ASCII characters.

Is your string indicator set to "Normal Display" or "Hex Display"? If it's set to "Hex Display" and you see the string 0028 387E 000C 8356 782E 0020 0018 367E then what I showed will work, with the 11 changed to 9 due to only 2 bytes separating the sections you want.

If it's set to "Normal Display" and you see the string
0028 387E 000C 8356 782E 0020 0018 367E then you are receiving ASCII characters, and what I showed you won't work. If this is the case did you put those spaces in, or is that how they came across? If you're getting ASCII characters you just need the standard string functions. One way is the Match Pattern. You could use the Scan String for Tokens, but that's usually used when you're looking for multiple delimiters and you're not really doing that.

See attached VI (LabVIEW 8.20) for a comparison.
0 Kudos
Message 4 of 5
(2,950 Views)

A couple other questions, what is the format of the two parts of the packet that you need to convert to decimals? Are they just integers? Also you should be planning on testing the checksum (the last byte?). It's there to tell you whether you can trust the rest of the data.

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 5
(2,945 Views)