Example #1
0
 public OutputTCBase(Protocol protocol, string devicename, string ip, int port, int deviceid, byte[] hw_status, bool isconnected )
     : base(protocol, devicename, ip, port, deviceid, hw_status,  isconnected)
 {
     tmrCheckOutput = new System.Timers.Timer(outputCompareMin*1000 * 60);
     tmrCheckOutput.Elapsed += new System.Timers.ElapsedEventHandler(tmrCheckOutput_Elapsed);
     tmrCheckOutput.Start();
 }
Example #2
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)
                {
                    ;
                }
            }
        }
Example #3
0
        System.Timers.Timer tmrCheckConnectTimeOut = new System.Timers.Timer(1000 * 2 * 60); //2 min

        #endregion Fields

        #region Constructors

        public TCBase(Protocol protocol,string devicename,string ip, int port, int deviceid,byte[]hw_status,byte opmode,byte opstatus,byte comm_state)
        {
            m_ip = ip;
            m_port = port;
            m_deviceid = deviceid;
            this.m_protocol = protocol;
            this.m_deviceName = devicename;
            this.m_hwstaus = hw_status;
            this.m_opmode = opmode;
            this.m_opstatus = opstatus;
            this.m_comm_state = comm_state;

            this.OnTCPConnectChange += new ConnectStatusChangeHandler(OnTcpConnectChanged);
            this._OnConnectStatusChanged += new ConnectStatusChangeHandler(TC_OnConnectStatusChanged);

            start_connect();
            OneMinTimer = new System.Timers.Timer(1000 *30);
            OneMinTimer.Elapsed += new System.Timers.ElapsedEventHandler(OneMinTimer_Elapsed);
            OneMinTimer.Start();
            OneHourTimer = new System.Timers.Timer(1000 * 60 * 60);
            OneHourTimer.Elapsed += new System.Timers.ElapsedEventHandler(OneHourTimer_Elapsed);
            OneHourTimer.Start();

            new System.Threading.Thread(ReportProcessTask).Start();
            LastReceiveTime = System.DateTime.Now;
        }
Example #4
0
        internal ScriptsManager()
        {
            try
                    {
                string scriptpath = Comm.Util.CPath(AppDomain.CurrentDomain.BaseDirectory + @"Scripts");
                string[] files = System.IO.Directory.GetFiles(scriptpath);
                protocols = new Protocol[files.Length];
                for (int i = 0; i < protocols.Length; i++)
                {

                        protocols[i] = new Protocol();
                        try
                        {
                            protocols[i].Parse(System.IO.File.ReadAllText(files[i]), false);
                        }
                        catch (Exception ex)
                        {
                            ConsoleServer.WriteLine(files[i] + "數位簽章不符!"); //write into error log
                        }
                        if (protocols[i].Enabled)
                        {
                            protocolhash.Add(protocols[i].DeviceType, protocols[i]);
                        }
                    }

                }
                catch (Exception ex)
                {

                    Console.WriteLine(ex.Message + "," + ex.StackTrace);
                }
        }
Example #5
0
        public CMSTC(Protocol protocol, string devicename, string ip, int port, int deviceid, byte[] hw_status, byte opmode, byte opstatus, byte comm_state)
            : base(protocol, devicename, ip, port, deviceid, hw_status, opmode, opstatus,comm_state)
        {
            this.OnTCReport += new OnTCReportHandler(CMSTC_OnTCReport);
               this.OnTCReceiveText += new OnTCReportHandler(CMSTC_OnTCReceiveText);
             //  this.m_device.OnReceiveText += new OnTextPackageEventHandler(m_device_OnReceiveText);
            System.Data.Odbc.OdbcConnection cn = new System.Data.Odbc.OdbcConnection(Comm.DB2.Db2.db2ConnectionStr);
            System.Data.Odbc.OdbcCommand cmd = new System.Data.Odbc.OdbcCommand("select show_icon,CRmode from tblCmsConfig where DeviceName='" + this.DeviceName + "'");
            cmd.Connection = cn;

            try
            {

                cn.Open();
                System.Data.Odbc.OdbcDataReader rd = cmd.ExecuteReader();
                if (rd.Read())
                {
                    isIcon = (System.Convert.ToInt32(rd[0])==0)?false:true;
                    CrMode = System.Convert.ToInt32(rd[1]);
                }
                rd.Close();

            }
            catch (Exception ex)
            {
                ConsoleServer.WriteLine(ex.Message + ex.StackTrace);
            }
            finally
            {
                cn.Close();
            }
        }
