how to write hundred of channels to a file


riseres

Recommended Posts

i have hundred of channels named "d1000" ,"d1001","d1002",....,"d1100"

and i want to save that last value to a file by write function but i can't do it.

in a flie will look like this number run (d1000 to d1100).

50,12,12,4543,..........,123

please do the script for me

thank you

private FileHandle = file.Open("c:\save.txt",0,1,0,0)
private run_num
private string strString
private hold
for(run_num=1000,run_num<1030,run_num++)
   strString = "d"doubletostr(run_num)"" 
   //hold = strtodouble(strString) // this line for test
   //strString = doubletostr(d1001) // this line for test
   //strString = d1001 //this line for test
   File.Write(FileHandle,strString)
endfor
file.Close(FileHandle)

Link to comment
Share on other sites

You've got the right idea but are using the wrong syntax to concatenate strings. You want:

strString = "d" + doubletostr(run_num)

then, to actually evaluate that string as if it was script you need to use the evaluate function:

File.Write(fileHandle, evaluate(strString))

Finally, don't forget to write your commas:

File.write(",")

and your carriage return outside the loop:

File.Write(chr(13) + chr(10))

Link to comment
Share on other sites

I'm not sure. But unless you want all your data to appear on one line, you need to add the carriage return and new line characters to the file. So, lets say you had only three channels. Without the CR/LF you'd get:

1,2,31,2,31,2,3

where the values are 1, 2 and 3. The CR/LF would give you:

1,2,3

1,2,3

1,2,3

Even if you expect to only have one line in the file, I'd still probably put a CR/LF at the end.

The ASCII key code for line feed is 10. The code for carriage return is 13. chr() takes an ascii key code and returns the character. So, chr(13) + chr(10) adds both a carriage return and a line feed at the end of the line. Some computers only use Linefeeds (namely Mac's) but PC's typically use both.

Link to comment
Share on other sites

write file. i have done. thank you.

but if i want to read file from above code to execute to channels that i saved

i can script and it can work(no error) , but channel can not get that value.

private FileHandle = File.Open("c:\save.txt",1,0,0,1)
private string strString
private count
private run = 0
private power
private string dd
strString = File.Read(Filehandle,10)
for(count=1000,count<1005,count++)
   ?strString
   power = strtodouble(parse(strString,doubletostr(run),","))
   ?power
   dd = "d"+doubleToStr(count)
   ?dd
   run++
   execute("dd = power")
   ?dd
endfor
file.close(filehandle)

Link to comment
Share on other sites

below this is the result

you can see the last line ?d1002 but no return

if i direct (F2) command

d1002 = 50

it work. but code not work

thankyou

,10,20,30,400,100,100,,,2,2.5,,0,5,10,,,,,,,,,,,,,,,,

NaN

d1000

NaN

,10,20,30,400,100,100,,,2,2.5,,0,5,10,,,,,,,,,,,,,,,,

10

d1001

10

,10,20,30,400,100,100,,,2,2.5,,0,5,10,,,,,,,,,,,,,,,,

20

d1002

20

,10,20,30,400,100,100,,,2,2.5,,0,5,10,,,,,,,,,,,,,,,,

30

d1003

30

,10,20,30,400,100,100,,,2,2.5,,0,5,10,,,,,,,,,,,,,,,,

400

d1004

400

?d1002

Link to comment
Share on other sites

I'm afraid again you are misunderstanding strings and using them as macros. This line:

execute("dd = power")

is simply going to set the local variable dd to the value of power, overwriting the "d"+doubleToStr(count) you put in there a few statements before. You want:

execute(dd + " = power")

that way the resulting string inside execute() looks like:

d1001 = power

not

dd = power

also, you probably should use addvalue():

execute(dd + ".addvalue(power)")

It depends on whether the channel is a Test D to A channel or not. You can only use your method with a Test D to A channel.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.