LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String to number conversion

Hi guys, I am new on labview and I need your help. I need to convert a string in a number, but I am acquiring data continuously and when I do the conversion I only obtain the first number of that string. Instead I have to acquire all the numbers, or better only the last or the last five, in such a way I could do an average (also I don't know how to do it) between these ones and obtain the value to put in pid control.

This because I am acquiring the value of the thermocouple, and when I run the program in the string I visualize continuously the value, but for the number I visualize only the first value, and it doesn't change anymore.

How can I do it? Thanks, Vincenzo

 

0 Kudos
Message 1 of 8
(4,254 Views)

Here is a simple method for extracting the last 5 values in an array and averaging them.  If you provide some code we can help choose the best method of this.

 

array average.png



-Matt
0 Kudos
Message 2 of 8
(4,241 Views)

Do you mean you have one string that includes several numeric values? If so what is the separation character? Tab? Comma?

 

What could really help is, if you could post your code with representative data, so for example with your string(s) saved as default on the front panel or added as constant on the diagram. That way we can track down what you are doing and may be able to help you.

 

Without, this thread could become an extended exchange of guessing.

0 Kudos
Message 3 of 8
(4,237 Views)

@fantalotto wrote:

Hi guys, I am new on labview and I need your help.  


OK, lets start with the first lesson: If something does not work correctly, you need to attach your code (or a simplified version that still shows the problem).

 

Typically, if an indicator does not update, it is not in the dataflow (e.g. outside the loop).

 

Show us a typical string. How does the word "continuously" fit into all that? Does the string grow with time without bounds? Do you convert each string to a numeric and grow an array without bounds? (both are bad ideas, because untilmately you will run out of memory! :D)

To average the last 5 values (these need to be numeric, you cannot average strings!), you can use the "mean ptbypt" with a history lenght of 5 or you could roll your own.

 

0 Kudos
Message 4 of 8
(4,226 Views)

I describe my sistem: I have a generator of current, connected to a metal. A thermocouple , connected to an arduino nano, measure the temperature of the metal. I also have a national instruments NI 6009 usb, to control the output of the system. So I have to measure the real time value of the thermocouple, and I can do it, but I obtain a string. When I try to convert the string to the number, to put it in as the variable process of pid control, only the first value is converted to number, so I can't control the system because for him the temperature is costant and equal to the first value of the string, until I stop the program and I run it again. Instead the values of the string are always changing because the temperature is changing. 

I attached the vi and a photos.

I hope I was clear, thank you again

Download All
0 Kudos
Message 5 of 8
(4,197 Views)

You are growing the string without limits, but the numeric indicator only sees the first value of the string. Maybe you want to wire from the visa-read string output instead. That's where the latest value is.

Convert each read to a number and use mean ptbypt to get the average of the last N values before processing.

I also assume that the reading is a floating point value. Why are you scanning it as an integer?

0 Kudos
Message 6 of 8
(4,185 Views)

You are growing the string without limits, but the numeric indicator only sees the first value of the string..

 

How to keep updating value on coming of every new value..??

 

@altenbach...

0 Kudos
Message 7 of 8
(2,485 Views)

Is there a reason that you are concatenating all of your values together? Do you really just want the current value? Just wire the value directly out from your read to the converter. As others have said you may want to consider the conversion that you're making as the string likely contains a floating point number, not an integer. We can't tell that because you did not save your vi with any default data.

0 Kudos
Message 8 of 8
(2,464 Views)