Exemple #1
0
        public int GetGeneralLogData()
        {
            int      count        = 0;
            DateTime startTime    = DateTime.Now;
            Worker   workerObject = new Worker();

            workerObject.device = this;
            Thread workerThread = new Thread(workerObject.DoWork);

            workerThread.IsBackground = true;
            workerThread.Start();
            Console.WriteLine("main thread: Starting worker thread...");

            while (!workerThread.IsAlive)
            {
                ;
            }

            while (workerThread.IsAlive)
            {
                if (DateTime.Now - startTime > new TimeSpan(0, 0, connectTimeout))
                {
                    string[] paramlist = new string[4];
                    paramlist[0] = DeviceName; paramlist[1] = ""; paramlist[2] = ""; paramlist[3] = "";
                    String message = "Connection to device " + DeviceFullName + " failed, Timeout";
                    SystemContext.LogWithParams(SystemContext.RootLogger, LogLevel.CORE, message, paramlist, true);
                    worker.ReportProgress(0, new ProgressRecord(DateTime.Now, false, message));
                    DeviceService.updateDeviceConnectStatus(false, DeviceIP);
                    axCZKEM1.CancelOperation();
                    workerThread.Abort();
                    worker.ReportProgress(0, new ProgressRecord(999999));
                    IsRunning = false;
                    Thread.Sleep(Int32.MaxValue); // do nothing because bg worker will be killed by owner thread
                }
            }
            DeviceService.updateDeviceTransactionCount(DeviceIP, transactionLog.Count);
            if (transactionLog.Count > 0)
            {
                // Move data to our table
                count = TransactionService.insertLog(transactionLog, DeviceID, DeviceIP);
                String message = count + " Records were read from device " + DeviceFullName;
                worker.ReportProgress(0, new ProgressRecord(DateTime.Now, false, message));
            }
            return(count);
        }
Exemple #2
0
        //If your device supports the TCP/IP communications, you can refer to this.
        //when you are using the tcp/ip communication,you can distinguish different devices by their IP address.
        private int connect()
        {
            if (String.IsNullOrEmpty(DeviceIP) || String.IsNullOrEmpty(DevicePort))
            {
                return(-1);
            }
            int idwErrorCode = 0;

            bIsConnected = axCZKEM1.Connect_Net(DeviceIP.Trim(), Convert.ToInt32(DevicePort.Trim()));
            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)
                DeviceService.updateDeviceConnectStatus(true, DeviceIP);
            }
            else
            {
                axCZKEM1.GetLastError(ref idwErrorCode);
                // log here
            }
            return(idwErrorCode);
        }
Exemple #3
0
        //Download the attendance records from the device(For both Black&White and TFT screen devices).
        public int downloadGeneralLogData()
        {
            int count         = 0;
            int connectResult = 0;

            if (!bIsConnected)
            {
                connectResult = connect();
            }
            if (!bIsConnected)
            {
                string[] paramlist = new string[4];
                paramlist[0] = DeviceName;
                paramlist[1] = "";
                paramlist[2] = "";
                paramlist[3] = "";

                if (connectResult == 0)
                {
                    axCZKEM1.GetLastError(ref connectResult);
                }

                String message = "Connection to device " + DeviceFullName + " failed, errorCode:" + connectResult.ToString();
                SystemContext.LogWithParams(SystemContext.RootLogger, LogLevel.CORE, message, paramlist, true);
                worker.ReportProgress(0, new ProgressRecord(DateTime.Now, false, message));

                DeviceService.updateDeviceConnectStatus(false, DeviceIP);

                return(0);
            }


            string sdwEnrollNumber = "";
            int    idwVerifyMode   = 0;
            int    idwInOutMode    = 0;
            int    idwYear         = 0;
            int    idwMonth        = 0;
            int    idwDay          = 0;
            int    idwHour         = 0;
            int    idwMinute       = 0;
            int    idwSecond       = 0;
            int    idwWorkcode     = 0;

            int idwErrorCode = 0;

            DeviceService.updateDeviceConnectStatus(true, DeviceIP);



            axCZKEM1.EnableDevice(iMachineNumber, false);    //disable the device
            if (axCZKEM1.ReadGeneralLogData(iMachineNumber)) //read all the attendance records to the memory
            {
                while (axCZKEM1.SSR_GetGeneralLogData(iMachineNumber, out sdwEnrollNumber, out idwVerifyMode,
                                                      out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkcode))//get records from the memory
                {
                    LogRecord record = new LogRecord(iMachineNumber, sdwEnrollNumber, idwVerifyMode,
                                                     idwInOutMode, idwYear, idwMonth, idwDay, idwHour, idwMinute, idwSecond, idwWorkcode);
                    transactionLog.Add(record);
                }
            }
            else
            {
                axCZKEM1.GetLastError(ref idwErrorCode);
                string[] paramlist = new string[4];
                paramlist[0] = DeviceName;
                paramlist[1] = "";
                paramlist[2] = "";
                paramlist[3] = "";
                String message = "Connection to device " + DeviceFullName + " failed, errorCode:" + idwErrorCode.ToString();
                SystemContext.LogWithParams(SystemContext.RootLogger, LogLevel.CORE, message, paramlist, true);
                worker.ReportProgress(0, new ProgressRecord(DateTime.Now, false, message));
            }
            axCZKEM1.EnableDevice(iMachineNumber, true);//enable the device
            return(count);
        }