生物识别设备ping一段时间后失败 [英] Biometrics device ping becoming failed after sometime

查看:168
本文介绍了生物识别设备ping一段时间后失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 ZKTeco 生物识别设备,该设备使用 本教程(C#ZKTeco生物识别设备入门) .

I have ZKTeco Biometrics device which is connected with a C# windows application using This tutorial (C# ZKTeco Biometric Device Getting Started).

它工作正常,但是一段时间后,我的应用程序无法ping设备.如以下代码所示,我尝试每隔25秒对设备进行一次ping操作.

It is working fine but after sometime, my application becoming failed to ping the device. As below code suggested, I am trying to ping the device after every 25 seconds.

  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都能正常运行.我不知道问题出在哪里?是网络问题还是其编码问题?

And when I am trying to ping the command from cmd the device show destination host is unreachable. But whenever I restart the device, the ping working fine. I don't know where is the problem? Either the network problem or its coding issue?

注意:我正在按固定的时间间隔执行ping操作,因为在断开连接事件上不起作用.我假设ping操作失败是因为设备已与应用程序断开连接.

Note: I am doing a ping on regular time interval, because on Disconnected Event is not working. I am assuming ping failed meaning is the device has disconnected with the application.

推荐答案

首先:谢谢您浏览我的文章

您做错了方法.

每25秒尝试一次ping设备是不必要的.

Trying to ping the device after every 25 seconds is unnecessary.

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

The only job of the UniversalStatic.PingTheDevice method is to check if the device is presumably active, the first time you connect with the device.

如果要检查设备的状态 ie IsDeviceConnected,只需注册SDK提供的设备 OnDisConnected 事件.

If you want to check the status of the device i.e IsDeviceConnected, All you need to do is register to the device OnDisConnected event provided by the SDK.

似乎此处的代码数字57已经为您完成了 OnDisConnected 事件注册.

It seems the code here at line number 57 has already done the OnDisConnected event registration for you.

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

All you need to do now is set your IsDeviceConnected to false when the objCZKEM_OnDisConnected method in the ZkemClient.cs class is called upon by the device itself.

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

Sample snippet : In the ZkemClient.cs class file, between line number 81-84

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

现在,每次您尝试拨打该设备时,您要做的就是检查 IsDeviceConnected 的值.

Now, Every time you try to make a call to the device, All you need to do is check for the value of your IsDeviceConnected.

这篇关于生物识别设备ping一段时间后失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