Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 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();
              }
        }