Zkemkeeper На события не отвечают - PullRequest
0 голосов
/ 20 января 2020

При попытке получить записи отпечатков пальцев в режиме реального времени события не инициируются. Часы подключены, и другие функции возвращают данные правильно, но вы не в режиме реального времени.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Management;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using MySql.Data.MySqlClient;

namespace WinServicioReloj
{
    public partial class WinServicioReloj : ServiceBase
    {
        private static string StringConexion;
        private static MySqlConnection conectarSql;
        private int eventId = 1;
        private bool bIsConnected = false;

        private int errorCode;
        private int iMachineNumber = 1;

        public WinServicioReloj()
        {
            InitializeComponent();
            if (!EventLog.SourceExists("WinServicioReloj"))
            {
                EventLog.CreateEventSource("WinServicioReloj", "MyLogWinServicioReloj");
                Console.WriteLine("CreatedEventSource");
                return;
            }

            eventLog1.Source = "WinServicioReloj";
            eventLog1.Log = "MyLogWinServicioReloj";
            EventLog myLog = new EventLog
            {
                Source = "MySource"
            };
        }

        private void axCZKEM1_OnFinger()
        {
            eventLog1.WriteEntry("RTEvent OnFinger Has been Triggered");
        }

        //After you have placed your finger on the sensor(or swipe your card to the device),this event will be triggered.
        //If you passes the verification,the returned value userid will be the user enrollnumber,or else the value will be -1;
        private void axCZKEM1_OnVerify(int iUserID)
        {
            eventLog1.WriteEntry("RTEvent OnVerify Has been Triggered,Verifying...");
            if (iUserID != -1)
            {
                eventLog1.WriteEntry("Verified OK,the UserID is " + iUserID.ToString());
            }
            else
            {
                eventLog1.WriteEntry("Verified Failed... ");
            }
        }

        //If your fingerprint(or your card) passes the verification,this event will be triggered
        private 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)
        {
            eventLog1.WriteEntry("RTEvent OnAttTrasactionEx Has been Triggered,Verified OK");
            eventLog1.WriteEntry("...UserID:" + sEnrollNumber);
            eventLog1.WriteEntry("...isInvalid:" + iIsInValid.ToString());
            eventLog1.WriteEntry("...attState:" + iAttState.ToString());
            eventLog1.WriteEntry("...VerifyMethod:" + iVerifyMethod.ToString());
            eventLog1.WriteEntry("...Workcode:" + iWorkCode.ToString());//the difference between the event OnAttTransaction and OnAttTransactionEx
            eventLog1.WriteEntry("...Time:" + iYear.ToString() + "-" + iMonth.ToString() + "-" + iDay.ToString() + " " + iHour.ToString() + ":" + iMinute.ToString() + ":" + iSecond.ToString());
        }

        protected override void OnStop()
        {

            eventLog1.WriteEntry("OnStop");
        }

        protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("OnStart");
            try
            {
                eventLog1.WriteEntry("Try");
                Thread createComAndMessagePumpThread = new Thread(() =>
                {
                    eventLog1.WriteEntry("Thread");
                    zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();
                    StringConexion = @"Server=******; Database=**********; Uid=**********; Pwd=**************; Port=3306;";
                    conectarSql = new MySqlConnection(StringConexion);
                    conectarSql.Open();
                    eventLog1.WriteEntry("Conec");
                    string query = "SELECT id, dispositivo_ip, dispositivo_puerto FROM dispositivos";
                    MySqlCommand mycommand = new MySqlCommand(query, conectarSql);
                    mycommand.CommandTimeout = 360;
                    MySqlDataReader myreader = mycommand.ExecuteReader();
                    while (myreader.Read())
                    {
                        int idwErrorCode = 0;
                        string Id_dispositivo = myreader["id"].ToString();
                        string axIp = myreader["dispositivo_ip"].ToString();
                        int axPuerto = Convert.ToInt32(Convert.ToDecimal(myreader["dispositivo_puerto"].ToString()));
                        eventLog1.WriteEntry("Dispositivo: " + Id_dispositivo + "-" + axIp + "-" + axPuerto, EventLogEntryType.Information);

                        bIsConnected = axCZKEM1.Connect_Net(axIp, Convert.ToInt32(myreader["dispositivo_puerto"].ToString()));
                        if (bIsConnected == true)
                        {
                            iMachineNumber = 1;

                            if (axCZKEM1.RegEvent(iMachineNumber, 65535))
                            {

                                axCZKEM1.OnFinger += new zkemkeeper._IZKEMEvents_OnFingerEventHandler(axCZKEM1_OnFinger);
                                axCZKEM1.OnVerify += new zkemkeeper._IZKEMEvents_OnVerifyEventHandler(axCZKEM1_OnVerify);
                                axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
                            }
                            else
                            {
                                axCZKEM1.GetLastError(ref idwErrorCode);
                                int ret = idwErrorCode;

                                if (idwErrorCode != 0)
                                {
                                    eventLog1.WriteEntry("*RegEvent failed,ErrorCode: " + idwErrorCode.ToString());
                                }
                                else
                                {
                                    eventLog1.WriteEntry("*No data from terminal returns!");
                                }
                            }
                        }
                        else
                        {
                            axCZKEM1.GetLastError(ref idwErrorCode);
                            eventLog1.WriteEntry("Unable to connect the device,ErrorCode=" + idwErrorCode.ToString());
                        }
                    }
                });
                createComAndMessagePumpThread.SetApartmentState(ApartmentState.STA);

                createComAndMessagePumpThread.Start();
            }
            catch (Exception ex)
            {
                eventLog1.WriteEntry("Error: " + ex.Message, EventLogEntryType.Error, eventId++);
            }
        }
    }
}

Я пытался удалить потоки и добавить таймер, но он не работает так же. У меня есть пример с формой, где она работает правильно (все точно так же), но я не могу найти ошибку.

Я пытался с

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

и

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