static void Main(string[] args) { Protocol protocol; string ip; int port; V2DLE dle; System.Net.Sockets.TcpClient tcp; protocol = new Protocol(); protocol.Parse(System.IO.File.ReadAllText(Protocol.CPath(AppDomain.CurrentDomain.BaseDirectory+"TIME.txt")),false); ip = protocol.ip; port = protocol.port; while (true) { try { bool isCommErr = false; tcp = new System.Net.Sockets.TcpClient(); tcp = ConnectTask(ip, port); dle = new V2DLE("DigitTimer", tcp.GetStream()); dle.OnCommError+=(s,a)=> { isCommErr = true; dle.Close(); }; while (!isCommErr) { System.Data.DataSet ds = protocol.GetSendDataSet("report_system_time"); SendPackage pkg = protocol.GetSendPackage(ds, 0xffff); pkg.cls = CmdClass.A; dle.Send(pkg); if (pkg.result == CmdResult.ACK) { System.Data.DataSet retDs = protocol.GetReturnDsByTextPackage(pkg.ReturnTextPackage); int yr,mon,dy,hr,min,sec; yr=System.Convert.ToInt32(retDs.Tables[0].Rows[0]["year"]); mon = System.Convert.ToInt32(retDs.Tables[0].Rows[0]["month"]); dy = System.Convert.ToInt32(retDs.Tables[0].Rows[0]["day"]); hr = System.Convert.ToInt32(retDs.Tables[0].Rows[0]["hour"]); min = System.Convert.ToInt32(retDs.Tables[0].Rows[0]["minute"]); sec = System.Convert.ToInt32(retDs.Tables[0].Rows[0]["second"]); DateTime dt = new DateTime(yr, mon, dy, hr, min, sec); Console.WriteLine(dt.ToString()); RemoteInterface.Util.SetSysTime(dt); } else { Console.WriteLine(pkg.result.ToString()); } System.Threading.Thread.Sleep(1000 * 60 ); } } catch (Exception ex) { ; } } }
//static void TiltConfig() //{ // ControllerConfigBase config = new ControllerConfigBase() // { // build_date = DateTime.Now, // controller_id = 0x0000, // device_type = "Tilt", // listen_port = 1002, // version_no = 1 , // sensors = new TiltSensorConfig[] // { // new TiltSensorConfig() // { // com_type="COM", // device_name="TILE1", // id=0, // execution_mode=0, // port_baud=115200, // ip_comport="COM7", // sensor_values=new SensorValueConfigBase[]{ // new SensorValueConfigBase() // { // coefficient=1, // offset=0, // desc="X", // id=0, // rules=new SensorValueRuleConfigBase[] // { // new SensorValueRuleConfigBase() // { // level=1, // lower_limit=0, // upper_limit=0, // hour_ma=0, // left_hour_ma1=0, // left_hour_ma2 =0, // right_hour_ma1=0, // right_hour_ma2=0 // }, // new SensorValueRuleConfigBase() // { // level=2, // lower_limit=0, // upper_limit=0, // hour_ma=0, // left_hour_ma1=0, // left_hour_ma2 =0, // right_hour_ma1=0, // right_hour_ma2=0 // }, // new SensorValueRuleConfigBase() // { // level=3, // lower_limit=0, // upper_limit=0, // hour_ma=0, // left_hour_ma1=0, // left_hour_ma2 =0, // right_hour_ma1=0, // right_hour_ma2=0 // } // } // }, // new SensorValueConfigBase() // { // coefficient=1, // offset=0, // desc="Y", // id=1, // rules=new SensorValueRuleConfigBase[] // { // new SensorValueRuleConfigBase() // { // level=1, // lower_limit=0, // upper_limit=0, // hour_ma=0, // left_hour_ma1=0, // left_hour_ma2 =0, // right_hour_ma1=0, // right_hour_ma2=0 // }, // new SensorValueRuleConfigBase() // { // level=2, // lower_limit=0, // upper_limit=0, // hour_ma=0, // left_hour_ma1=0, // left_hour_ma2 =0, // right_hour_ma1=0, // right_hour_ma2=0 // }, // new SensorValueRuleConfigBase() // { // level=3, // lower_limit=0, // upper_limit=0, // hour_ma=0, // left_hour_ma1=0, // left_hour_ma2 =0, // right_hour_ma1=0, // right_hour_ma2=0 // } // } // } // } // } // } // }; // System.Xml.Serialization.XmlSerializer ser = new XmlSerializer(typeof(ControllerConfigBase)); // System.IO.MemoryStream ms=new System.IO.MemoryStream(); // ser.Serialize(ms, config); // byte[] data =new byte[ms.Length+3]; // data[0]=0x20; // data[1]=(byte)(ms.Length/256); // data[2]=(byte)(ms.Length%256); // System.Array.Copy(ms.GetBuffer(),0,data,3,ms.Length); // Comm.SendPackage pkg = new SendPackage(CmdType.CmdSet, CmdClass.A,0xffff, data); // System.Net.Sockets.TcpClient client=new System.Net.Sockets.TcpClient(); // client.Connect("127.0.0.1",1002); // DeviceV2DLE dle = new DeviceV2DLE("tile", client.GetStream()); // dle.Send(pkg); //} static void GetPeriodData() { Protocol protocol = new Protocol(); protocol.Parse(System.IO.File.ReadAllText("PILT.txt"), false); System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient(); client.Connect("127.0.0.1", 1001); DeviceV2DLE dev = new DeviceV2DLE("PILT", client.GetStream()); dev.OnReceiveText += new OnTextPackageEventHandler(dev_OnReceiveText); //while (true) //{ for (byte hour = 0; hour < 23; hour++) { for (byte min = 0; min < 60; min++) { SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, 0xffff, new byte[] { 0x28, 12, hour, min }); dev.Send(pkg); if (pkg.ReturnTextPackage != null) { System.Data.DataSet ds = protocol.GetReturnDsByTextPackage(pkg.ReturnTextPackage); if (Convert.ToInt32(ds.Tables[0].Rows[0]["sensor_cnt"]) == 0) { Console.WriteLine("Not Found"); } else Console.WriteLine(V2DLE.ToHexString(pkg.ReturnTextPackage.Text)); } } } }