Example #6
0
        public static void RGS_Test_Task()
        {
            Protocol protocol=new Protocol();
            protocol.Parse(System.IO.File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory+"protocol.txt"));
            Comm.TC.RGSTC tc = new Comm.TC.RGSTC(protocol, "RGSTest", "59.120.20.153", 4660,0xffff, new byte[] { 0, 0, 0, 0 },0,0,0);
            // Comm.TC.RGSTC tc = (Comm.TC.RGSTC)this.manager["RGS232"];

            while (!tc.IsConnected) ;
            tc.m_device.OnAck += new OnAckEventHandler(m_device_OnAck);
            tc.m_device.OnSendingPackage += new OnSendPackgaeHandler(m_device_OnSendingPackage);
            tc.m_device.OnReceiveText += new OnTextPackageEventHandler(m_device_OnReceiveText);
            while (true)
            {

                System.Drawing.Color[][] color;
                color = new System.Drawing.Color[1][];
                color[0] = new System.Drawing.Color[4] { System.Drawing.Color.Red, System.Drawing.Color.Red, System.Drawing.Color.Red, System.Drawing.Color.Red };
                try
                {
                    if (tc.IsConnected)
                        tc.SetTravelDisplay(new byte[0], new string[] { "系統測試" }, color);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Example #7
0
 public RGSTC(Protocol protocol, string devicename, string ip, int port, int deviceid, byte[] hw_status, byte opmode, byte opstatus, byte comm_state)
     : base(protocol, devicename, ip, port, deviceid, hw_status,opmode,opstatus,comm_state)
 {
     this.OnTCReport += new OnTCReportHandler(RGSTC_OnTCReport);
        this.OnTCReceiveText += new OnTCReportHandler(RGSTC_OnTCReceiveText);
        this.OnConnectStatusChanged += new ConnectStatusChangeHandler(RGSTC_OnConnectStatusChanged);
        //this.OnConnectStatusChanged += new ConnectStatusChangeHandler(RGSTC_OnConnectStatusChanged);
 }
Example #8
0
        public CommWin()
        {
            InitializeComponent();

            _state = State.IDLE;
            _wrap = new SocketWrap(Connected, Accepted, Received, Disconnected, Error);
            _proto = new Protocol(ReceivedMessage);

            UpdateCtrls();
            this.Show();
        }
Example #9
0
 public TCBase(Protocol protocol,string devicename,string ip, int port, int deviceid)
 {
     m_ip = ip;
     m_port = port;
     m_deviceid = deviceid;
     this.m_protocol = protocol;
     this.m_deviceName = devicename;
     this._OnConnectStatusChanged += new ConnectStatusChangeHandler(TC_OnConnectStatusChanged);
       //  th_1_min_task=new System.Threading.Thread(inTask);
     start_connect();
     OneMinTimer = new System.Timers.Timer(1000 * 60);
     OneMinTimer.Elapsed += new System.Timers.ElapsedEventHandler(OneMinTimer_Elapsed);
     OneMinTimer.Start();
     OneHourTimer = new System.Timers.Timer(1000 * 60 * 60);
     OneHourTimer.Elapsed += new System.Timers.ElapsedEventHandler(OneHourTimer_Elapsed);
 }
Example #10
0
        public RGSTC(Protocol protocol, string devicename, string ip, int port, int deviceid)
            : base(protocol, devicename,ip, port, deviceid)
        {
            //m_protocol = protocol;
               //m_deviceName = devicename;
              // this.deviceid = deviceid;
               //System.Net.WebRequest req = System.Net.HttpWebRequest.Create(QYTask.Settings1.Default.TIMCC_uri);

               //System.IO.Stream stream = req.GetResponse().GetResponseStream();
               //System.IO.TextReader rd = new System.IO.StreamReader(stream);
               //System.IO.TextWriter wr = new System.IO.StreamWriter("tmp.xml");
               //wr.Write(rd.ReadToEnd());
               //wr.Flush();
               //wr.Close();
               //rd.Close();
               //stream.Close();

               new System.Threading.Thread(CheckGenericDisplayTask).Start();
        }
Example #11
0
        public void VD_Test()
        {
            string src = System.IO.File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "protocol.txt");
            Comm.Protocol protocol = new Comm.Protocol();
            protocol.Parse(src);
            Comm.TC.VDTC vdtc = new Comm.TC.VDTC(protocol, "vd231", "192.168.22.231", 1001, 0xffff, new byte[] { 0, 0, 0, 0 },0,0,0);
            while (!vdtc.IsConnected)
                System.Threading.Thread.Sleep(1000);

             vdtc.m_device.OnTextSending += new Comm.OnSendingAckNakHandler(m_device_OnTextSending);
            vdtc.m_device.OnSendingPackage += new Comm.OnSendPackgaeHandler(m_device_OnSendingPackage);
            vdtc.m_device.OnReceiveText += new Comm.OnTextPackageEventHandler(m_device_OnReceiveText);
            vdtc.m_device.OnBeforeAck += new Comm.OnSendingAckNakHandler(m_device_OnBeforeAck);
            vdtc.m_device.OnAck += new Comm.OnAckEventHandler(m_device_OnAck);
            //  vdtc.m_device.

            while (true)
            {
                Console.ReadKey();
                vdtc.SetRealData(3, 0, 1);
                Console.ReadKey();
                vdtc.SetRealData(0, 0, 1);
            }
        }
Example #12
0
 static void AVITCTest()
 {
     Protocol protocol = new Protocol();
     protocol.Parse(getProtocolStr("AVI"));
       //  Comm.TC.AVITC tc = new Comm.TC.AVITC(protocol, "test", "192.168.90.227", 1001, 0xffff, new byte[] { 0, 0, 0, 0 }, 0, 0);
 }
Example #13
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));
                    }

                }

            }
        }
