ZKteco Attendance Device is widely used machine for bio-metric attendance and facial recognition attendance,
Here is the function how to get the device log from Machine using ZKteco SDK.
Here is the function how to get the device log from Machine using ZKteco SDK.
public DataTable LogTable()
{
DataTable
DT = new DataTable();
DT.Columns.Add("EmpID");
DT.Columns.Add("Logtime");
DT.Columns.Add("LogBranchId");
DT.Columns.Add("TTYPE");
DT.Columns.Add("Description");
return
DT;
}
DataTable
DTAttLog = LogTable();
public void GetLogfromMachine(int
iMnumber, String MachineIP, String Port,String
LogBranchId,String TTYPE)
{
//Setup
columns and other UI stuff
//Set
datasource of grid
//axCZKEM1
= new zkemkeeper.CZKEMClass();
//Cursor
= Cursors.WaitCursor;
int
idwErrorCode = 0;
setstatus("Connecting
to device " + MachineIP + ":"
+ Port + ", please wait...");
bIsConnected =
axCZKEM1.Connect_Net(MachineIP, Convert.ToInt32(Port));
if
(bIsConnected)
{
//c1TrueDBGrid1[iMnumber
- 1, "Status"] = "Connected";
c1TrueDBGrid1[iMnumber - 1, "F.Attempts"] = "0";
c1TrueDBGrid1[iMnumber - 1, "LSTime"] = DateTime.Now;
setstatus("Connected to device " + MachineIP + ":" + Port + "");
OutPut(MachineIP + ":" + Port + "
Current State:Connected");
c1TrueDBGrid1.Refresh();
axCZKEM1.RegEvent(iMachineNumber, 65535);
#region
GetLog
string
sdwEnrollNumber = "";
//int
idwTMachineNumber=0;
//int
idwEMachineNumber=0;
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;
idwErrorCode = 0;
int
iGLCount = 0;
int
iIndex = 0;
//Cursor
= Cursors.WaitCursor;
int
LogRecivedCount = 0;
//axCZKEM1.EnableDevice(iMachineNumber,
false);//disable the device
setstatus("Fetching log from device " + MachineIP
+ ":" + Port + ", please wait...");
if
(axCZKEM1.ReadGeneralLogData(iMachineNumber))//read
all the attendance records to the memory
{
LogRecivedCount = 0;
while
(axCZKEM1.SSR_GetGeneralLogData(iMnumber, 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
{
//iGLCount++;
//lvLogs.Items.Add(iGLCount.ToString());
//lvLogs.Items[iIndex].SubItems.Add(sdwEnrollNumber);//modify by Darcy
on Nov.26 2009
//lvLogs.Items[iIndex].SubItems.Add(idwVerifyMode.ToString());
//lvLogs.Items[iIndex].SubItems.Add(idwInOutMode.ToString());
//lvLogs.Items[iIndex].SubItems.Add(idwYear.ToString() + "-" +
idwMonth.ToString() + "-" + idwDay.ToString() + " " +
idwHour.ToString() + ":" + idwMinute.ToString() + ":" +
idwSecond.ToString());
//lvLogs.Items[iIndex].SubItems.Add(idwWorkcode.ToString());
//iIndex++;
try
{
DTAttLog.Rows.Add(sdwEnrollNumber, idwYear.ToString() + "-" + idwMonth.ToString() + "-" + idwDay.ToString() + " " + idwHour.ToString() + ":" + idwMinute.ToString() + ":" + idwSecond.ToString(), LogBranchId,
TTYPE, MachineIP+":"+Port);
}
catch (Exception)
{
// throw;
}
LogRecivedCount++;
setstatus("Fetching
log from device " + MachineIP + ":"
+ Port + ", log fetched = " +
LogRecivedCount + ", please wait...");
}
OutPut("Fetch Record from Machine Total Count was "
+ LogRecivedCount);
setstatus("Fetching
log completed from device " + MachineIP + ":"
+ Port + ", log fetched = " +
LogRecivedCount + "");
LogRecivedCount = 0;
}
else
{
//Cursor
= Cursors.Default;
axCZKEM1.GetLastError(ref idwErrorCode);
if
(idwErrorCode != 0)
{
OutPut("Reading data from terminal failed,ErrorCode: "
+ idwErrorCode.ToString());
setstatus("Reading data from terminal failed,ErrorCode: "
+ idwErrorCode.ToString() + " from device
" + MachineIP + ":" +
Port + "");
}
else
{
OutPut("No
data from terminal returns!");
setstatus("No data from returns from device " +
MachineIP + ":" + Port + "");
}
}
axCZKEM1.ClearGLog(iMachineNumber);
axCZKEM1.RefreshData(iMachineNumber);
//axCZKEM1.EnableDevice(iMachineNumber,
true);//enable the device
#endregion
axCZKEM1.Disconnect();
}
else
{
axCZKEM1.GetLastError(ref idwErrorCode);
//c1TrueDBGrid1[iMnumber
- 1, "Status"] = "ErrorCode=" + idwErrorCode.ToString();
OutPut("Unable
to connect the device " + MachineIP + ":"
+ Port + ", ErrorCode=" + idwErrorCode.ToString());
c1TrueDBGrid1[iMnumber - 1, "LSTime"] = DateTime.Now;
setstatus("Unable to connect, ErrorCode: " +
idwErrorCode.ToString() + " from device "
+ MachineIP + ":" + Port + "");
if
(idwErrorCode == -7)
{
try
{
int ConAttempts = Convert.ToInt32(c1TrueDBGrid1[iMnumber
- 1, "F.Attempts"]);
ConAttempts =
ConAttempts + 1;
c1TrueDBGrid1[iMnumber - 1, "F.Attempts"] = ConAttempts;
c1TrueDBGrid1[iMnumber
- 1, "LSTime"] = DateTime.Now;
if (ConAttempts >= 3)
{
TerminalActivateDeactivate(iMnumber,
"InActive");
}
}
catch
(Exception)
{
//throw;
}
}
axCZKEM1.Disconnect();
}
}