LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

converting the floating point ascii in decimal values

Solved!
Go to solution

Hello,

Using LV8.6 I am working on a project in which I am getting Floating point data on serial port in ASCII form and I have to convert it into its appropriate decimal value.

I have tried the type cast to convert the data and succeeded when the data was only a decimal value.

But when these values are in floating point which is my actual data i.e. 1.63, 3.41. I am receiving it as 1.11 (if it is 1.63), i.e. getting only the first digit.

But the data is received correctly on String Display and hyperterminal that means the communication is perfect but the error lies in programing.

kindly guide me what I have to do.

Thanks

0 Kudos
Message 1 of 9
(5,314 Views)

here is the file too

0 Kudos
Message 2 of 9
(5,308 Views)

Whatever you are doing does not look right and is overly complicated?

 

 

  • You are reading all bytes at the port 4x in a row and converting each read into a single U8. How many bytes do you actually read typically at each iteration?
  • Why is there no wait in the big FALSE case. Whenever you are not reading, your loop consumes 100% CPU. Not good.
  • Your inner case on the right only has one case, you might as well delete this case structure. It has no function.
  • From your "-48" stuff, it seem like you are reading formatted (not binary) data and you are trying to skip the decimal point at step 1. Why don't you concatenate the strings, then simply scan from string with %f format?

 

  • Please wire the read string to the edge of the FOR loop to create an array of strings. Create an indicator at the output tunnel. Run the VI so this indicator contains some data. Change the string array indicator to a constant (tight-click...change to constant). Save and attach the VI once more so we see what is actually arriving.

 

0 Kudos
Message 3 of 9
(5,297 Views)

Thanks alot.

I have actually altered the simple read write vi of examples to achieve my goal.

 

1- Since my data is like 1.63 means four digits (1 . 6 3). i think that these are recieved indivisually in the same order so i am running it 4 times to recieve them, Then converting the indivisual ASCII data into its appropriate decimal value in the for loop and this is the reason that the for loop is run four times.

 

2- As working on a previously develop example and to avoid any unwanted error.

 

3- i have connected the array constant and deleted the Case structure but its showing broken wire.(see attachment). i have used case here to only view the final result as one value.

 

4- Yes i am receiving the data in ASCII format and since if "1" is arriving in ASCII you can view it as "1" of decimal by subtracting 48 from converted decimal. (http://www.asciitable.com/).

 

One interesting thing that i want to share is that when the data is received it is seen as the complete measurement on the String Read on the first cycle. And i dont know its reason.

0 Kudos
Message 4 of 9
(5,291 Views)

 


@Intelligent wrote:

3- i have connected the array constant and deleted the Case structure but its showing broken wire.(see attachment).


 

String is pink, not orange! If this is confusing to you, please start with a few simple tutorials first.

Please do as follows (shown in the image), run the VI to get data, then convert the string array to a constant. Remove the broken wire.

 


Intelligent wrote:

One interesting thing that i want to share is that when the data is received it is seen as the complete measurement on the String Read on the first cycle. And i dont know its reason.


 

Obviously, you are reading all bytes in the first read as I thought. How many bytes are on the port at the first iteration?

 

Remember, you are reading all bytes at the port, not just a single byte with each iteration. With each read, you are throwing away all bytes except the first. Your code so far is highly flawed!

 

 

0 Kudos
Message 5 of 9
(5,286 Views)

The array is of four complete values. This means that in each cycle one complete ASCII value is obtained.

Strange but interesting. 

0 Kudos
Message 6 of 9
(5,270 Views)
Solution
Accepted by topic author Getwonder

it simply changed by format into string conversion.

Thanks for you guidence

0 Kudos
Message 7 of 9
(5,265 Views)

The thing strange for me is that how a complete set of data is send while there is specific representation for each character in ASCII form. Anyone who has the idea of it. The data is send from 8051 and received on COM Port of the PC.

0 Kudos
Message 8 of 9
(5,249 Views)

 


@Intelligent wrote:

The thing strange for me is that how a complete set of data is send while there is specific representation for each character in ASCII form. Anyone who has the idea of it. The data is send from 8051 and received on COM Port of the PC.


Why is that strange?  What else do you expect???

 

 

You never specify to read a single character, else you would wire a "1" to the serial read count. Whenever you read, there are 5 bytes available and that's what you read. No need to jump through flaming hoops.

 

So, get rid of the inner FOR loop and simply take a serial reading, then use "scan from string" to get the number into an orange wire for further processing if needed. 🙂

 

You should also not mark your own comment as solution, it is NOT! Whatever you have marked now is not the solution to the original question and actually contains virtually no information that would help somebody in the future with a similar problem. So please un-mark your solution and mark the post that that best solved the problem as solution. Thanks!

Message 9 of 9
(5,237 Views)