Пример #1
0
        void establish_RMS_TC()
        {
            RMS_protocol.Parse(System.IO.File.ReadAllText(Util.CPath(AppDomain.CurrentDomain.BaseDirectory+"RMS.txt")), false);
              lock (QYTask.Program.RMSConfDs.tblRmsConfig)
              {

              foreach (QYTask.Ds.tblRmsConfigRow r in Program.RMSConfDs.tblRmsConfig.Rows)
              {
                  Comm.TC.RMSTC tc = new Comm.TC.RMSTC(RMS_protocol, r.rms_name, r.ip, (int)r.port, 0xffff);
                  //AD HWSTATUS EVENT HERE!
                  tc.OnConnectStatusChanged += new Comm.ConnectStatusChangeHandler(tc_OnConnectStatusChanged);
                  tc.OnHwStatusChanged += new Comm.HWStatusChangeHandler(tc_OnHwStatusChanged);
                  RMS_tcs.Add(r.ip, tc);

              }
              }
        }
Пример #2
0
        public void AddDevice(string devName)
        {
            if (this.manager.IsContains(devName))
              throw new Exception(devName + " alreay in MFCC name list!");

              System.Data.Odbc.OdbcDataReader rd=null;
              System.Data.Odbc.OdbcConnection cn = new System.Data.Odbc.OdbcConnection(Comm.DB2.Db2.db2ConnectionStr);
              //rd = Comm.DB2.Db2.getDeviceConfigReader(cn, this.mfccid);
              System.Data.Odbc.OdbcCommand cmd = new System.Data.Odbc.OdbcCommand("select devicename,ip,port ,hw_status_1,hw_status_2,hw_status_3,hw_status_4,op_mode,op_status,comm_state,IsF311z,comparison_cycle,enable from tbldeviceconfig where mfccid='" + mfccid + "'" + " and  devicename='" + devName + "'" , cn);
              Comm.TCBase tc = null;
             // this.dbServer.SendSqlCmd("update tblDeviceConfig set comm_state=3 where devicename='" + devName + "'");
              try
              {

              cmd.Connection = cn;
              cn.Open();
              rd = cmd.ExecuteReader();

              if (!rd.Read())
                  throw new Exception("can't find " + devName + "in tblDeviceConfig");

               //   ConsoleServer.WriteLine(string.Format("load tc:{0} ip:{1} port:{2}", rd[0], rd[1], rd[2]));

              byte[] hw_status = new byte[4];
              byte opmode, opstatus;
              byte comm_state;
              bool enable;
              for (int i = 0; i < 4; i++)
              hw_status[i] = System.Convert.ToByte(rd[3 + i]);
              opmode = System.Convert.ToByte(rd[7]);
              opstatus = System.Convert.ToByte(rd[8]);
              comm_state = System.Convert.ToByte(rd[9]);
              enable = (rd[12].ToString() == "Y");

              if (this.devType == "VD")
              {
              tc = new Comm.TC.VDTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus,comm_state);
              }

              else if (this.devType == "RGS")
              {
              tc = new Comm.TC.RGSTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus,comm_state);
              }
              else if (this.devType == "RMS")
              {
              tc = new Comm.TC.RMSTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus,comm_state);

              }
              else if (this.devType == "CMS")
              {
              tc = new Comm.TC.CMSTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus,comm_state);

              }
              else if (this.devType == "WIS")
              {
              tc = new Comm.TC.WISTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus,comm_state);

              }
              else if (this.devType == "LCS")
              {
              tc = new Comm.TC.LCSTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus,comm_state);
              }
              else if (this.devType == "CSLS")
              {
              tc = new Comm.TC.CSLSTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus,comm_state);
              }
              else if (this.devType == "AVI")
              {
              tc = new Comm.TC.AVITC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus,comm_state);
              }
              else if (this.devType == "ETAG")
              {
              tc = new Comm.TC.ETAGTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }

              else if (this.devType == "RD")
              {
              tc = new Comm.TC.RDTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }
              else if (this.devType == "VI")
              {
              tc = new Comm.TC.VITC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }
              else if (this.devType == "WD")
              {
              tc = new Comm.TC.WDTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }
              else if (this.devType == "TTS")
              {
              tc = new Comm.TC.TTSTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }
              else if (this.devType == "FS")
              {
              tc = new Comm.TC.FSTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }
              else if (this.devType == "MAS")
              {
              tc = new Comm.TC.MASTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }
              else if (this.devType == "IID")
              {
              tc = new Comm.TC.IIDTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }
              else if (this.devType == "ETTU")
              {
              tc = new Comm.TC.ETTUTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }
              else if (this.devType == "LS")
              {
              tc = new Comm.TC.LSTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }
              else if (this.devType == "TEM")
              {
              tc = new Comm.TC.TEMTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }
              else if (this.devType == "SCM")
              {
              tc = new Comm.TC.SCMTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }
              else if (this.devType == "CMSRST")
              {
              tc = new Comm.TC.CMSRSTTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }
              else if (this.devType == "BS")
              {
              tc = new Comm.TC.BSTC(protocol, rd[0].ToString().Trim(), rd[1].ToString(), (int)rd[2], 0xffff, hw_status, opmode, opstatus, comm_state);
              }

              ConsoleServer.WriteLine(string.Format("load tc:{0} ip:{1} port:{2}", rd[0], rd[1], rd[2]));
              if(tc is OutputTCBase)
             ((OutputTCBase)tc).setDisplayCompareCycle( System.Convert.ToInt32(rd[11]));

              tcAry.Add(tc);
              tc.OnHwStatusChanged += new HWStatusChangeHandler(tc_OnHwStatusChanged);
              tc.OnConnectStatusChanged += new ConnectStatusChangeHandler(tc_OnConnectStatusChanged);
              tc.OnOpModeChanged += new OnOPModeChangeHandler(tc_OnOpModeChanged);
              tc.OnOpStatusChanged += new OnOPStatusChangeHandler(tc_OnOpStatusChanged);
              tc.OnTCReport += new OnTCReportHandler(tc_OnTCReport);
              tc.OnDbDemand += new OnDbDemandHandler(tc_OnDbDemand);
              tc.IsF311z = (System.Convert.ToString(rd[10]).ToUpper() == "Y") ? true : false;
              tc.IsEnable = enable;
              if (tc is OutputTCBase)
              {
              ((OutputTCBase)tc).OnOutputChanged += new Comm.OnOutputChangedHandler(MFCC_Base_OnOutputChanged);
              ((OutputTCBase)tc).OnOutputDataCompareWrongEvent += new OnOutputDataCompareWrongEventHandler(MFCC_Base_OnOutputDataCompareWrongEvent);
              }
              this.BindEvent(tc);

              manager.AddTC(tc);

              }
              catch (Exception ex)
              {
              ConsoleServer.WriteLine("InAddDevice:" + ex.Message);
              throw new Exception("InAddDevice:" + ex.Message);
              }
              finally
              {
              rd.Close();
              cn.Close();
              }
        }