我正在使用asp.net c#开发考勤软件,当我尝试使用asp.net c#连接生物识别设备(考勤打孔机)时显示错误
错误: "尝试读取或写入受保护的内存。这通常表明其他内存已损坏。"
我的代码:
array_diff()
任何人都可以解决这个问题,是否有其他方法可以连接机器?...
如果我使用
public zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();
它显示以下错误:
" Interop type' zkemkeeper.CZKEMClass'无法嵌入。请改用适用的界面。"
答案 0 :(得分:3)
更改(在属性中)该dll interop.zkemkeeper,将类型嵌入为False。
答案 1 :(得分:0)
将此代码添加到创建类的代码顶部
[SecurityPermission(SecurityAction.Assert,Unrestricted = true)]
答案 2 :(得分:0)
public static CZKEM axCZKEM1 = new CZKEM();
private static bool bIsConnected;
private static int iMachineNumber;
public static bool ConnectDevice(string IP,int Port)
{
int idwErrorCode=0;
try
{
bIsConnected = axCZKEM1.Connect_Net(IP.Trim(),Port);
if (bIsConnected)
{
iMachineNumber = 1; //In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
axCZKEM1.EnableDevice(iMachineNumber, false);
axCZKEM1.RegEvent(iMachineNumber, 65535); //
return true;
}
else
{
axCZKEM1.GetLastError(idwErrorCode);
new Exception($"Error : Unable to connect the device, ErrorCode = {idwErrorCode}");
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
public static bool DisconnectDevice()
{
try
{
axCZKEM1.Disconnect();
return true;
}
catch (Exception ex)
{
throw ex;
}
答案 3 :(得分:-1)
使用C#.NET将生物识别考勤机与.NET连接。 现在在连接按钮的点击事件上写下面的代码。
首先声明你的连接对象:
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());
}
}
使用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());
}
}
使用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.....");
}
}
}