Exemplo n.º 1
0
        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)
                {
                    ;
                }
            }
        }
Exemplo n.º 2
0
        static void set_pilt_level_degree()
        {
            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", 1002);
            DeviceV2DLE dev = new DeviceV2DLE("PILT", client.GetStream());
               System.Data.DataSet ds= protocol.GetSendDataSet("set_level_degree");
               ds.Tables[0].Rows[0]["sensor_cnt"] = 1;

               System.Data.DataRow row = ds.Tables[1].NewRow();
               row["id"] = 0;
               row["init_value1"] = V2DLE.DoubleTouLong(1.1111);
               row["value1_factor"] = V2DLE.DoubleTouLong(1.1);
               row["value1_offset"] = V2DLE.DoubleTouLong(0.1);
               row["value1_level1"] =V2DLE.DoubleTouLong(1.1);
               row["value1_level2"] = V2DLE.DoubleTouLong(1.2);
               row["value1_level3"] = V2DLE.DoubleTouLong(1.3);

               row["init_value2"] = V2DLE.DoubleTouLong(2.2222);
               row["value2_factor"] =V2DLE.DoubleTouLong( 2.1);
               row["value2_offset"] =V2DLE.DoubleTouLong( 0.2);
               row["value2_level1"] = V2DLE.DoubleTouLong(2.1);
               row["value2_level2"] = V2DLE.DoubleTouLong(2.2);
               row["value2_level3"] =V2DLE.DoubleTouLong( 2.3);
               ds.Tables[1].Rows.Add(row);
               ds.AcceptChanges();
               SendPackage pkg= protocol.GetSendPackage(ds, 0xffff);
               dev.Send(pkg);
        }