我有面部识别装置。这个设备有一个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();
}
答案 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;通过掩码注册事件:
事件OnConnected()和OnDisConnected()在没有RegEvent()的情况下工作 并在连接前添加