LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, How would I change a wire from a character (%s) to double(%d)

I'm not sure how to use the polymorphic property. I am using the INSERT INTO ARRAY vi. Thanks!
0 Kudos
Message 1 of 14
(3,321 Views)
Can you use the scan from string.vi ??
0 Kudos
Message 2 of 14
(3,321 Views)
We have a mismatch here. A character is 1 byte, and a double is 8 bytes. %d stands for decimal interger, and is also a string and has very little to do with DBL representation.

In summary, a %s to %d conversion does not exist, they are both strings. The wire does not change, but the data might be meaningless in the context.

Do you possibly want a numeric DBL output? It is still not clear what your %s "string" represents. Is is
(a) an ASCII formatted value of a double precision numberic (e.g. 1.23E5)... (-->Use e.g. "Fract/Exp String to number" in the "string..String/number Conversion" palette)
(b)a string containing flattened data, 8 bytes/double? (--> use typecast).
(c) something else ...

What polymorphic property are you talking about? Co
uld you attach a small example of your code to make your question more clear? Thanks!
0 Kudos
Message 3 of 14
(3,321 Views)
Thanks,
My input is numbers in ASCII format (string) and I would like to use them in calculations, so I feel that I need to convert them into a usable format. I am also having a lot of trouble with the dimensions of my vi. Can you tell what my mistake is, or do you need more clarification?
Thank you!
Ivanka
0 Kudos
Message 4 of 14
(3,321 Views)
I also forgot to mention that The input is read from the serial port in same form as the constant input in this file.
0 Kudos
Message 5 of 14
(3,321 Views)


Howdy,

See attached diagram. It shows how you can extract numbers from your string. We first replace all the single and multiple occurences of "\s" with a single "\t" (doesn't have to be "\t"; it can be anything). Then we use the 'Spreadsheet String To Array' function passing the "\t" as the delimiter to obtain an array of numbers.

I hope this is what you wanted.

Note that if you want a single-dimension array, just wire-in a single-dimension array contsant to the 'Spreadsheet String To Array' function.

Khalid

0 Kudos
Message 6 of 14
(3,321 Views)
OK, your example has the following problems:

(1) your string is apparently formatted as "'\'codes", in a normal display. For correct behavior, you should use your raw string as obtained from the device, then right-click and select "'\' codes". I took the liberty to correct your string in the attached example.

(2) I have no idea why you need a 5x5 2D array for your 6 numbers. Why not just create a 1D array of 6 integers? Frankly, I don't understand any of the code inside your FOR loop.

I suggest to use something like the attached example. It simply extracts all the integers and puts them in a 1D array for further processing. (If there is a possibility that the data also contains fractional numbers, use "Fract/exp string to number" and create a D
BL array instead.). Let me know if my code makes sense to you.
0 Kudos
Message 7 of 14
(3,321 Views)
Thanks, I think your program will help with the conversion of the data to usable data. I am still confused about the dimensions of the arrays and adding new strings to the 2D array( built of 1D arrays of the elements of the string) I have commented my program, so hopefully that will explain to you my thought process.
0 Kudos
Message 8 of 14
(3,321 Views)
OK, some questions remain:

-- Is "n" (the number of reads) known in advance?
-- Your string has only 6 numbers, but you need seven.
-- Do you really need the first column to be 1,2,3,4,5,6,7?
-- Why a 5x5 array??

There are several ways to do this. If N is not known at the beginning, you need to append each new row to the existing array.

If N is known, you can initialize a 2D array at the final size. In this case you would use "replace array subset", keeping the array size constant. This is more efficient.

(You were using "Insert into array" which actually adds colums, thus growing the array and making the earlier preallocation of the 2D array pointless.)

I have attached a quick demo that shows suggested code for each v
ersion. Just run it and press stop after a while. I have also modified the string to produce 7 integers.

In your case you would need to get a new string from the device in each iteration. Modify as required. Good luck!
0 Kudos
Message 9 of 14
(3,321 Views)
thanks for your reply. I used the build an array vi and everything worked. The point of my program to this point was to collect an infinite number of number strings from a serial port, and format them into a numeric form so that I could do some analysis with the numbers. Now that I am able to do this, how can I access the seperate values in the array. I know in C we say Array[x][y] to access specific values. How would I do this in LV? Thanks so much for your help! I really appreciate it!
0 Kudos
Message 10 of 14
(3,321 Views)