LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ASCii code convert to decimal number

Solved!
Go to solution

Hi,

 

I faced a problem to convert ASCii code to decimal number .

ASCii code getting from Bluetooth receiver.

Refer to "result" picture, the "output" i can get is 123. This is not correct.

The expected result  should be x.xxxx (refer to "expected result decimal" picture).

Attached my program file and image file (diagram picture) for your study.

Please provide me your Labview file if you able to solve it.

I can use your file to try out.

 

thank you.

best result.

0 Kudos
Message 1 of 17
(2,390 Views)

Please run your VI once more until the received string contains actual data, stop the VI and make current values default (Do you know how to do that?).  Save and attach. Now we have a correct string to play with.

 

altenbach_0-1619277014068.png

 

And no, I would not call this "ASCII code" (A character encoding standard). It is just a random binary string to be interpreted as a sequence of bytes.

 

Casting a long string to a U8 will drop all information except one single byte, so whatever you are doing now is incorrect. Do you have information about the received string? How long is it (looks like ~16bytes)? What's the structure?

 

So you seem to expect floating point values. It could be that you need to cast to SGL or DBL or some multibyte integer that needs to be scaled. No way to tell. Do you have the manual for this device?

0 Kudos
Message 2 of 17
(2,359 Views)

Hi, Altenbach,

 

Thanks for your reply.

i changed the "ASCII code from Bluetooth receiver port"  display style property to Hexadecimal.  Please refer to "result_R1'.

I try to use other application software to find more data information. Refer to "information" picture.

 

best regards.

 

Download All
0 Kudos
Message 3 of 17
(2,317 Views)

The default value for the string is still blank in your VI.

0 Kudos
Message 4 of 17
(2,308 Views)

Hi, Altenbach,

 

How to get the default value ? Please teach me.

Before i start the program, there is nothing in "ASCII code from Bluetooth receiver port" display box.

Once i start, i can see hexadecimal number keep going to change.

I try to attached a video file, unfortunately, not succeed due to file size is too big. 

 

best regards.

 

0 Kudos
Message 5 of 17
(2,298 Views)

What device are you using to get this data? You need to know what kind of data to expect. Is there a data sheet or any documentation?

0 Kudos
Message 6 of 17
(2,268 Views)

The data is transmit from strain gauge Bluetooth transmitter.

Data format is in ASCII format .

The 'information" image file shows 2 information.

1st) ASCII code (0D 0A are the header and footer), balance are data.

2nd) 3.xxxx is the final decimal value that i want to get.

Example: 33 2e 32 37 32 36 after convert become 3.2726

So i want to build up a program to convert ASCII code to decimal value.

 

best regards.

0 Kudos
Message 7 of 17
(2,265 Views)
Solution
Accepted by topic author Jeffrey_Oon

From what you posted earlier, the data displayed from VISA read is garbage. Maybe the baud setting is wrong? In your VI, remove the Bytes at port, just wire a value larger than you expect to see and when the newline character (0xA) is read Visa read will return the data up to that character. (That is the default settings for visa configure port)

 

If all the port settings are correct (data bits, stop bits, parity and baud) the VISA read will return the the ascii data.

 

Screenshot 2021-04-25 091222.png

Enable Term. char and the linefeed (0XA) are the default settings.

0 Kudos
Message 8 of 17
(2,260 Views)

 


@Jeffrey_Oon wrote:

Example: 33 2e 32 37 32 36 after convert become 3.2726

.


Well, this is quite different to the received string shown in your first picture, which had basically no printable characters!

Now you just show us a formatted string, which, (using ASCII convention) consists of numeric an delimiter characters describing the number you want. You can scan that into a numeric datatype as needed.

 

altenbach_0-1619363543549.png

 

 

To answer the question how to make a value default:

  1. run the VI so the string indicator contains data (e.g. as shown in your first picture)
  2. go to menu: "edit...make current values default".
  3. save the VI under a new name and attach it here.

 

 

0 Kudos
Message 9 of 17
(2,260 Views)

Hi, Altenbach

 

The root cause is the baud rate wrong selection.

Thank you for your advice.

 

best regards.

0 Kudos
Message 10 of 17
(2,226 Views)