Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To acquire attendance logs from a ZKTEco device using their SDK in C#, follow the steps below:

  1. Install the ZKSoftware SDK and its dependencies on your system.

  2. Initialize the SDK by creating an instance of the SDK class in C#.

```# zkemkeeper.CZKEMClass sdk = new zkemkeeper.CZKEMClass();


3. Connect to the ZKTEco device using the Connect_Net() method of the SDK class, which takes the IP address and port number of the device as its arguments.

```#
string ipAddress = "192.168.1.201"; // Example IP address
int port = 4370; // Example port number
bool isConnected = sdk.Connect_Net(ipAddress, port);
  1. Once the device is connected, you can retrieve the attendance logs using the GetGeneralLogData() method of the SDK class, which takes the following arguments:
  • Machine number: The number of the device. Here, we can pass 1 if only one device is connected.
  • Start time: The start time for retrieving the attendance logs.
  • End time: The end time for retrieving the attendance logs.
  • Enroll number: The user ID associated with the attendance logs. Here, we can pass an empty string to retrieve all logs.

```# DateTime startDate = DateTime.Parse("2022-01-01 00:00:00"); // Example start time DateTime endDate = DateTime.Now; // Example end time string userId = ""; // Retrieve logs for all users int totalCount = 0;

// Call GetGeneralLogData() method to retrieve attendance logs bool isRetrieved = sdk.GetGeneralLogData(1, ref userId, ref startDate, ref endDate, ref totalCount);


5. After retrieving the logs, you can loop through the logs and extract the required data. The attendance logs can be retrieved as an array of strings, where each string represents a single attendance log.

```#
if (isRetrieved && totalCount > 0)
{
    string[] attendanceLogs = new string[totalCount];
    int retrievedLogs = sdk.SSR_GetGeneralLogData(1, out attendanceLogs[0], out userId, out startDate, out endDate, out logOptions, out logStatus);

    for (int i = 0; i < retrievedLogs; i++)
    {
        // Extract the required data from the log
        string[] logData = attendanceLogs[i].Split('\t');
        string userId = logData[0];
        DateTime attendanceTime = DateTime.Parse(logData[1]);
        int verifyMode = int.Parse(logData[2]);
        int verifyState = int.Parse(logData[3]);
        int workCode = int.Parse(logData[4]);
        Console.WriteLine($"User ID: {userId}, Attendance Time: {attendanceTime}, Verify Mode: {verifyMode}, Verify State: {verifyState}, Work Code: {workCode}");
    }
}
  1. Finally, disconnect from the device using the Disconnect() method of the SDK class.

# sdk.Disconnect();

Note: The above code is an example, and it is advised to modify it as per the requirements of your project.