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: 

convert hexadecimal output to decimal (number)

Well, the clue was that the encoding is BCD, i.e. Binary Coded Decimal. (See e.g. http://www.webopedia.com/TERM/B/BCD.html ) for a definition. Is the string you have in your latest example exactly the raw string you get from the machine? Your sample string is length 70 and contains spaces, probably meaning the spaces should be ignored and it is a hexadecimal formatted representation of the original string, which should be only 24bytes, right?

Please capture the raw string from your device and include it without any formatting (Just aquire, stop, then righ-click on the terminal and select "create constant, then save the VI). Your current example string does not look right.
0 Kudos
Message 11 of 29
(1,346 Views)
Coop wrote:

> Hi guys,
>
> I am writing you back because I tried the two solutions that you
> offered to me (with and without loop) and I think the problem still
> exists. This time I attached simpler example and you can see what I
> mean.
>
> I am trying to read all the pressure levels at all 8 channels of my
> multi-gauge. Inside of the loop you will see the string constant that
> represents the pressure levels read from the VISA read.
>
> Now that I have read all pressures I have to display all 8 gauges
> seperatelly so that's why I am using String Subset and storing data in
> 8 different indicators. This mechanism works well but the only problem
> that remains is how to display string eg. 1435 00 as 1.435E+00.
>
> If I use the two examples that you suggested it will convert it
> properly only if the input string is set to hex display and then the
> 1435 00 is typed in. In this case it does convert it right into
> 1.435E+00.
>
> But the string that I receive from VISA read or the string constant
> that I use in this example can not be changed between normal and hex
> display. Therefore when 1435 00 enters the convert subVI it converts
> it to 3.134E+33.

If the string in the example is exactly what you get from VISA this
means you are not getting binary strings from your instrument but simply
text strings. The difference between these are double the number of
bytes. As you have always claimed that the numbers you say were the ones
needed when the string control was set to show hex Display we did assume
that that was what you wanted. If the string you have in your test
example is really what you get then of course our assumption was all wrong.

So the question is if you use VISA Read and display the received string
in a string indicator which has been configured to show "Normal Display"
what do you see? If you see all numbers you are receiving a text string
with hexadecimal formated numbers. If you see lots of squares and spaces
and a few normal characters you receive a binary string.

Depending on that we can look further.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
0 Kudos
Message 12 of 29
(1,346 Views)
Hi,

I am so glad you replied guys because the actual output string is not in the form of 0E00 030E 0003 0E00 030E 0003 0000 0000 0000 1435 0014 0300 0000 0000 as I said before it is in the form that you assumed it will be. See my example now.
Here I did exactly what you told me to do.
When you open attached VI you can see what is read at the output of VISA Read in Normal and Hex Display.

You are right that there should be 24 bytes (8x3) but in reality there is 30 bytes. Extra 6 bytes come from last two readings (see Front Panel: Error 1 & 2) which represent the error in the software of the multi-gauge so we can ignore it.

I am sorry for making confusion.
You guys are the best.

Thanks so much,
Pedja
0 Kudos
Message 13 of 29
(1,346 Views)
I just entered new reply.
You were right Rolf from very beginning.

So what would be the right way to convert it now?

Thanks,
Pedja
0 Kudos
Message 14 of 29
(1,346 Views)
OK, after all that extra information, we should be getting closer.

The first four channels in your new sample string are 0E 00 03, this cannot be BCD, because E is not allowed. Could it be this has a special meaning, e.g. "overflow", "not connected", etc?

Anyway, I have attached a new try based on the information. It converts everything, including the two extra numbers at the end. Insert a "-2" at the loop count input if you don't need these.

Does this look OK?
Message 15 of 29
(1,346 Views)
Hi,

The first four channels are showing E03 if we convert it to better format. That just means error 3 which corresponds to level at the gauge being too low or basically nothing is connected to it. So just ignore those first four channels. I should have mentioned it earlier it would be much easier for you to think.

I looked at the new VI and it looks perfect. That was basically the goal to display it in the exponential form.
However the only one thing remains and that is to convert 0E00 03 error code into E03 form.

These error codes are quite important for the vacuum chamber system I am writing the program for. It is because the user can know what went wrong at any point in time and act accordingly.

I was thinking to simply sort of take the strin
g as it is and then make it up like trim it and then cut extra digits out and things like that...
I am not sure.

I just have to thank you for who knows what time for your time.

Regards,
Pedja
0 Kudos
Message 16 of 29
(1,346 Views)
Here's a suggestion for the error handling. Good luck.
0 Kudos
Message 17 of 29
(1,346 Views)
This is great.
I don't know what else to say.

Thanks a lot,
Pedja
0 Kudos
Message 18 of 29
(1,346 Views)
Now I just want to display 8 elements of an array as 8 indicators but I am thinking now how to link Status array and Numbers array. I basically want to combine the two into one because when error occurs the E03 will be displayed, when there is no error then the reading is displayed.

I wanted to check for NaN and if Numbers are receiving NaN then I would write Status to an indicator but they are different types...

I know there is a way to do it I just wanted to know if there is a fast way that you have in mind.

Thanks a lot,
Pedja

p.s. see ConvertBCD VI now
0 Kudos
Message 19 of 29
(1,346 Views)
I just noticed that if reading is 7699 FF it would not work so I replaced the Decimal to Number block inside of Default case with Hexadecimal to Number and now it seems to work.

What do you think about this?

The exponent (3rd byte of the reading is in two's complement notation as written in the manual).

Regards,
Pedja
0 Kudos
Message 20 of 29
(1,324 Views)