public int sta_ConnectTCP(List <string> lblOutputInfo, string ip, string port, string commKey) { if (ip == "" || port == "" || commKey == "") { lblOutputInfo.Add("*Name, IP, Port or Commkey cannot be null !"); return(-1);// ip or port is null } if (Convert.ToInt32(port) <= 0 || Convert.ToInt32(port) > 65535) { lblOutputInfo.Add("*Port illegal!"); return(-1); } if (Convert.ToInt32(commKey) < 0 || Convert.ToInt32(commKey) > 999999) { lblOutputInfo.Add("*CommKey illegal!"); return(-1); } int idwErrorCode = 0; axCZKEM1.SetCommPassword(Convert.ToInt32(commKey)); if (bIsConnected == true) { axCZKEM1.Disconnect(); SetConnectState(false); lblOutputInfo.Add("Disconnect with device !"); //connected = false; return(-2); //disconnect } if (axCZKEM1.Connect_Net(ip, Convert.ToInt32(port)) == true) { SetConnectState(true); lblOutputInfo.Add("Connect with device !"); return(1); } else { axCZKEM1.GetLastError(ref idwErrorCode); lblOutputInfo.Add("*Unable to connect the device,ErrorCode=" + idwErrorCode.ToString()); return(idwErrorCode); } }