//This shows the current sample of 'FIC101.Value' in the console var CurrentSample= OP.Tag("FIC101.Value").Sample; OP.Log("Current Sample Value is = " + CurrentSample.Value); OP.Log("Current Sample Time is = " + CurrentSample.TSUTC.ToLocalTime());
//This shows the last known value of 'FIC101.Value' in the console var LastKnownValue = OP.Tag("FIC101.Value").Value; OP.Log(LastKnownValue); //This shows the current sample of 'FIC101.Value' in the console var LastKnownSample = OP.Tag("FIC101.Value").LastSample; OP.Log("Last known sample Value is = " + LastKnownSample.Value); OP.Log("Last known sample Time is = " + LastKnownSample.TSUTC);
//This shows the first sample of 'FIC101.Value' in the console var FirstSample = OP.Tag("FIC101.Value").FirstSample; OP.Log("First Sample Value is = " + CurrentSample.Value); OP.Log("First Sample Time is = " + CurrentSample.TSUTC);
var SpotSample1 = OP.Tag("FIC101.Value").SpotSample(DateTime.UtcNow); OP.Log("Sample1 Value = " + SpotSample1.Value); //The specified date must be in UTC var SpotSample2 = OP.Tag("FIC101.Value").SpotSample("2020-06-18 20:02:00"); OP.Log("Sample2 Value = " + SpotSample2.Value); var SpotSample3 = OP.Tag("FIC101.Value").SpotSample("Now"); OP.Log("Sample3 Value = " + SpotSample3.Value); var SpotSample4 = OP.Tag("FIC101.Value").SpotSample("Now-1Hour"); OP.Log("Sample4 Value = " + SpotSample4.Value); var SpotSample5 = OP.Tag("FIC101.Value").SpotSample("Now-5Day"); OP.Log("Sample5 Value = " + SpotSample5.Value); var SpotSample6 = OP.Tag("FIC101.Value").SpotSample("Now-10Minute"); OP.Log("Sample6 Value = " + SpotSample6.Value); //The specified date is in local time but it is converted to UniversalTime var SpotSample7 = OP.Tag("FIC101.Value").SpotSample((new DateTime(2020,6,18,10,2,0)).ToUniversalTime()); OP.Log("Sample7 Value = " + SpotSample7.Value);
//This list all samples in the last hour for FIC101.Value. //Since interval is not specified and the duration is less than 24 hours, it defaults to 1 minute or 60000ms. ListSamples = OP.Tag("FIC101.Value").Samples("Now-1Hour","Now"); OP.Log("Number of Samples = " + Samples.Count); foreach (Sample S in Samples) { OP.Log("Sample time: " + S.TSUTC.ToLocalTime() + ", Value: " + S.Value); }
//This list all the samples in the last hour ListSamples = OP.Tag("FIC101.Value").Samples(DateTime.UtcNow.AddMinutes(-60),DateTime.UtcNow,30000); OP.Log("Number of Samples = " + Samples.Count); foreach (Sample S in Samples) { OP.Log("Sample time: " + S.TSUTC.ToLocalTime() + ", Value: " + S.Value); }
//This lists all raw samples in the last 10 minutes for FIC101.Value. //Since interval is not specified, it will return all existing samples in the database between this period //Open-Plant enforces a soft limit of 100,000 samples returned to avoid overloading the system. //This limit can be disabled, see the other examples ListRawSamples = OP.Tag("FIC101.Value").RawSamples("Now-10minutes","Now"); foreach (Sample S in RawSamples) { OP.Log("Sample time: " + S.TSUTC.ToLocalTime() + ", Value: " + S.Value); } OP.Log("Number of Raw Samples = " + RawSamples.Count);
//This lists all raw samples in the last 10 minutes for FIC101.Value. //Interval is set as 30s, which mean it will only return a raw sample every 30s //This variant also uses dateTime input rather than the timestamp semantic ListRawSamples = OP.Tag("FIC101.Value").RawSamples(DateTime.UtcNow.AddHours(-1),DateTime.UtcNow,30000); foreach (Sample S in RawSamples) { OP.Log("Sample time: " + S.TSUTC.ToLocalTime() + ", Value: " + S.Value); } OP.Log("Number of Raw Samples = " + RawSamples.Count);
//This lists all raw samples in the last 3 days for FIC101.Value. //Interval is set as 1s, which mean it will return a raw sample every second //The soft limit of 100,000 is disabled here by setting the last input parameter as false ListRawSamples = OP.Tag("FIC101.Value").RawSamples("Now-3day","Now",1000, false); foreach (Sample S in RawSamples) { OP.Log("Sample time: " + S.TSUTC.ToLocalTime() + ", Value: " + S.Value); } OP.Log("Number of Raw Samples = " + RawSamples.Count);
//This writes the value 10 to FIC101.Value at the current time OP.InsertSample("FIC101.Value",10); //This writes the value 10 to FIC101.Value at the current time. It is same as above OP.InsertSample("FIC101.Value",10, DateTime.UtcNow); //This writes the value 10 to FIC101.Value at 3rd Sept 2019 3:00:00PM OP.InsertSample("FIC101.Value",10, "2019-09-03 15:00:00"); //This writes the value 10 to FIC101.Value at 3rd Sept 2019 3:00:00PM, 250milisecond OP.InsertSample("FIC101.Value",10, "2019-03 15:00:00.250");
//This generates a table of value from the last 30minutes with a 60second interval for 3 Tags. The result is printed on the console OutputTable Table = OP.GetTableOfValues("Now-30mins","Now",60000,IfError.GetPreviousValue, "FIC101.Value","TIC102.Value","WIC103.Value"); //This is similar to the above, but with input specified with DateTime instead //OutputTable Table = OP.GetTableOfValues(DateTime.UtcNow.AddMinutes(-30),DateTime.UtcNow,60000,IfError.GetPreviousValue, "FIC101.Value","TIC102.Value","WIC103.Value"); foreach (OutputRow Row in Table) { //Column 0 is for Time Stamp DateTime Timestamp = ((DateTime)Row[0]).ToLocalTime(); //Column 1 is for FIC101.Value var FIC101 = Row[1]; //Column 2 is for TIC102.Value var TIC102 = Row[2]; //Column 3 is for WIC103.Value var WIC103 = Row[3]; OP.Log(Timestamp + ", FIC101=" + FIC101 + ", TIC102=" + TIC102 + ", WIC103=" + WIC103); } OP.Log("Number of Rows = " + Table.Count);