Using A Variable For Selecting A Component Name


Recommended Posts

Posted

Hi, Further to my previous post. I seem to have found a solution by using the execute command

 

e.g.

 

 

 

global string Sensor = "SensorA"
 
filename = FormatDateTime("%a-%m-%Y", Systime())
   
execute("page." +Sensor+ ".Component.OldGraph.SaveToFile('C:\GraphSaves\" +Sensor+ "\" +filename+ "')")
 
Although I had to replace the " with ' in the directory path. Does this seem okay?
Posted

That was exactly what I was going to suggest.  You could have left the " and simply enclosed every thing else in '.  DAQFactory allows you to use " and ' interchangeably provided they match up (i.e. you can't do: "some string')

Posted

Further to the previous posts. Initially I set up a test program to automatically save 2 graphs every hour (note: eventually it will be 50 graphs). This seemed to work fine initially but then I noticed the 2nd graph file was failing to save.

 

I have stripped things back to basics (as per test code below) and it now seems to reliable save both files by putting the delay(10) in between. Does this make sense or do you think the problem is elsewhere?

 

//This is in a startup file

global string filename 

 

//SaveGraphSequence

while(1)
   
         filename = FormatDateTime("Min%M-Hour%H-%a-%m-%Y", Systime())
   
               
            page.sensor1.Component.MyGraph.SaveToFile("C:\HMI_DATA\GraphSaves\sensor1\" +filename)
            delay(10)
            page.sensor2.Component.MyGraph.SaveToFile("C:\HMI_DATA\GraphSaves\sensor2\" +filename)
            delay(10)        
     
        delay(600)
 
endwhile
Posted

Further to my previous post. After stopping and restarting the program the 2nd file is failing to save again? Any ideas? I am using the latest DAQFACTORY on Windows 7.

Posted

Are the two graph components actually named the same, or is that just for purposes of posting here? Have no idea if that's your saving problem but I don't believe that's a good idea (having components on different pages with the same name).

Posted

The solution I came up of putting the savetofile() in separate sequences doesn't work either. It works once and then fails when the program is stopped and restarted. The program only seems to successfully save the first graph savetofile() operation. 

Posted

It works fine for me in the example you provided.  The only thing is that I viewed both graph pages before running the sequence.  This is a requirement to properly initialize the graphs.  You have to view any graph you want to manipulate (using capture(), savetoFile(), printpdf(), through the web, etc) at least once at startup before calling these commands.  You can do this easily in script by just jumping to the page for 0.1 seconds then moving on to the next one.

Archived

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