LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to convert u8 to decimal

You really haven't told us enough for us to fully understand your question.  So I'm going to guess here, and show you what might be happening (and how you should deal with it).

 

I'm going to assume that you have a device that produces a value, which I will assume is a Dbl (Float), and may be either represented as a Float or as a String representing a Float (i.e. it is either the number 12.34 or the string "12.34").  In any case, it is transmitted to LabVIEW in string representation as an array of bytes (U8).

 

Here is a Snippet of the process, showing the original number (Value), the representation as a String (using Format Into String) and the conversion of the String to a Byte Array (String to Byte Array).  At this point, we have an array of U8, similar to what you showed.

Decode Byte Array.png

The final two functions reverse the process.  Byte Array to String recovers the String, and Scan from String reconvers the number.

 

As resonable as this may be, it is possibly quite wrong, as your example shows a Byte value of 251, which corresponds to the character "û", clearly not part of what we consider a string representation of a number.  So not only don't we (I shouldn't say "we", I should say "I") understand what you are attempting, I don't have "typical data" that you are trying to reformat (indeed, it wasn't until recent posts that I realized that you were dealing with Byte arrays).

 

So please, tell us in detail (a) what the original value (from Arduino?) represents, and whether it is an Integer or a Float, (b) how the data are transmitted to LabVIEW, and (c) provide a complete example of the data array.  I dare say, many of us would almost instantly recognize whether what you are showing is an Ascii string representation, the byte components of a multi-byte Integer, or the byte components of a multi-byte Float.  Once we know this, the conversion process will be clear (to us) and we can help you.

 

Bob Schor

0 Kudos
Message 11 of 21
(2,520 Views)

@joap wrote:

response.PNG


Please resize that array container so it show all elements.  How many elements are there?

 

What's the name of the LINX function in the middle and what does the help say about it?

 

(In any case, you might get more specialized advice posting this on the LabVIEW MakerHub forum.)

0 Kudos
Message 12 of 21
(2,512 Views)

hello

 I have tried that already and in the string indicator there comes only this: û

0 Kudos
Message 13 of 21
(2,501 Views)

this is what a custom command is: labiewhacker.com/doku.php?id=learn:libraries:linx:tutorials:adding_custom_command

 

I wrote in arduino:

 

int batterij(unsigned char numInputBytes, unsigned char* input, unsigned char* numResponseBytes, unsigned char* response)
{
x = analogRead(3);
y = map(x, 0, 1023, 0, 255);
//y = (x/1023)*5;
response[0] = y;
*numResponseBytes = 1;
return L_OK;
}

0 Kudos
Message 14 of 21
(2,501 Views)

hello, thank you for your reply
I got that string scan used but then I get an error that the type of the string is not correct.
The exact way the data is sent to LabView I do not know because we had to do this so our supervisor

In arduino I have an array U8 with the response

This is the link where I found information on the custom command:
https://labviewhacker.com/doku.php?id=learn:libraries:linx:tutorials:adding_custom_command

(apologies for my poor english)

0 Kudos
Message 15 of 21
(2,493 Views)

@joap wrote:

hello

 I have tried that already and in the string indicator there comes only this: û


OK, so you probably only get a single character (hard to tell, because some might not be printable). Why don't you right-click on the string indicator and select "hex display"? What does it say now?

 

Maybe all you need to do is use "index array" to get the first element as a U8 number?

0 Kudos
Message 16 of 21
(2,486 Views)

Thank you for your answer
These are all elements that response exists (I can make it very long but there is nothing sent to)
and I will ask again at the forum, the linx function in the middle is custom command

0 Kudos
Message 17 of 21
(2,484 Views)

now it says F9

0 Kudos
Message 18 of 21
(2,478 Views)

F9 in hex is 249, very similar to 251 that you saw, previously.  Something very strange is going on here -- I think that I am "out of my comfort zone" ...

 

Bob Schor

0 Kudos
Message 19 of 21
(2,457 Views)

Your map command seems to scale the raw sensor value to a range of 0..255. Simply use "index array" to convert the single elements U8 array to a U8 scalar and wire it to you indicator.

0 Kudos
Message 20 of 21
(2,444 Views)