Ejemplo n.º 1
0
        private void ConnectDevice()
        {
            if (bIsConnected)
            {
                return;
            }

            int idwErrorCode = 0;

            try
            {
                bIsConnected = axCZKEM1.Connect_Net(this._device.IP, this._device.Port);
                if (bIsConnected)
                {
                    //this.Device.DeviceStatus = DeviceStatus.Available;
                    iMachineNumber = 1;                       //In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
                    axCZKEM1.RegEvent(iMachineNumber, 65535); //Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
                    MyLogger.GetInstance.Info("ZKDevice.ConnectDevice() - The device is connected successull " + this.Device.IP);
                }
                else
                {
                    axCZKEM1.GetLastError(ref idwErrorCode);
                    MyLogger.GetInstance.Error(string.Format("ZKDevice.ConnectDevice() - Unable to connect the Device: {0}, ErrorCode: {1}", this.Device.IP, idwErrorCode.ToString()));
                }
            }
            catch (Exception e)
            {
                MyLogger.GetInstance.Error(e.Message);
            }
        }
Ejemplo n.º 2
0
        private bool Connect(string ip, int port = 4370)
        {
            int  i      = 0;
            bool result = true;

            try
            {
                log.Info(string.Format("Try connection to ZK Device ({0})", ip));

                log.Info(string.Format("ZKSoftware API :  axCZKEM1.Connect_Net=>1"));
                if (!axCZKEM1.Connect_Net(ip, port))
                {
                    for (i = 2; i < 4; i++)
                    {
                        log.Info(string.Format("ZKSoftware API :  axCZKEM1.Connect_Net=>{0}", i));
                        if (!axCZKEM1.Connect_Net(ip, port))
                        {
                            result = false;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (!result)
                    {
                        axCZKEM1.GetLastError(ref ErrorCode);
                        ErrorMessage = "Unable to connect the device,ErrorCode= " + ErrorCode;
                        log.Warn(ErrorMessage);
                    }
                }

                if (result)
                {
                    log.Info(string.Format("ZKSoftware API :  axCZKEM1.EnableDevice: false"));
                    axCZKEM1.EnableDevice(iMachineNumber, false);
                    log.Info(string.Format("ZK Device ({0}) is Connected", ip));
                }
            }
            catch (AccessViolationException aex)
            {
                log.Fatal(aex);
                result = false;
                throw new Exception(aex.Message);
            }
            catch (Exception ex)
            {
                log.Fatal(ex);
                result = false;
                throw ex;
            }
            catch
            {
                throw;
            }

            return(result);
        }
Ejemplo n.º 3
0
        // obtiene checadas BlackWhite
        private List <Modelos.AttLogs> obtieneChecadas()
        {
            List <Modelos.AttLogs> result = new List <Modelos.AttLogs>();

            Modelos.AttLogs ent;

            int    idwEnrollNumber = 0;
            int    idwVerifyMode   = 0;
            int    idwInOutMode    = 0;
            string dwTimestr       = string.Empty;

            int idwErrorCode = 0;

            Cursor = Cursors.WaitCursor;

            axCZKEM1.EnableDevice(iMachineNumber, false);                                                                                      // disable the device

            if (axCZKEM1.ReadGeneralLogData(iMachineNumber))                                                                                   // read all the attendance records to the memory
            {
                while (axCZKEM1.GetGeneralLogDataStr(iMachineNumber, ref idwEnrollNumber, ref idwVerifyMode, ref idwInOutMode, ref dwTimestr)) // get records from the memory
                {
                    ent = new Modelos.AttLogs();

                    ent.enrolIdNumber = idwEnrollNumber;
                    ent.fecha         = Convert.ToDateTime(dwTimestr);

                    result.Add(ent);
                }
            }
            else
            {
                Cursor = Cursors.Default;
                axCZKEM1.GetLastError(ref idwErrorCode);

                if (idwErrorCode != 0)
                {
                    this.agregarDetalle("Lectura de información del checador falló. ErrorCode: " + idwErrorCode.ToString());
                    throw new Exception("Lectura de información del checador falló. ErrorCode: " + idwErrorCode.ToString());
                }
                else
                {
                    this.agregarDetalle("No hay informacion en el Checador");
                    throw new Exception("No hay informacion en el Checador");
                }
            }

            axCZKEM1.EnableDevice(iMachineNumber, true);//enable the device
            Cursor = Cursors.Default;

            return(result);
        }
Ejemplo n.º 4
0
        public int sta_ConnectTCP(List <string> lblOutputInfo, string ip, string port, string commKey)
        {
            if (ip == "" || port == "" || commKey == "")
            {
                lblOutputInfo.Add("*Name, IP, Port or Commkey cannot be null !");
                return(-1);// ip or port is null
            }

            if (Convert.ToInt32(port) <= 0 || Convert.ToInt32(port) > 65535)
            {
                lblOutputInfo.Add("*Port illegal!");
                return(-1);
            }

            if (Convert.ToInt32(commKey) < 0 || Convert.ToInt32(commKey) > 999999)
            {
                lblOutputInfo.Add("*CommKey illegal!");
                return(-1);
            }

            int idwErrorCode = 0;

            axCZKEM1.SetCommPassword(Convert.ToInt32(commKey));

            if (bIsConnected == true)
            {
                axCZKEM1.Disconnect();
                SetConnectState(false);
                lblOutputInfo.Add("Disconnect with device !");
                //connected = false;
                return(-2); //disconnect
            }

            if (axCZKEM1.Connect_Net(ip, Convert.ToInt32(port)) == true)
            {
                SetConnectState(true);
                lblOutputInfo.Add("Connect with device !");


                return(1);
            }
            else
            {
                axCZKEM1.GetLastError(ref idwErrorCode);
                lblOutputInfo.Add("*Unable to connect the device,ErrorCode=" + idwErrorCode.ToString());
                return(idwErrorCode);
            }
        }
Ejemplo n.º 5
0
 void Conectar()
 {
     if (btnConnect.Text == "Desconectar")
     {
         axCZKEM1.Disconnect();
         axCZKEM1.OnAttTransactionEx -= axCZKEM1_OnAttTransactionEx;
         bIsConnected    = false;
         btnConnect.Text = "Conectar";
         lblState.Text   = "Estado Actual:Desconectado";
         Cursor          = Cursors.Default;
         return;
     }
     else
     {
         bIsConnected = axCZKEM1.Connect_Net(IP, Puerto);
         if (bIsConnected)
         {
             if (axCZKEM1.RegEvent(iMachineNumber, 65535))
             {
                 axCZKEM1.OnAttTransactionEx += axCZKEM1_OnAttTransactionEx;
             }
             btnConnect.Text = "Desconectar";
             lblState.Text   = "Estado Actual:Conectado";
         }
         else
         {
             axCZKEM1.GetLastError(idwErrorCode);
             lblState.Text = "No se pudo conectar, Error=" + idwErrorCode.ToString();
         }
     }
 }
Ejemplo n.º 6
0
        public bool ConnectNet(MacType macType, string ipAddress, int port, int machineNo)
        {
            _con = new ConnectToDevices
            {
                MacType   = MacType.Net,
                IpAddress = ipAddress,
                Port      = port,
                MachineNo = machineNo
            };

            _bConnected = axCZKEM1.Connect_Net(ipAddress, port);
            if (!_bConnected)
            {
                axCZKEM1.GetLastError(_idwErrorCode);
            }

            return(_bConnected);
        }
        private static int iMachineNumber = 1;     //the serial number of the device.After connecting the device ,this value will be changed.

        public static Response conectar(string ip, int puerto)
        {
            Response result = new Response();

            int idwErrorCode = 0;

            bIsConnected = axCZKEM1.Connect_Net(ip, Convert.ToInt32(puerto));
            if (bIsConnected == true)
            {
                iMachineNumber = 1;                       //In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
                axCZKEM1.RegEvent(iMachineNumber, 65535); //Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)

                result.status    = Estatus.OK;
                result.resultado = "Conectado";
            }
            else
            {
                axCZKEM1.GetLastError(ref idwErrorCode);
                result.status = Estatus.ERROR;
                result.error  = "Unable to connect the device, ErrorCode=" + idwErrorCode.ToString();
            }

            return(result);
        }
Ejemplo n.º 8
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            //timer1.Enabled = true;
            //timer1.Start();

            string ip = "";

            //ip = comboBox1.<SelectedValue.ToString();
            ip = textBox1.Text;


            int idwErrorCode = 0;

            Cursor = Cursors.WaitCursor;
            if (btnConnect.Text == "DisConnect")
            {
                axCZKEM1.Disconnect();
                bIsConnected    = false;
                btnConnect.Text = "Connect";
                lblState.Text   = "Current State:DisConnected";
                Cursor          = Cursors.Default;
                return;
            }

            bIsConnected = axCZKEM1.Connect_Net(ip, Convert.ToInt32(puerto));
            if (bIsConnected == true)
            {
                btnConnect.Text = "DisConnect";
                btnConnect.Refresh();
                lblState.Text = "Current State:Connected";


                iMachineNumber = 1;                           //In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
                if (axCZKEM1.RegEvent(iMachineNumber, 65535)) //Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
                {
                    this.axCZKEM1.OnFinger           += new zkemkeeper._IZKEMEvents_OnFingerEventHandler(axCZKEM1_OnFinger);
                    this.axCZKEM1.OnVerify           += new zkemkeeper._IZKEMEvents_OnVerifyEventHandler(axCZKEM1_OnVerify);
                    this.axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
                    this.axCZKEM1.OnFingerFeature    += new zkemkeeper._IZKEMEvents_OnFingerFeatureEventHandler(axCZKEM1_OnFingerFeature);
                    this.axCZKEM1.OnEnrollFingerEx   += new zkemkeeper._IZKEMEvents_OnEnrollFingerExEventHandler(axCZKEM1_OnEnrollFingerEx);
                    this.axCZKEM1.OnDeleteTemplate   += new zkemkeeper._IZKEMEvents_OnDeleteTemplateEventHandler(axCZKEM1_OnDeleteTemplate);
                    this.axCZKEM1.OnNewUser          += new zkemkeeper._IZKEMEvents_OnNewUserEventHandler(axCZKEM1_OnNewUser);
                    this.axCZKEM1.OnHIDNum           += new zkemkeeper._IZKEMEvents_OnHIDNumEventHandler(axCZKEM1_OnHIDNum);
                    this.axCZKEM1.OnAlarm            += new zkemkeeper._IZKEMEvents_OnAlarmEventHandler(axCZKEM1_OnAlarm);
                    this.axCZKEM1.OnDoor             += new zkemkeeper._IZKEMEvents_OnDoorEventHandler(axCZKEM1_OnDoor);
                    this.axCZKEM1.OnWriteCard        += new zkemkeeper._IZKEMEvents_OnWriteCardEventHandler(axCZKEM1_OnWriteCard);
                    this.axCZKEM1.OnEmptyCard        += new zkemkeeper._IZKEMEvents_OnEmptyCardEventHandler(axCZKEM1_OnEmptyCard);
                }
            }
            else
            {
                axCZKEM1.GetLastError(ref idwErrorCode);
                MessageBox.Show("Unable to connect the device,ErrorCode=" + idwErrorCode.ToString(), "Error");
                this.axCZKEM1.OnFinger           -= new zkemkeeper._IZKEMEvents_OnFingerEventHandler(axCZKEM1_OnFinger);
                this.axCZKEM1.OnVerify           -= new zkemkeeper._IZKEMEvents_OnVerifyEventHandler(axCZKEM1_OnVerify);
                this.axCZKEM1.OnAttTransactionEx -= new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
                this.axCZKEM1.OnFingerFeature    -= new zkemkeeper._IZKEMEvents_OnFingerFeatureEventHandler(axCZKEM1_OnFingerFeature);
                this.axCZKEM1.OnEnrollFingerEx   -= new zkemkeeper._IZKEMEvents_OnEnrollFingerExEventHandler(axCZKEM1_OnEnrollFingerEx);
                this.axCZKEM1.OnDeleteTemplate   -= new zkemkeeper._IZKEMEvents_OnDeleteTemplateEventHandler(axCZKEM1_OnDeleteTemplate);
                this.axCZKEM1.OnNewUser          -= new zkemkeeper._IZKEMEvents_OnNewUserEventHandler(axCZKEM1_OnNewUser);
                this.axCZKEM1.OnHIDNum           -= new zkemkeeper._IZKEMEvents_OnHIDNumEventHandler(axCZKEM1_OnHIDNum);
                this.axCZKEM1.OnAlarm            -= new zkemkeeper._IZKEMEvents_OnAlarmEventHandler(axCZKEM1_OnAlarm);
                this.axCZKEM1.OnDoor             -= new zkemkeeper._IZKEMEvents_OnDoorEventHandler(axCZKEM1_OnDoor);
                this.axCZKEM1.OnWriteCard        -= new zkemkeeper._IZKEMEvents_OnWriteCardEventHandler(axCZKEM1_OnWriteCard);
                this.axCZKEM1.OnEmptyCard        -= new zkemkeeper._IZKEMEvents_OnEmptyCardEventHandler(axCZKEM1_OnEmptyCard);
            }
            Cursor = Cursors.Default;
        }