0

I'm attempting to integrate a ZKTEco U650-C with my company's systems to automatically fetch attendance logs but I'm having trouble connecting to the device using C#.

I managed to download the SDK from their website which includes the ZKHID, ZKCamera DLL files, and the SDK wrapper so I could import and use the functions from them.

In Visual Studio, I couldn't reference the ZKHID and ZKCamera DLL files because they are unmanaged. Although, I was able to reference the ZKBioModuleSDKWrapper because it uses PInvoke.

Some operations such as connecting to the device using the TcpClient class, initializing, and terminating the device were successful. However, using other operations such as opening the device and getting the device configuration couldn't be made because I don't know how to get the device handle.

Am I using the wrong set of SDK or is it something else? Any help would be appreciated.

  • That device is a biometric device used for time attendance. You need to use Standalone SDK. With it, you don't need to deal with TcpClient class. Instead, there are several methods to accomplish what you need. – jstuardo Dec 28 '22 at 12:01
  • @jstuardo Where do I get the Standalone SDK? – Mohammad Jamjoom Dec 28 '22 at 13:09
  • ZKTeco does not have that SDK anymore in its page because new hardware is prepared for cloud computing (ADMS). I have uploaded latest SDK to my server. Please, get it from: https://www.desytec.com/files/apps/windows/ZKTeco/standalone+sdk-6.3.1.37-doc-2.1.0-demo-1.1.15.zip. Please tell me when you have downloaded. – jstuardo Dec 28 '22 at 17:42
  • @jstuardo I've downloaded it. Thanks a lot. – Mohammad Jamjoom Dec 29 '22 at 07:08
  • @jstuardo I've obtained the attendance logs as well :) Can I post this link in the answers section? – Mohammad Jamjoom Dec 29 '22 at 08:13
  • Glad you solved the problem. I have uploaded the SDK just for you to download it so I don't recommend to post the link since it could be removed to free space. You can, however, post the code you used to make it work. – jstuardo Dec 29 '22 at 19:40

1 Answers1

0

It turns out I was using the wrong set of SDK. ZKTEco took down the SDK download link from their official website so I had to downloaded the correct SDK from a private server.

I added the zkemkeeper.dll reference as normal in Visual Studio, made some changes to the code, and I managed to receive the attendance logs.

using zkemkeeper;

namespace ZKTEco_Biometric_Device_Integration
{
    internal class Program
    {
        public Program()
        {
        }

        public enum CONSTANTS
        {
            PORT = 4370,
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Connecting...");
            CZKEM objCZKEM = new CZKEM();
            if (objCZKEM.Connect_Net("192.168.1.11", (int)CONSTANTS.PORT))
            {
                objCZKEM.SetDeviceTime2(objCZKEM.MachineNumber, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
                Console.WriteLine("Connection Successful!");
                Console.WriteLine("Obtaining attendance data...");
            }
            else
            {
                Console.WriteLine("Connection Failed!");
            }
            if (objCZKEM.ReadGeneralLogData(objCZKEM.MachineNumber))
            {
                //ArrayList logs = new ArrayList();
                string log;
                string dwEnrollNumber;
                int dwVerifyMode;
                int dwInOutMode;
                int dwYear;
                int dwMonth;
                int dwDay;
                int dwHour;
                int dwMinute;
                int dwSecond;
                int dwWorkCode = 1;
                int AWorkCode;
                objCZKEM.GetWorkCode(dwWorkCode, out AWorkCode);
                //objCZKEM.SaveTheDataToFile(objCZKEM.MachineNumber, "attendance.txt", 1);
                while (true)
                {
                    if (!objCZKEM.SSR_GetGeneralLogData(
                    objCZKEM.MachineNumber,
                    out dwEnrollNumber,
                    out dwVerifyMode,
                    out dwInOutMode,
                    out dwYear,
                    out dwMonth,
                    out dwDay,
                    out dwHour,
                    out dwMinute,
                    out dwSecond,
                    ref AWorkCode
                    ))
                    {
                        break;
                    }
                    log = "User ID:" + dwEnrollNumber + " " + verificationMode(dwVerifyMode) + " " + InorOut(dwInOutMode) + " " + dwDay + "/" + dwMonth + "/" + dwYear + " " + time(dwHour) + ":" + time(dwMinute) + ":" + time(dwSecond);
                    Console.WriteLine(log);
                    //logs.Add(log);
                }
            }
            //Console.ReadLine();
        }

        static void getAttendanceLogs(CZKEM objCZKEM)
        {
            string log;
            string dwEnrollNumber;
            int dwVerifyMode;
            int dwInOutMode;
            int dwYear;
            int dwMonth;
            int dwDay;
            int dwHour;
            int dwMinute;
            int dwSecond;
            int dwWorkCode = 1;
            int AWorkCode;
            objCZKEM.GetWorkCode(dwWorkCode, out AWorkCode);
            //objCZKEM.SaveTheDataToFile(objCZKEM.MachineNumber, "attendance.txt", 1);
            while (true)
            {
                if (!objCZKEM.SSR_GetGeneralLogData(
                objCZKEM.MachineNumber,
                out dwEnrollNumber,
                out dwVerifyMode,
                out dwInOutMode,
                out dwYear,
                out dwMonth,
                out dwDay,
                out dwHour,
                out dwMinute,
                out dwSecond,
                ref AWorkCode
                ))
                {
                    break;
                }
                log = "User ID:" + dwEnrollNumber + " " + verificationMode(dwVerifyMode) + " " + InorOut(dwInOutMode) + " " + dwDay + "/" + dwMonth + "/" + dwYear + " " + time(dwHour) + ":" + time(dwMinute) + ":" + time(dwSecond);
                Console.WriteLine(log);
            }
        }

        static string time(int Time)
        {
            string stringTime = "";
            if (Time < 10)
            {
                stringTime = "0" + Time.ToString();
            }
            else
            {
                stringTime = Time.ToString();
            }
            return stringTime;
        }

        static string verificationMode(int verifyMode)
        {
            String mode = "";
            switch (verifyMode)
            {
                case 0:
                    mode = "Password";
                    break;
                case 1:
                    mode = "Fingerprint";
                    break;
                case 2:
                    mode = "Card";
                    break;
            }
            return mode;
        }

        static string InorOut(int InOut)
        {
            string InOrOut = "";
            switch (InOut)
            {
                case 0:
                    InOrOut = "IN";
                    break;
                case 1:
                    InOrOut = "OUT";
                    break;
                case 2:
                    InOrOut = "BREAK-OUT";
                    break;
                case 3:
                    InOrOut = "BREAK-IN";
                    break;
                case 4:
                    InOrOut = "OVERTIME-IN";
                    break;
                case 5:
                    InOrOut = "OVERTIME-OUT";
                    break;

            }
            return InOrOut;
        }
    }
}