如何在C#中使用zKemKeeper连接考勤打孔机?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在C#中使用zKemKeeper连接考勤打孔机?相关的知识,希望对你有一定的参考价值。

我正在使用asp.net c#开发考勤软件,当我尝试使用asp.net c#连接生物识别设备(考勤打孔机)时显示错误

错误:“尝试读取或写入受保护的内存。这通常表示其他内存已损坏。”

我的代码:

//internal Axzkemkeeper.AxCZKEM AxCZKEM1;
    //public Axzkemkeeper.AxCZKEM axCZKEM1 = new Axzkemkeeper.AxCZKEM();
    //public zkemkeeper.CZKEM axCZKEM1 = new zkemkeeper.CZKEM();
    //public delegate int DecompressMCX(int hComp,IntPtr in, uint in_len, IntPtr out, ref uint out_len, bool eod);

    public zkemkeeper.CZKEM axCZKEM1 = new zkemkeeper.CZKEM();

private void Essl_Connect(string IpAddress, int MachineNo)
    
        try
        
            bConn = axCZKEM1.Connect_Net(IpAddress.Trim(), 8080);
            //bConn = axCZKEM1.Connect_Net(IpAddress.Trim(), 4370);
            if (bConn == true)
            
                ScriptManager.RegisterStartupScript(this, GetType(), "Message", "alert('Connected')", true);
            
            else
            
                ScriptManager.RegisterStartupScript(this, GetType(), "Message", "alert('Not Connected')", true);
            
        
        catch (Exception ex)
        
            ScriptManager.RegisterStartupScript(this, GetType(), "Error Message", "alert('" + ex.Message.ToString() + "')", true);
        
    

任何一个人纠正这个问题,有没有其他方法来连接机器?

如果我正在使用

public zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();

它显示以下错误:

“无法嵌入Interop类型'zkemkeeper.CZKEMClass'。请改用适用的接口。”

答案

更改(在属性中)该dll interop.zkemkeeper,将类型嵌入到False。

另一答案
  1. 确保regstr正确的dll文件x64 / x32
  2. 将此代码添加到创建类的代码顶部 [SecurityPermission(SecurityAction.Assert,Unrestricted = true)]