Example #14
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));
            //}
        }
Example #15
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);
        }
Example #16
0
        static void SCM_Test()
        {
            Protocol protocol=new Protocol();
            protocol.Parse(System.IO.File.ReadAllText("SCM-20100226.txt"),false);

            Comm.TC.SCMTC scm=new Comm.TC.SCMTC(protocol,"SCM","10.21.50.221",1001,0xffff,new byte[]{0,0,0,0},0,0,0);
             Console.ReadKey();
        }
Example #17
0
 static void RMSTCTest()
 {
     Protocol protocol=new Protocol();
     protocol.Parse(getProtocolStr("RMS"));
       //  Comm.TC.RMSTC tc = new Comm.TC.RMSTC(protocol, "test", "10.21.63.130", 1001, 0xffff, new byte[] { 0, 0, 0, 0 }, 0, 0);
 }
Example #18
0
 public RGSTC(Protocol protocol, string devicename, string ip, int port, int deviceid, byte[] hw_status, byte opmode, byte opstatus, byte comm_state)
     : base(protocol, devicename, ip, port, deviceid, hw_status,opmode,opstatus,comm_state)
 {
     this.OnTCReport += new OnTCReportHandler(RGSTC_OnTCReport);
 }
Example #19
0
 public Cmd(Protocol protocol)
 {
     this.protocol = protocol;
 }