LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert string data obtained from serial port to double?

Solved!
Go to solution

Hi!

 

I am very new to LabView and trying to read data from an OHAUS pioneer pa-313 electronic scale through RS232 serial port. I am using the VISA. I can read the data and see it as a string on the screen but when I try to convert it to a double, it just gets the integer and decimal numbers are gone. Here is the question: What can be the problem? How can I have the decimals as well?

 

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

Use Fract/Exp String to Number instead.

 

There might be some bit of Whitespace at the beginning of that string (from the looks of a small gap there). You could try using the Trim Whitespace VI as well if the above function doesn't work. If Trim Whitespace doesn't work, then it's a different type of delimiter that you'll need to remove manually. If you right click the string indicator, you can choose to use "\" display. This will show you the whitespace character.

 

 

 

"Give me six hours to chop down a tree and I will spend the first four sharpening the axe."  - Abraham Lincoln

 

Here are some free training tools primarily focused on LabVIEW and NI hardware to help get started.

NI Learning Center

NI Getting Started

-Hardware Basics

-MyRIO Project Essentials Guide (lots of good simple circuits with links to youtube demonstrations)

-LabVEW Basics

-DAQ Application Tutorials

-cRIO Developer's Guide

Learn NI Training Resource Videos

3 Hour LabVIEW Introduction

6 Hour LabVIEW Introduction
Self Paced training for students
Self Paced training beginner to advanced, SSP Required
LabVIEW Wiki on Training

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 9
(5,439 Views)
Solution
Accepted by topic author akifyalcinkaya

What is your normal decimal point? . or , ?

 

Message 3 of 9
(5,427 Views)

Thanks for the reply!

 

I tried the Trim Whitespace VI but it didn't solve the issue. 

I also tried Fract/Exp String to Number and it gave the same result as you can see in the attachment.

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

The number in the read buffer is shown with a point decimal. Can it be different in the settings of Labview? How can it be changed? 

 

Edit: I think this is the problem. Since my OS is Turkish and Turkey use comma instead of points to separate decimals the default settings of Labview can be commas for separators. How can I change it to points?

0 Kudos
Message 5 of 9
(5,404 Views)
Solution
Accepted by topic author akifyalcinkaya

Your code should work.  2 things to check

1.  your wire is comming from the output and not offset (most likely otherwise your wire would be blue)

2.  your terminal is setup to show more than 1 significatnt digit (ie 0.133 is displayed as 0)

3.  Internationalization, the pc is setup to parse , insteds of . for decimal.  The scale is displaying a decimal but this doesnt tell us about the PC convention.

 

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 6 of 9
(5,393 Views)

Yeah, it looks like it's most likely a comma vs period issue. Try hard-coding (creating a string contant) that uses a comma instead of a period.

If that solves the conversion issue, then you need to do one of two things:

  • Figure out what setting needs to be changed to understand the periods
  • Or use a Search and Replace function on your string and replace all "." with ",". This is not preferred because you might have a period somewher else in your code that you don't want to change.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


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

I changed the country settings of Windows and restarted my pc. Now it works! Thank you all for your interest and help!

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

also if it is an internationalization issue, you can actualy specify thius in the string formater (use period is %f).

also change your string to hex display and make sure you do not have non printable characters attached to the number, this is not uncommon on scales to have other indo hiden in the return string.  it would have thrown an error on the parsing and returned 0 for the output.  if you have auto error handling off you will not know.

 

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 9 of 9
(5,362 Views)