为什么zkemkeeper SDK OnConnected事件不会触发?

时间:2017-06-06 13:54:51

标签: c# events

我有面部识别装置。这个设备有一个SDK。我用它来向设备发送命令,但它不会触发某些事件。未触发onConnected和OnDisconnected函数,但正在调用onAttendanceTransaction函数。为什么没有调用其他函数?

代码:

  public void init()
    {
        Thread machineActionListener = new Thread(() =>
        {
            connect();
            Application.Run();
        });

        machineActionListener.SetApartmentState(ApartmentState.STA);
        machineActionListener.Start();
    }

    private CZKEMClass getDeviceApi()
    {
        if(deviceApi == null)
        {
            deviceApi = new CZKEMClass();
        }
        return deviceApi;
    }

    private void connect()
    {
        Logger.log("Connecting to ...", machine.getMachineInfo());
        Boolean isConnected = getDeviceApi().Connect_Net(this.machine.ip, this.machine.port);
        if (isConnected)
        {
            connectionTryCount = 0;
            Logger.log("Connected!");

            if (getDeviceApi().RegEvent(this.machine.machineCode, 65535))
            {
                getDeviceApi().OnAttTransactionEx += new _IZKEMEvents_OnAttTransactionExEventHandler(onAttendanceTransaction);
                getDeviceApi().OnConnected += new _IZKEMEvents_OnConnectedEventHandler(onConnected);
                getDeviceApi().OnDisConnected += new _IZKEMEvents_OnDisConnectedEventHandler(onDisConnected);

            }
        }
        else
        {
            Logger.log("Could not be connected! Reconnecting...", machine.getMachineInfo());
            if(connectionTryCount < Config.CONNECTION_TRY_LIMIT)
            {
                connectionTryCount++;
                connect();
            }
            else
            {
                Logger.logAndMail("Cihaza " + Config.CONNECTION_TRY_LIMIT + " connection limit exceed!",
                    "Cihaz Bilgileri: " + machine.getMachineInfo());
            }
        }
    }

    private void onConnected()
    {
        Logger.log("Connected to device: " + machine.getMachineInfo());
    }

    private void onDisConnected()
    {
        Logger.log("Disconnected from device: " + machine.getMachineInfo());
        connect();
    }

1 个答案:

答案 0 :(得分:1)

试一试:

        private void connect()
{
    Logger.log("Connecting to ...", machine.getMachineInfo());

    getDeviceApi().OnConnected += new _IZKEMEvents_OnConnectedEventHandler(onConnected);
    getDeviceApi().OnDisConnected += new _IZKEMEvents_OnDisConnectedEventHandler(onDisConnected);

    Boolean isConnected = getDeviceApi().Connect_Net(this.machine.ip, this.machine.port);
    if (isConnected)
    {
        connectionTryCount = 0;
        Logger.log("Connected!");

        if (getDeviceApi().RegEvent(this.machine.machineCode, 65535))
        {
            getDeviceApi().OnAttTransactionEx += new _IZKEMEvents_OnAttTransactionExEventHandler(onAttendanceTransaction);
        }
    }
}

RegEvent - &gt;通过掩码注册事件:

  • 1 OnAttTransaction,OnAttTransactionEx
  • 2 OnFinger
  • 4 OnNewUser
  • 8 OnEnrollFinger
  • 16 OnKeyPress
  • 256 OnVerify
  • 512 OnFingerFeature
  • 1024 OnDoor,OnAlarm
  • 2048 OnHIDNum
  • 4096 OnWriteCard
  • 8192 OnEmptyCard
  • 16384 OnDeleteTemplate

事件OnConnected()和OnDisConnected()在没有RegEvent()的情况下工作 并在连接前添加