Exemplo n.º 1
0
        /// <summary>
        /// 连接设备(网络)
        /// </summary>
        public bool Connect_Net()
        {
            if (COM_IsConnected == true)
            {
                return(true);
            }
            switch (COM_ConnectType)
            {
            case 1:
                COM_IsConnected = m_CZKEMClass.Connect_Net(COM_IPAddress, COM_TCP_PORT);
                break;

            case 2:
                COM_IsConnected = m_CZKEMClass.Connect_Com(COM_TCP_PORT, COM_MACHINENUMBER, COM_BAUDRATE);
                break;

            case 3:
                COM_IsConnected = m_CZKEMClass.Connect_USB(COM_MACHINENUMBER);
                break;

            default:
                COM_IsConnected = m_CZKEMClass.Connect_Net(COM_IPAddress, COM_TCP_PORT);
                break;
            }

            if (COM_IsConnected == true)
            {
                if (m_CZKEMClass.RegEvent(COM_MACHINENUMBER, 65535))
                {
                    this.m_CZKEMClass.OnFinger           += new zkemkeeper._IZKEMEvents_OnFingerEventHandler(m_CZKEMClass_OnFinger);
                    this.m_CZKEMClass.OnVerify           += new zkemkeeper._IZKEMEvents_OnVerifyEventHandler(m_CZKEMClass_OnVerify);
                    this.m_CZKEMClass.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(m_CZKEMClass_OnAttTransactionEx);
                    this.m_CZKEMClass.OnFingerFeature    += new zkemkeeper._IZKEMEvents_OnFingerFeatureEventHandler(m_CZKEMClass_OnFingerFeature);
                    this.m_CZKEMClass.OnEnrollFingerEx   += new zkemkeeper._IZKEMEvents_OnEnrollFingerExEventHandler(m_CZKEMClass_OnEnrollFingerEx);
                    this.m_CZKEMClass.OnDeleteTemplate   += new zkemkeeper._IZKEMEvents_OnDeleteTemplateEventHandler(m_CZKEMClass_OnDeleteTemplate);
                    this.m_CZKEMClass.OnNewUser          += new zkemkeeper._IZKEMEvents_OnNewUserEventHandler(m_CZKEMClass_OnNewUser);
                    this.m_CZKEMClass.OnHIDNum           += new zkemkeeper._IZKEMEvents_OnHIDNumEventHandler(m_CZKEMClass_OnHIDNum);
                    this.m_CZKEMClass.OnAlarm            += new zkemkeeper._IZKEMEvents_OnAlarmEventHandler(m_CZKEMClass_OnAlarm);
                    this.m_CZKEMClass.OnDoor             += new zkemkeeper._IZKEMEvents_OnDoorEventHandler(m_CZKEMClass_OnDoor);
                    this.m_CZKEMClass.OnWriteCard        += new zkemkeeper._IZKEMEvents_OnWriteCardEventHandler(m_CZKEMClass_OnWriteCard);
                    this.m_CZKEMClass.OnEmptyCard        += new zkemkeeper._IZKEMEvents_OnEmptyCardEventHandler(m_CZKEMClass_OnEmptyCard);
                }
                lbRTShow.Items.Add("设备连接成功,设备码:" + COM_MACHINENUMBER.ToString());
                return(true);
            }
            else
            {
                int idwErrorCode = 0;
                m_CZKEMClass.GetLastError(ref idwErrorCode);
                //MessageUtil.ShowError("不能连上设备,错误代码=" + idwErrorCode.ToString());
                lbRTShow.Items.Add("不能连上设备,错误代码=" + idwErrorCode.ToString());
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool ConnectUSB(bool VirtualUSB, int VirtualUSBMachineSN = 1)
        {
            if (bIsDestroying)
            {
                return(false);
            }

            lock (_locker)
            {
                //int idwErrorCode = 0;
                //ilock++; //bIsBusy = true;
                if (!VirtualUSB)        //the common USBClient
                {
                    iMachineNumber = 1; //In fact,when you are using common USBClient communication,parameter Machinenumber will be ignored,that is any integer will all right.Here we use 1.
                    bIsConnected   = axCZKEM1.Connect_USB(iMachineNumber);
                }
                else //connect the device via the virtual serial port created by USB
                {
                    SearchForUSBCom usbcom  = new SearchForUSBCom();
                    string          sCom    = "";
                    bool            bSearch = usbcom.SearchforCom(ref sCom); //modify by Darcy on Nov.26 2009
                    if (bSearch == false)                                    //modify by Darcy on Nov.26 2009
                    {
                        throw new ArgumentNullException("Can not find the virtual serial port that can be used");
                        //return false;
                    }

                    int iPort;
                    for (iPort = 1; iPort < 10; iPort++)
                    {
                        if (sCom.IndexOf(iPort.ToString()) > -1)
                        {
                            break;
                        }
                    }

                    iMachineNumber = VirtualUSBMachineSN;
                    if (iMachineNumber == 0 || iMachineNumber > 255)
                    {
                        throw new ArgumentNullException("The Machine Number is invalid!");
                        //return false;
                    }

                    int iBaudRate = 115200; //115200 is one possible baudrate value(its value cannot be 0)
                    bIsConnected = axCZKEM1.Connect_Com(iPort, iMachineNumber, iBaudRate);
                }

                if (bIsConnected == true)
                {
                    if (axCZKEM1.RegEvent(iMachineNumber, 65535))//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
                    {
                        RegisterEvents();
                    }
                }
                else
                {
                    axCZKEM1.GetLastError(ref iLastError);
                    //throw new Exception("Unable to connect the device! ErrorCode=" + idwErrorCode.ToString());
                }
                //ilock--; //bIsBusy = false;
            }
            return(bIsConnected);
        }