public PHDR() { var configurationSection = GlobalAttributes.Configuration.GetSection("RTDBInfo").GetSection("PHD"); string tempIp = GlobalAttributes.Configuration.GetSection("RTDBInfo").GetSection("TempIP").Value; IConfigurationSection phdInfo = configurationSection.GetSection(tempIp); PHDServer _phdServer = new PHDServer { HostName = tempIp, UserName = phdInfo.GetSection("UserName").Value, Password = phdInfo.GetSection("Password").Value, APIVersion = SERVERVERSION.RAPI200 }; _session = new PHDHistorian { DefaultServer = _phdServer, Sampletype = SAMPLETYPE.Snapshot }; }
public PHD() { var configurationSection = GlobalAttributes.Configuration.GetSection("RTDBInfo").GetSection("PHD"); string tempIp = GlobalAttributes.Configuration.GetSection("RTDBInfo").GetSection("TempIP").Value; IConfigurationSection phdInfo = configurationSection.GetSection(tempIp); var _phdServer = new PHDServer(tempIp, SERVERVERSION.API200) { UserName = phdInfo.GetSection("UserName").Value, Password = phdInfo.GetSection("Password").Value, Port = Convert.ToInt32(phdInfo.GetSection("Port").Value), }; _log.Info($"UserName:{_phdServer.UserName}\r\nPassword:{_phdServer.Password}\r\nPort:{_phdServer.Port}"); _session = new PHDHistorian { DefaultServer = _phdServer }; }
public static void HandleRequest(TcpClient tcpclient, StreamReader reader, Dictionary <string, string> args) { string hostname; string requesttype; try { hostname = args["hostname"]; requesttype = args["type"]; // [browse, fetch, ping]: default is ping } catch (Exception e) { System.Console.Out.WriteLine("hostname argument not available: {0}", e.Message); WriteLine(tcpclient.Client, "400, Bad Request, hostname argument not available"); return; } using (PHDHistorian oPhd = new PHDHistorian()) { using (PHDServer server = new PHDServer(hostname, SERVERVERSION.RAPI200)) { if (args.ContainsKey("port") && !string.IsNullOrEmpty(args["port"])) { server.Port = int.Parse(args["port"]); } //SafeGet(args, "username", server.UserName); if (args.ContainsKey("username") && !string.IsNullOrEmpty(args["username"])) { server.UserName = args["username"]; } if (args.ContainsKey("password") && !string.IsNullOrEmpty(args["password"])) { server.Password = args["password"]; } if (args.ContainsKey("windowsuser") && !string.IsNullOrEmpty(args["windowsuser"])) { server.WindowsUsername = args["windowsuser"]; } if (args.ContainsKey("windowspwd") && !string.IsNullOrEmpty(args["windowspwd"])) { server.WindowsPassword = args["windowspwd"]; } oPhd.DefaultServer = server; if (requesttype.Equals("browse")) { Console.Out.WriteLine("start to browse ..."); Browse(args, tcpclient.Client, oPhd); } else if (requesttype.Equals("fetch")) { Console.Out.WriteLine("start to fetch ..."); Fetch(args, reader, tcpclient.Client, oPhd); } else { Console.Out.WriteLine("start to ping ..."); Ping(args, tcpclient.Client, oPhd); } } } }
static void Main() { PHDHistorian PHD = new PHDHistorian(); PHDServer DefaultServer = new PHDServer("192.168.0.4"); DefaultServer.APIVersion = SERVERVERSION.RAPI200; //DefaultServer.UserName = "******"; //DefaultServer.Password = "******"; //PutData DefaultServer.WindowsUsername = "******"; DefaultServer.WindowsPassword = "******"; PHD.DefaultServer = DefaultServer; PHD.DefaultServer.Port = 3150; string flag = "Read"; if (flag == "Read") { Double[] timestamps = null; Double[] values = null; short[] confidences = null; Tag MyTag = new Tag("RTOR.TI1237.DACA.PV"); //PHD.StartTime = "NOW-1H"; //PHD.EndTime = "NOW"; PHD.StartTime = "6/12/2020 9:00"; PHD.EndTime = "6/12/2020 10:00"; //PHD.Sampletype = SAMPLETYPE.Raw; PHD.Sampletype = SAMPLETYPE.Average; //PHD.SampleFrequency = 3600; //PHD.ReductionType = REDUCTIONTYPE.None; PHD.ReductionType = REDUCTIONTYPE.Average; PHD.ReductionFrequency = 300; PHD.FetchData(MyTag, ref timestamps, ref values, ref confidences); int count = timestamps.GetUpperBound(0); Console.WriteLine("Retrieved {0} data points", count); Console.WriteLine(); for (int i = 0; i < count; ++i) { Console.WriteLine("{0},{1},{2},{3}", i + 1, DateTime.FromOADate(timestamps[i]), values[i], confidences[i]); } //Console.WriteLine("{0},{1},{2},{3}", // count + 1, // DateTime.FromOADate(timestamps[count]), // values[count], // confidences[count]); } else if (flag == "Write") { Tag MyTag = new Tag("RTOS.TEST.PV"); float floatValue = 3; PHD.PutData(MyTag, floatValue); } PHD.Dispose(); }