首页 > 解决方案 > 生物识别设备 ping 一段时间后失败

问题描述

我有ZKTeco Biometrics 设备,它使用This tutorial (C# ZKTeco Biometric Device Getting Started)与 C# windows 应用程序连接。

它工作正常,但一段时间后,我的应用程序无法 ping 设备。如下代码所示,我尝试每 25 秒 ping 一次设备。

  private void TimerCheckPingAndCloseAttendanceForm() {
  timerCheckPingAndCloseAttendanceForm            = new Timer();
  timerCheckPingAndCloseAttendanceForm.Tick       += new EventHandler(CheckPingAndCloseAttendanceForm);
  timerCheckPingAndCloseAttendanceForm.Interval   = 25000;//25 seconds.
  timerCheckPingAndCloseAttendanceForm.Start();
        }


 private void CheckPingAndCloseAttendanceForm(object sender, EventArgs e) {
     string ipAddress = tbxDeviceIP.Text.Trim();
     if (UniversalStatic.PingTheDevice(ipAddress) == false) {
           //CloseAttendaceListForm();
           IsDeviceConnected = false;
           string infoString = "Application started on " + applicationStartDateTime.ToString() + " and ping failed on " + DateTime.Now.ToString() + " then, app closed while device ip is "+ ipAddress;
          File.AppendAllText("ConnectionLog.txt", infoString + Environment.NewLine);
          Application.Exit();
          //timerCheckPingAndCloseAttendanceForm.Tick -= new EventHandler(CheckPingAndCloseAttendanceForm);
            }
        }

当我尝试从 cmd ping 命令时,设备显示destination host is unreachable。但是每当我重新启动设备时,ping 工作正常。不知道问题出在哪里?是网络问题还是它的编码问题?

注意:我正在定期执行 ping 操作,因为Disconnected Event is not working。我假设 ping 失败意味着设备已与应用程序断开连接。

标签: c#connectionbiometricszktecozkemkeeper

解决方案


首先:感谢您阅读我的文章

你做错了。

每 25 秒后尝试 ping 设备是不必要的。

UniversalStatic.PingTheDevice方法的唯一工作是在您第一次连接设备时检查设备是否可能处于活动状态。

如果要查看设备的状态,只需注册SDK提供的设备OnDisConnected 事件即可。IsDeviceConnected

似乎第 57 行的代码已经为您完成了OnDisConnected事件注册。

当设备本身调用 ZkemClient.cs 类中的objCZKEM_OnDisConnected方法时,您现在需要做的就是将IsDeviceConnected设置为 false 。

示例片段: 在 ZkemClient.cs 类文件中,行号 81-84 之间

void objCZKEM_OnDisConnected()
{
     IsDeviceConnected = false;  // <-- Add this line
}

现在,每次您尝试调用设备时,您需要做的就是检查IsDeviceConnected的值。


推荐阅读