2016-09-21 4 views
1

を働いていないようなDLLの外観。私はいくつかのイベントは何も起こらないようにしようとしている間、私はちょうどASP.NET MVCの実装を開始する前にSDKをテストするためのコンソールアプリケーションを作成した私のコードは、私は最初にデバイスに接続して、その後イベントを追加しますOnAttTransactionEx誰かが私が間違っていることを私に指摘してください。ZKEmkeeper:イベントトリガーではない、私は指紋</em>ため<em>InBios(コントローラ)を使用するアプリケーションで使用する<strong>zkemkeeperのSDK</strong>を使用しようとしてしばらくの間、stuckedだ

private static void Main(string[] args) 
    { 
     CZKEMClass zkem = new CZKEMClass(); 
     int idwErrorCode = 0; 
     const string ipAddr = "10.0.1.240"; 
     bool isConnected; 
     try 
     { 
      isConnected = zkem.Connect_Net(ipAddr, Convert.ToInt32(4370)); 
     } 
     catch (Exception ext) 
     { 
      Console.WriteLine("Erro: " + ext); 
      zkem.GetLastError(ref idwErrorCode); 
      if (idwErrorCode != 0) 
      { 
       zkem.GetLastError(idwErrorCode); 
      } 
      else 
      { 
       Console.WriteLine("No data from terminal returns!"); 
      } 
      throw new Exception(); 
     } 

     if (isConnected) 
     { 
      //Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all) 
      zkem.EnableDevice(1, true); 
      zkem.RegEvent(1, 65535); 
      zkem.OnAttTransactionEx += axCZKEM1_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; 

      zkem.EnableDevice(1, false); //disable the device 
      if (zkem.ReadGeneralLogData(1)) 
      { 
       //read all the attendance records to the memory 
       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 = (int) datetime.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; 
        try 
        { 
         Console.WriteLine(idwInOutMode); 
         Console.WriteLine(sdwEnrollNumber); 
         Console.WriteLine(unixDate); 
        } 
        catch (Exception ex) 
        { 
         //ignored 
        } 
        try 
        { 
         Console.WriteLine("inserted: " + 
              $"{idwYear}/{idwMonth}/{idwDay} {idwHour}:{idwMinute}:{idwSecond}.000"); 
        } 
        catch (Exception ex) 
        { 
        } 
       } 
      } 
      Console.WriteLine("Fim"); 
     } 
     else 
     { 
      zkem.GetLastError(ref idwErrorCode); 
      if (idwErrorCode != 0) 
      { 
       zkem.GetLastError(idwErrorCode); 
      } 
      else 
      { 
       Console.WriteLine("No data from terminal returns!"); 
      } 
     } 
     zkem.EnableDevice(1, true); 

     Console.WriteLine("Teste"); 
     do 
     { 
      while (!Console.KeyAvailable) 
      { 
      } 
     } while (Console.ReadKey(true).Key != ConsoleKey.Escape); 
    } 

    public static void axCZKEM1_OnAttTransactionEx(string sEnrollNumber, int iIsInValid, int iAttState, 
     int iVerifyMethod, int iYear, int iMonth, int iDay, int iHour, int iMinute, int iSecond, int iWorkCode) 
    { 
     Console.WriteLine("Finger Recognized"); 
    } 

答えて

1

あなたはSTAスレッドを使用する必要があります。

は、ここに私のコードです。

Thread TT = new Thread(() => 
{ 
    CZKEMClass zkem = new CZKEMClass(); 
    Application.Run(); 
}); 
TT.IsBackground = true; 
TT.SetApartmentState(ApartmentState.STA); 
TT.Start(); 

イベントを作成します。 ZKEMイベントはSTAスレッドで発生します。

+0

ありがとう、本当に役に立ちました –

+0

@WaldirDePaulaNetoどのようにあなたのコードでこれを使いましたか? – user5173426

+0

'Application'が' using System.Windows.Forms; 'からのものであるため、これはエラーをスローします。どのようにasp.net mvcで使用しますか? – user5173426

関連する問題

 関連する問題