我正在尝试连接网络中的RFID和生物指标设备,我的本地IP是192.168.1.24
,RFID设备ip是192.168.1.22
,我正在使用Visual Studio 12示例窗口应用程序。连接此设备但它会引发错误:
无法连接设备,错误代码= -201
private void btnConnect_Click(object sender, EventArgs e)
{
if (txtIP.Text.Trim() == "" || txtPort.Text.Trim() == "")
{
MessageBox.Show("IP and Port cannot be null", "Error");
return;
}
int idwErrorCode = 0;
Cursor = Cursors.WaitCursor;
if (btnConnect.Text == "DisConnect")
{
axCZKEM1.Disconnect();
this.axCZKEM1.OnVerify -= new zkemkeeper._IZKEMEvents_OnVerifyEventHandler(axCZKEM1_OnVerify);
this.axCZKEM1.OnAttTransactionEx -= new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
this.axCZKEM1.OnNewUser -= new zkemkeeper._IZKEMEvents_OnNewUserEventHandler(axCZKEM1_OnNewUser);
this.axCZKEM1.OnHIDNum -= new zkemkeeper._IZKEMEvents_OnHIDNumEventHandler(axCZKEM1_OnHIDNum);
this.axCZKEM1.OnWriteCard -= new zkemkeeper._IZKEMEvents_OnWriteCardEventHandler(axCZKEM1_OnWriteCard);
this.axCZKEM1.OnEmptyCard -= new zkemkeeper._IZKEMEvents_OnEmptyCardEventHandler(axCZKEM1_OnEmptyCard);
bIsConnected = false;
btnConnect.Text = "Connect";
lblState.Text = "Current State:DisConnected";
Cursor = Cursors.Default;
return;
}
axCZKEM1.PullMode = 1;
bIsConnected = axCZKEM1.Connect_Net(txtIP.Text.Trim(), Convert.ToInt32(txtPort.Text.Trim()));
if (bIsConnected == true)
{
btnConnect.Text = "DisConnect";
btnConnect.Refresh();
lblState.Text = "Current State:Connected";
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.
if (axCZKEM1.RegEvent(iMachineNumber, 65535))//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
{
this.axCZKEM1.OnVerify += new zkemkeeper._IZKEMEvents_OnVerifyEventHandler(axCZKEM1_OnVerify);
this.axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
this.axCZKEM1.OnNewUser += new zkemkeeper._IZKEMEvents_OnNewUserEventHandler(axCZKEM1_OnNewUser);
this.axCZKEM1.OnHIDNum += new zkemkeeper._IZKEMEvents_OnHIDNumEventHandler(axCZKEM1_OnHIDNum);
this.axCZKEM1.OnWriteCard += new zkemkeeper._IZKEMEvents_OnWriteCardEventHandler(axCZKEM1_OnWriteCard);
this.axCZKEM1.OnEmptyCard += new zkemkeeper._IZKEMEvents_OnEmptyCardEventHandler(axCZKEM1_OnEmptyCard);
}
MyCountFinger = 1;
MyCountFace = 2;
}
else
{
axCZKEM1.GetLastError(ref idwErrorCode);
MessageBox.Show("Unable to connect the device,ErrorCode=" + idwErrorCode.ToString(), "Error");
}
Cursor = Cursors.Default;
}
请提前帮助谢谢
答案 0 :(得分:0)
bool isConnected;
try {
isConnected = zkem.Connect_Net(ipAddr.Text, Convert.ToInt32(4370));
} catch (Exception ext) {
Debug.WriteLine("Холбогдож чадсангүй" + ext);
zkem.GetLastError(ref idwErrorCode);
if (idwErrorCode != 0) {
getError(idwErrorCode);
} else {
MessageBox.Show("No data from terminal returns!", "Error");
}
throw new Exception();
}
if (isConnected) { //Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
this.btnRC.Enabled = false;
zkem.EnableDevice(1, true);
zkem.RegEvent(1, 65535);
this.zkem.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(onAttTransactionEx);
string sdwEnrollNumber = "";
int idwVerifyMode = 0;
int idwInOutMode = 0;
int idwYear = 0;
int idwMonth = 0;
int idwDay = 0;
int idwHour = 0;
int idwMinute = 0;
int idwSecond = 0;
int idwWorkcode = 0;
Cursor = Cursors.WaitCursor;
zkem.EnableDevice(1, false);//disable the device
if (zkem.ReadGeneralLogData(1)) { //read all the attendance records to the memory
Debug.WriteLine("Trying to open connection");
m_dbConnection.Open();
Debug.WriteLine("Connection Opened");
using (var command = new SQLiteCommand(m_dbConnection)) {
using (var transaction = m_dbConnection.BeginTransaction()) {
command.CommandText = String.Format("INSERT INTO `{0}` (`state`, `user_id`, `date`) VALUES(@state, @userID, @date)", prefix);
command.Prepare();
while (zkem.SSR_GetGeneralLogData(1, out sdwEnrollNumber, out idwVerifyMode,
out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour,
out idwMinute, out idwSecond, ref idwWorkcode)) { //get records from the memory
DateTime datetime = new DateTime(idwYear, idwMonth, idwDay, idwHour, idwMinute, idwSecond);
int unixDate = (Int32)(datetime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
try {
command.Parameters.AddWithValue("@state", idwInOutMode);
command.Parameters.AddWithValue("@userID", Convert.ToInt32(sdwEnrollNumber));
command.Parameters.AddWithValue("@date", unixDate);
} catch (Exception ex) {
//Debug.WriteLine(ex.ToString() + Environment.NewLine + ex.StackTrace);
}
try {
command.ExecuteNonQuery();
Debug.WriteLine("inserted: " + String.Format("{0}/{1}/{2} {3}:{4}:{5}.000", idwYear , idwMonth, idwDay, idwHour, idwMinute, idwSecond));
} catch (SQLiteException ex) {
Debug.WriteLine(ex.ToString() + " "+ex.StackTrace);
}
}
transaction.Commit();
}
}
m_dbConnection.Close();
Debug.WriteLine("Connection Closed");
Cursor = Cursors.Default;
} else {
Cursor = Cursors.Default;
zkem.GetLastError(ref idwErrorCode);
if (idwErrorCode != 0) {
getError(idwErrorCode);
} else {
MessageBox.Show("No data from terminal returns!", "Error");
}
}
zkem.EnableDevice(1, true); //enable the device
Cursor = Cursors.Default;
logBox.Items.Add("Холбогдлоо");
}
这是我的连接代码。我只使用指纹。这很好用。