Exemple #1
0
        //static void dev_OnReceiveText(object sender, TextPackage txtObj)
        //{
        //    //throw new NotImplementedException();
        //}
        static void Set_Pilt_Param()
        {
            System.IO.MemoryStream ms=new System.IO.MemoryStream();
               System.Net.Sockets.TcpClient client=new System.Net.Sockets.TcpClient();
            client.Connect("127.0.0.1",1002);

            DeviceV2DLE dev = new DeviceV2DLE("PILT", client.GetStream());
            uint port_baud=115200;
            byte[] data ;
            ms.WriteByte(0x20);
            ms.WriteByte(1);
            ms.WriteByte(1); //id
            ms.WriteByte(0);  //tcp/com
            ms.WriteByte(4);
            ms.WriteByte(0);
             ms.WriteByte(0);
             ms.WriteByte(0);
             byte[] bdata = System.BitConverter.GetBytes(port_baud);
             for(int i=bdata.Length-1;i>=0;i--)
                 ms.WriteByte(bdata[i]);
             data = ms.ToArray();
            dev.Send(new SendPackage( CmdType.CmdSet, CmdClass.A,0xffff,data));

               // System.Data.DataSet ds;
            //byte[] data = new byte[]
            //{ 0x01,1,0,4,0,0,0
        }
Exemple #2
0
        static void get_Pilt_Param()
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
            client.Connect("127.0.0.1", 1002);
            DeviceV2DLE dev = new DeviceV2DLE("PILT", client.GetStream());
               // dev.OnReceiveText += new OnTextPackageEventHandler(dev_OnReceiveText);
            byte[] data = new byte[] { 0x04, 0x20 };
            SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, 0xffff, data);

            dev.Send(pkg);
            Console.WriteLine(Comm.V2DLE.ToHexString(pkg.ReturnTextPackage.Text));
        }
Exemple #3
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);
        }
Exemple #4
0
        static void get_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());
            dev.OnReceiveText += new OnTextPackageEventHandler(dev_OnReceiveText);
            //while (true)
            //{
                SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, 0xffff,
                    new byte[] { 0x04, 0x21 });
                dev.Send(pkg);

                Console.WriteLine(V2DLE.ToHexString(pkg.ReturnTextPackage.Text));
            //}
        }
Exemple #5
0
        static void GetTileConfig()
        {
            ControllerConfigBase config;
            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[] { 0x04, 0x20 };

            Comm.SendPackage pkg = new SendPackage(CmdType.CmdQuery, 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);
            System.IO.MemoryStream ms = new System.IO.MemoryStream(pkg.ReturnTextPackage.Text, 10, pkg.ReturnTextPackage.Text.Length - 10);
               // string str = System.Text.UTF8Encoding.UTF8.GetString(ms.GetBuffer());
               // Console.WriteLine(str);
             config = ser.Deserialize(ms) as ControllerConfigBase;
            Console.WriteLine(config.build_date+"finish!");
        }
Exemple #6
0
        //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));
                    }

                }

            }
        }
Exemple #7
0
 void v2dle_OnCommError(object sender, Exception ex)
 {
     v2dle.OnReceiveText -= v2dle_OnReceiveText;
     v2dle.OnCommError -= v2dle_OnCommError;
     v2dle.Close();
     Console.WriteLine("Dispose V2dle!");
     v2dle = null;
     lock (lockobj)
     {
         System.Threading.Monitor.Pulse(lockobj);
     }
 }
Exemple #8
0
        void ListenTask()
        {
            System.Net.Sockets.TcpListener listener=null;
            System.Net.Sockets.TcpClient client;
            while (true)
            {
                try
                {
                    if (listener == null)
                    {
                        listener = new System.Net.Sockets.TcpListener(System.Net.IPAddress.Any,ListenPort);
                        Console.WriteLine("listen:" + ListenPort);
                        listener.Start();
                    }

                    client = listener.AcceptTcpClient();
                    Console.WriteLine("=================Accept connection!================");
                    v2dle = new DeviceV2DLE("client", client.GetStream());
                    v2dle.OnReceiveText += new OnTextPackageEventHandler(v2dle_OnReceiveText);
                    v2dle.OnCommError += new OnCommErrHandler(v2dle_OnCommError);
                    lock (lockobj)
                    {
                        System.Threading.Monitor.Wait(lockobj);
                    }
                }
                catch {

                    System.Threading.Thread.Sleep(1000);
                    ;}

            }
        }