示例#1
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);
        }
示例#2
0
        private static void ReadAll()
        {
            if (IsRunning)
            {
                ServiceResult <DataTable> devices = null;
                bool isPeriorityDevice            = !String.IsNullOrEmpty(ParamService.getParameterValue("PeriorityDevice"));
                try
                {
                    if (isPeriorityDevice)
                    {
                        devices = DeviceService.getPeriorityDevice();
                        ParamService.updateParameter("PeriorityDevice", null);
                    }
                    else
                    {
                        devices = DeviceService.getActiveDevices();
                    }
                }
                catch (Exception e)
                {
                    string message = "Error getting devices list: " + e.Message;
                    SystemContext.LogWithParams(SystemContext.RootLogger, LogLevel.ERROR, message, null, true);
                    worker.ReportProgress(0, new ProgressRecord(DateTime.Now, false, message));
                    return;
                }
                int totalCount = 0;
                if (devices.IsSuccess())
                {
                    foreach (DataRow row in devices.Result.Rows)
                    {
                        //Thread.Sleep(5000);
                        if (!IsRunning)
                        {
                            return;
                        }
                        int      count  = 0;
                        ZKDevice device = new ZKDevice();
                        if (!String.IsNullOrEmpty(ParamService.getParameterValue("PeriorityDevice")))
                        {
                            break;
                        }
                        try
                        {
                            device.DeviceID   = row["ID"].ToString();
                            device.DeviceName = row["DEVICE_NAME"].ToString();
                            device.DeviceIP   = row["DEVICE_IP"].ToString();
                            device.DevicePort = row["DEVICE_PORT"].ToString();
                            worker.ReportProgress(0, new ProgressRecord(DateTime.Now, true,
                                                                        "Pooling Data From:  " + device.DeviceFullName));
                            if (!isPeriorityDevice)
                            {
                                if (device.DeviceID != devices.Result.Rows[devices.Result.Rows.Count - 1]["ID"].ToString())
                                {
                                    ParamService.updateParameter("CurrentDevice", device.DeviceID);
                                }
                                else
                                {
                                    ParamService.updateParameter("CurrentDevice", "0");
                                }
                            }
                            count       = device.GetGeneralLogData();
                            totalCount += count;
                        }
                        catch (Exception e)
                        {
                            string message = "Error reading from device  " + device.DeviceFullName + "  " + e.Message;
                            SystemContext.LogWithParams(SystemContext.RootLogger, LogLevel.ERROR, message, null, true);
                            worker.ReportProgress(0, new ProgressRecord(DateTime.Now, false, message));
                        }
                    }
                }

                /*worker.ReportProgress(0, new ProgressRecord(DateTime.Now, true,
                 *              "Coping Log Data ..."));
                 * TransactionService.moveToRemoteTable(Customer);*/
            }
        }
示例#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);
        }