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 Tc_Test() { Comm.V2DLE dle; System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient(); client.Connect("192.192.85.40", 1001); dle = new Comm.V2DLE("test", client.GetStream()); dle.OnReceiveText += new Comm.OnTextPackageEventHandler(dev_OnReceiveText); dle.OnReport += new Comm.OnTextPackageEventHandler(dle_OnReport); // dle.Send(new Comm.SendPackage(Comm.CmdType.CmdSet, Comm.CmdClass.A,0xffff,new byte[]{0x02,11,10,1})); Comm.SendPackage pkg; while (true) { try { Console.ReadKey(); byte[] data = new byte[] { // 03, 1,60,1,10 0x0b }; pkg = new Comm.SendPackage(Comm.CmdType.CmdQuery, Comm.CmdClass.A, 0xffff, data); dle.Send(pkg); Console.WriteLine(Comm.V2DLE.ToHexString(pkg.ReturnTextPackage.Text)); } catch (Exception ex) { Console.WriteLine(ex.Message + ex.StackTrace); } } }