LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert ASCII with decimal point to number

I am trying to convert ASCII data from an instrument to a numeric value. I am using the 'Fract/Exp String to Number' VI. inputting the ASCII string '32 33 34 2E 35 36 37 to the VI results in the output (Single) number 234 (integer part only). Inputting the string constant 234.567 to the same VI results in the correct 234.567 numeric output. Why does the VI recognize ASCII 32 as a numeric 2 but doesn't recognize ASCII 2E as numeric 'decimal point'. How should I do this conversion? I tried the Scan VI and a format string but the result was the same.
0 Kudos
Message 1 of 11
(7,680 Views)
Works for me just fine.
Randall Pursley
Download All
0 Kudos
Message 2 of 11
(7,674 Views)
Is your string control set to "Hex Display" mode?



Message Edited by smercurio_fc on 07-30-2008 10:30 AM
0 Kudos
Message 3 of 11
(7,660 Views)
That's might be a localization issue, your OS is ',' decimal and you have setup LabVIEW to follow (which is good).

Now you need to instruct the conversion to use a '.' as the decimal sign.
A scan from string should need the following formatter: '%.;%f'

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 4 of 11
(7,655 Views)
It works fine if the string into the fuction is displayed as a number (e.g. 123.456). This is what I saw when I input a string constant to the conversion VI. The problem is when the input to the VI is an ASCII string (e.g. 31 32 33 3E 34 35 36). The output from the VI is 123.456  for the constant input and 123 for the ASCII input. What is the difference between a string which is displayed as a number and an ASCII value? Aren't all strings composed of ASCII data?
 
If you input a string constant to the VI, enter 123.456 into the constant and run the VI it will output 123.456
 
If you then change the constant to 31 32 33 3E 34 35 36 (ASCII 123.456) and run the VI it will output 123
 
It is converting through the whitespaces and locking up on the decimal point.  
0 Kudos
Message 5 of 11
(7,653 Views)
It should be '3132 332E 3435 36' not the 3E you have above. If you had simply right clicked on the string control and selected Normal Display, you would have seen that the ASCII string you are trying to convert is '123>456'.

Message Edited by Dennis Knutson on 07-30-2008 09:51 AM
0 Kudos
Message 6 of 11
(7,645 Views)

Sorry - my typo mistake - the Labview data does contain the correct 2E code for decimal point. Also, I made an incorect statement in any earlier post. The constant conversion was not skipping white spaces. I had entered 3235 362E and the conversion resulted in 3235, stopping at the whitespace.

If I could, let me lay this out once more from the beginning. It's getting a little confusing. 

The data it coming from an external tachometer via an RS485 interface. The data format is ASCII string, formatted as xxxx.xxx (length varies with data as leading 0s are not transmitted). I want to be able to convert the data to a decimal number.

I'm receiving the data with a VISA read VI, removing the string termination CR charater (0x0D) and converting the remainder of the string to a decimal value. To test the conversion problem I've added a data select mux which chooses between the string output of the VI and a string constant.

If I control the speed the tachometer measures, set the mux to the VISA read output and run the VI so it reads a string, say 3233 342E 3130 300D, the resulting output from the 'Fract/Exp String to Number' VI (FESN) is 234. It stopped converting at the decimal point. Also, the Offset Past Number (OPN) output of the FESN VI contains 7, indicating that it converted 3233 34 as 234 and left the string 2E 3130 300D as not convertable. 

If I enter 3233 342E 3130 300D into the constant, point the mux at it and run the VI the output is 23 and the OPN is 2, so it stopped converting at the whitespace.

If I enter 234.100 into the constant, point the mux at it and run the VI the output is correct with trailing 0s dropped at 234.1 and the OPN is  6.

 

 

 

 

 

 

0 Kudos
Message 7 of 11
(7,602 Views)
Still cannot reproduce the problem. If I set a string control to hex display, the Fract/Exp String to number converts 3233 342E 3130 300D correctly to 234.1. Could you post your VI with some actual data saved in the controls/indicators.
0 Kudos
Message 8 of 11
(7,591 Views)


fr@nk wrote:

If I enter 3233 342E 3130 300D into the constant, point the mux at it and run the VI the output is 23 and the OPN is 2, so it stopped converting at the whitespace.

If I enter 234.100 into the constant, point the mux at it and run the VI the output is correct with trailing 0s dropped at 234.1 and the OPN is  6.


Do you change the representation between those two actions of the constant?

If not you should get 3233 as value and the OPN on 5.

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 9 of 11
(7,583 Views)

I had the thing torn apart before getting your last post and when I rebuilt it it worked just as it should.  Unfortunately I don't know what I did wrong before but obviously I did something. Thank  you for all of your help.

Frank 

0 Kudos
Message 10 of 11
(7,578 Views)