Beispiel #1
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (m_lSetFingerPrintCfgHandle != -1)
            {
                CHCNetSDK.NET_DVR_StopRemoteConfig((int)m_lSetFingerPrintCfgHandle);
                m_lSetFingerPrintCfgHandle = -1;
            }

            CHCNetSDK.NET_DVR_FINGERPRINT_COND strupond = new CHCNetSDK.NET_DVR_FINGERPRINT_COND();
            strupond.init();
            int dwSize = Marshal.SizeOf(strupond);

            strupond.dwSize = dwSize;
            byte.TryParse(textBoxFingerID.Text, out strupond.byFingerPrintID);
            int.TryParse(textBoxCardReaderNo.Text, out strupond.dwEnableReaderNo);
            strupond.dwFingerprintNum = 1;//指纹数量写死的
            byte[] byTempptrRec = System.Text.Encoding.UTF8.GetBytes(textBoxCardNo.Text);
            for (int i = 0; i < byTempptrRec.Length; i++)
            {
                strupond.byCardNo[i] = byTempptrRec[i];
            }

            IntPtr ptrStrucond = Marshal.AllocHGlobal(dwSize);

            Marshal.StructureToPtr(strupond, ptrStrucond, false);

            m_lSetFingerPrintCfgHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(m_UserID, CHCNetSDK.NET_DVR_SET_FINGERPRINT, ptrStrucond, dwSize, null, IntPtr.Zero);
            if (-1 == m_lSetFingerPrintCfgHandle)
            {
                Marshal.FreeHGlobal(ptrStrucond);
                MessageBox.Show("NET_DVR_SET_FINGERPRINT_CFG_V50 FAIL, ERROR CODE" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                return;
            }

            Boolean Flag     = true;
            int     dwStatus = 0;

            CHCNetSDK.NET_DVR_FINGERPRINT_RECORD StruRecord = new CHCNetSDK.NET_DVR_FINGERPRINT_RECORD();
            StruRecord.init();
            int dwInBuffSize = Marshal.SizeOf(StruRecord);

            StruRecord.dwSize = dwInBuffSize;
            byte.TryParse(textBoxFingerID.Text, out StruRecord.byFingerPrintID);
            int.TryParse(textBoxCardReaderNo.Text, out StruRecord.dwEnableReaderNo);

            byte[] byTemp = System.Text.Encoding.UTF8.GetBytes(textBoxCardNo.Text);
            for (int i = 0; i < byTemp.Length; i++)
            {
                StruRecord.byCardNo[i] = byTemp[i];
            }
            ReadFingerData(ref StruRecord);

            CHCNetSDK.NET_DVR_FINGERPRINT_STATUS StruStatus = new CHCNetSDK.NET_DVR_FINGERPRINT_STATUS();
            StruStatus.init();
            int dwOutBuffSize = Marshal.SizeOf(StruStatus);

            StruStatus.dwSize = dwOutBuffSize;
            IntPtr ptrOutDataLen = Marshal.AllocHGlobal(sizeof(int));


            while (Flag)
            {
                dwStatus = CHCNetSDK.NET_DVR_SendWithRecvRemoteConfig(m_lSetFingerPrintCfgHandle, ref StruRecord, dwInBuffSize, ref StruStatus, dwOutBuffSize, ptrOutDataLen);
                switch (dwStatus)
                {
                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_SUCCESS:    //成功读取到数据,处理完本次数据后需调用next
                    ProcessSetFingerData(ref StruStatus, ref Flag);
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_NEED_WAIT:
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_FAILED:
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lSetFingerPrintCfgHandle);
                    MessageBox.Show("NET_SDK_GET_NEXT_STATUS_FAILED" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                    Flag = false;
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_FINISH:
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lSetFingerPrintCfgHandle);
                    Flag = false;
                    break;

                default:
                    MessageBox.Show("NET_SDK_GET_NEXT_STATUS_UNKOWN" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                    Flag = false;
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lSetFingerPrintCfgHandle);
                    break;
                }
            }

            Marshal.FreeHGlobal(ptrStrucond);
            Marshal.FreeHGlobal(ptrOutDataLen);
        }
Beispiel #2
0
        private void btnGet_Click(object sender, EventArgs e)
        {
            if (m_lGetFingerPrintCfgHandle != -1)
            {
                CHCNetSDK.NET_DVR_StopRemoteConfig((int)m_lGetFingerPrintCfgHandle);
                m_lGetFingerPrintCfgHandle = -1;
            }
            textBoxFingerData.Text = "";

            CHCNetSDK.NET_DVR_FINGERPRINT_COND struCond = new CHCNetSDK.NET_DVR_FINGERPRINT_COND();
            struCond.init();
            struCond.dwSize           = Marshal.SizeOf(struCond);
            struCond.dwFingerprintNum = 1;
            byte.TryParse(textBoxFingerID.Text, out struCond.byFingerPrintID);
            byte[] byTemp = System.Text.Encoding.UTF8.GetBytes(textBoxCardNo.Text);
            for (int i = 0; i < byTemp.Length; i++)
            {
                struCond.byCardNo[i] = byTemp[i];
            }
            int.TryParse(textBoxCardReaderNo.Text, out struCond.dwEnableReaderNo);
            int    dwSize      = Marshal.SizeOf(struCond);
            IntPtr ptrStruCond = Marshal.AllocHGlobal(dwSize);

            Marshal.StructureToPtr(struCond, ptrStruCond, false);
            m_lGetFingerPrintCfgHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(m_UserID, CHCNetSDK.NET_DVR_GET_FINGERPRINT, ptrStruCond, dwSize, null, IntPtr.Zero);
            if (-1 == m_lGetFingerPrintCfgHandle)
            {
                Marshal.FreeHGlobal(ptrStruCond);
                MessageBox.Show("NET_DVR_GET_FINGERPRINT_CFG_V50 FAIL, ERROR CODE" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                return;
            }

            Boolean Flag = true;

            CHCNetSDK.NET_DVR_FINGERPRINT_RECORD struOutBuff = new CHCNetSDK.NET_DVR_FINGERPRINT_RECORD();
            struOutBuff.init();
            int dWsize   = Marshal.SizeOf(struOutBuff);
            int dwStatus = 0;

            while (Flag)
            {
                dwStatus = CHCNetSDK.NET_DVR_GetNextRemoteConfig(m_lGetFingerPrintCfgHandle, ref struOutBuff, dWsize);
                switch (dwStatus)
                {
                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_SUCCESS:    //成功读取到数据,处理完本次数据后需调用next
                    ProcessFingerData(ref struOutBuff, ref Flag);
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_NEED_WAIT:
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_FAILED:
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lGetFingerPrintCfgHandle);
                    MessageBox.Show("NET_SDK_GET_NEXT_STATUS_FAILED" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                    Flag = false;
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_FINISH:
                    MessageBox.Show("NET_SDK_GET_NEXT_STATUS_FINISH", "Tips", MessageBoxButtons.OK);
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lGetFingerPrintCfgHandle);
                    Flag = false;
                    break;

                default:
                    MessageBox.Show("NET_SDK_GET_NEXT_STATUS_UNKOWN" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lGetFingerPrintCfgHandle);
                    Flag = false;
                    break;
                }
            }
            Marshal.FreeHGlobal(ptrStruCond);
        }