Ask Your Question
1

How can attendance logs be acquired from ZKTEco device through their SDK utilizing C#?

asked 2023-07-16 09:51:05 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-07-16 10:16:01 +0000

plato gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-16 09:51:05 +0000

Seen: 11 times

Last updated: Jul 16 '23