LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I make a HEX case selector?

Solved!
Go to solution

Hi all,

 

I am trying to parse serial HEX data from my SPS30 dust monitor. The way that I am approaching this is to use a case structure to parse data. The reason I am using this method is because the protocol of the data is SHDLC. Where the start byte is the 7E, then next byte is the address byte, 3rd is the command byte, 4th is the length byte, and then the Tx data bytes, ending with the 7E byte again. I can use the case selectors to categorize the data into bins and organize it in the way that the datasheet shows. I am having trouble with selecting the case, because the data is coming in as hex, I suspect that the case selector is in decimal or ascii and is expecting a decimal string. But, most characters from hex are just NUL so it just looks like an empty space. I looked for "Radix" to change it to hex but could not find it. Please, correct me if I'm wrong, I'm still trying to understand this. Thank you for your help!

0 Kudos
Message 1 of 4
(1,249 Views)

What I see is that you are taking 1 character from the beginning of the string and wiring that into a case selector.  For the case that you show, (if you attached an actual VI, we could see what else is going on) you are comparing it to "01".

 

Guess what, a 1 character string will never be equal to a 2 character string.

 

To change a radix to Hex, you need to set it to be selecting integers, not strings.  Wind don't you take your string data and convert them to integers  (e.g. Scan from String or other functions that are on String/Number conversion palette), then wire that into your case structure.

0 Kudos
Message 2 of 4
(1,238 Views)
Solution
Accepted by topic author Dvlasenko

Use String To Byte Array and then Index Array to get the first element.  When you wire that up to the case selector, you can right-click on the case structure and select Radix->Hex.


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 3 of 4
(1,184 Views)

Well there's a couple ways to go about this...

 

  1. Leave the strings as strings
    1. You can still have a case for every "hex value" ("00" through "FF")
  2. Convert the string to numbers
    1. Create a case for 00 through FF numeric values
    2. Use Show Radix on everything to help avoid confusion

HexCase.png

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 4
(1,153 Views)