另一答案
  1. 使用C#.NET将生物识别考勤机与.NET连接起来。现在在连接按钮的click事件上编写下面的代码。 首先声明您的连接对象: public zkemkeeper.CZKEM axCZKEM1 = new zkemkeeper.CZKEM(); private void btnconnect_Click(object sender, EventArgs e) try bool bIsConnected = axCZKEM1.Connect_Net(ip_address_of_your_machine, 4370); // 4370 is port no of attendance machine if (bIsConnected == true) MessageBox.Show("Device Connected Successfully"); else MessageBox.Show("Device Not Connect"); Catch( (Exception ex) MessageBox.Show(ex.Message.ToString());
  2. 使用C#.NET从数据库中的生物识别考勤机下载考勤日志。 在下载考勤按钮的点击事件上写下面的代码: private bool IsRead = false; string dwEnrollNumber; int dwVerifyMode, dwInOutMode, dwYear, dwMonth, dwDay, dwHour, dwMinute, dwSecond, dwWorkcode, dwMachineNumber; public zkemkeeper.CZKEM axCZKEM1 = new zkemkeeper.CZKEM(); public class ClsMachineBL public String DownloadDataFromBiomatrix(ClsMachineML prp) try string constr = CommonConnection.ConStr; con = new SqlConnection(constr); con.Open(); cmd = new SqlCommand("Prc_InsertDatafromBiomatrix", con); cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(cmd); cmd.Parameters.AddWithValue("@dwMachineNumber", prp.dwMachineNumber); cmd.Parameters.AddWithValue("@dwEnrollNumber", prp.dwEnrollNumber); cmd.Parameters.AddWithValue("@dwVerifyMode", prp.dwVerifyMode); cmd.Parameters.AddWithValue("@dwInOutMode", prp.dwInOutMode); cmd.Parameters.AddWithValue("@dwYear", prp.dwYear); cmd.Parameters.AddWithValue("@dwMonth", prp.dwMonth); cmd.Parameters.AddWithValue("@dwDay", prp.dwDay); cmd.Parameters.AddWithValue("@dwHour", prp.dwHour); cmd.Parameters.AddWithValue("@dwMinute", prp.dwMinute); cmd.Parameters.AddWithValue("@dwSecond", prp.dwSecond); cmd.Parameters.AddWithValue("@dwWorkcode", prp.dwWorkcode); cmd.ExecuteNonQuery(); catch (Exception ex) BL.clsCommon objerr = new BL.clsCommon(); objerr.InesrtError("Error IS " + ex.Message + "_" + ex.StackTrace); finally cmd.Dispose(); con.Close(); con.Dispose(); return result; public class ClsMachineML public string Id get; set; public string MachineNo get; set; public string MachineIP get; set; public string PortNo get; set; public string Remark get; set; public string Tuser get; set; public string Tdate get; set; public string Status get; set; public int dwMachineNumber get; set; public string dwEnrollNumber get; set; public int dwVerifyMode get; set; public int dwInOutMode get; set; public int dwYear get; set; public int dwMonth get; set; public int dwDay get; set; public int dwHour get; set; public int dwMinute get; set; public int dwSecond get; set; public int dwWorkcode get; set; public string User_Id get; set; public string Name get; set; public int Finger_Index get; set; public string Finger_Image get; set; public int Privilege get; set; public string Passwords get; set; public bool Enabled get; set; public int Flag get; set; public string Fromdate get; set; public string Todate get; set; private void btndownload_Click(object sender, EventArgs e) ClsMachineBL obj = new ClsMachineBL(); ClsMachineML prp = new ClsMachineML(); try if (cbmachine.Text == "" || cbmachine.Text == "Select") MessageBox.Show("Please Select Machine"); cbmachine.Focus(); return; progressBar1.Visible = true; bool bIsConnected = axCZKEM1.Connect_Net(ip_address_of_your_machine, 4370); // 4370 is port no of attendance machine if (bIsConnected == true) IsRead = axCZKEM1.ReadGeneralLogData(dwMachineNumber); if (IsRead == true) progressBar1.Maximum = 100; progressBar1.Step = 1; progressBar1.Value = 0; while (axCZKEM1.SSR_GetGeneralLogData(dwMachineNumber, out dwEnrollNumber, out dwVerifyMode, out dwInOutMode, out dwYear, out dwMonth, out dwDay, out dwHour, out dwMinute, out dwSecond, ref dwWorkcode)) prp.dwDay = dwDay; prp.dwEnrollNumber = dwEnrollNumber; prp.dwHour = dwHour; prp.dwInOutMode = dwInOutMode; prp.dwMachineNumber = dwMachineNumber; prp.dwMinute = dwMinute; prp.dwMonth = dwMonth; prp.dwSecond = dwSecond; prp.dwVerifyMode = dwVerifyMode; prp.dwWorkcode = dwWorkcode; prp.dwYear = dwYear; string add = obj.DownloadDataFromBiomatrix(prp); progressBar1.PerformStep(); string export = obj.ExportToAttendance(prp); MessageBox.Show("Attendance Downloaded Successfully"); progressBar1.Visible = false; else MessageBox.Show("No Log Found...."); progressBar1.Visible = false; else MessageBox.Show("Device Not Connected"); catch (Exception ex) MessageBox.Show(ex.Message.ToString());
  3. 使用C#.NET从数据库中的生物识别考勤机中删除考勤日志。 public zkemkeeper.CZKEM axCZKEM1 = new zkemkeeper.CZKEM(); private void btndownload_Click(object sender, EventArgs e) bool bIsConnected = axCZKEM1.Connect_Net(ip_address_of_your_machine, 4370); // 4370 is port no of attendance machine if (bIsConnected == true) bool delete = axCZKEM1.ClearGLog(dwMachineNumber); if (delete == true) MessageBox.Show("Deleted....."); if (delete == false) MessageBox.Show("No Log Found To Delete.....");

以上是关于如何在C#中使用zKemKeeper连接考勤打孔机?的主要内容,如果未能解决你的问题,请参考以下文章

使用C#代码读取中控指纹考勤机内的数据时提示错误代码-2

打孔状态在 ZK 设备上自动更改其状态

UDP 打孔 (c++/winsock)

如何控制对等端的套接字[TCP打孔]

Java TCP 打孔

浩顺晶密指纹考勤机忘记超级管理员密码且不能与电脑连接,如何重新进入考勤机进行设置? v5(新)求解。