Esempio n. 1
0
        private void Login()
        {
            CHCNetSDK.NET_DVR_USER_LOGIN_INFO struLoginInfo     = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();
            CHCNetSDK.NET_DVR_DEVICEINFO_V40  struDeviceInfoV40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
            struDeviceInfoV40.struDeviceV30.sSerialNumber = new byte[CHCNetSDK.SERIALNO_LEN];

            struLoginInfo.sDeviceAddress = textBoxDeviceAddress.Text;
            struLoginInfo.sUserName      = textBoxUserName.Text;
            struLoginInfo.sPassword      = textBoxPassword.Text;
            ushort.TryParse(textBoxPort.Text, out struLoginInfo.wPort);

            int lUserID = -1;

            lUserID = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref struDeviceInfoV40);
            if (lUserID >= 0)
            {
                m_iUserID = lUserID;
                MessageBox.Show("Login Successful");
            }
            else
            {
                uint nErr = CHCNetSDK.NET_DVR_GetLastError();
                if (nErr == CHCNetSDK.NET_DVR_PASSWORD_ERROR)
                {
                    MessageBox.Show("user name or password error!");
                    if (1 == struDeviceInfoV40.bySupportLock)
                    {
                        string strTemp1 = string.Format("Left {0} try opportunity", struDeviceInfoV40.byRetryLoginTime);
                        MessageBox.Show(strTemp1);
                    }
                }
                else if (nErr == CHCNetSDK.NET_DVR_USER_LOCKED)
                {
                    if (1 == struDeviceInfoV40.bySupportLock)
                    {
                        string strTemp1 = string.Format("user is locked, the remaining lock time is {0}", struDeviceInfoV40.dwSurplusLockTime);
                        MessageBox.Show(strTemp1);
                    }
                }
                else
                {
                    MessageBox.Show("net error or dvr is busy!");
                }
            }
        }
        private void btnDel_Click(object sender, EventArgs e)
        {
            if (pictureBoxFace.Image != null)
            {
                pictureBoxFace.Image.Dispose();
                pictureBoxFace.Image = null;
            }
            textBoxFilePath.Text = "";
            CHCNetSDK.NET_DVR_FACE_PARAM_CTRL_CARDNO struCardNo = new CHCNetSDK.NET_DVR_FACE_PARAM_CTRL_CARDNO();
            struCardNo.init();
            struCardNo.dwSize = Marshal.SizeOf(struCardNo);
            struCardNo.byMode = 0;
            int dwSize = struCardNo.dwSize;

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

            int dwEnableReaderNo = 1;

            int.TryParse(textBoxCardReaderNo.Text, out dwEnableReaderNo);
            if (dwEnableReaderNo <= 0)
            {
                dwEnableReaderNo = 1;
            }

            struCardNo.struByCard.byEnableCardReader[dwEnableReaderNo - 1] = 1;

            for (int i = 0; i < CHCNetSDK.MAX_FACE_NUM; ++i)
            {
                struCardNo.struByCard.byFaceID[i] = 1;//全部写1删除人脸
            }

            if (false == CHCNetSDK.NET_DVR_RemoteControl(m_UserID, CHCNetSDK.NET_DVR_DEL_FACE_PARAM_CFG, ref struCardNo, dwSize))
            {
                MessageBox.Show("NET_SDK_DEL_FACE_FAILED" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
            }
            else
            {
                MessageBox.Show("NET_SDK_DEL_FACE_SUCCEED", "succeed", MessageBoxButtons.OK);
            }
        }
        private void button6_Click(object sender, EventArgs e)
        {
            if (textBoxFilePath.Text == "")
            {
                MessageBox.Show("Please choose human Face path");
                return;
            }

            if (pictureBoxFace.Image != null)
            {
                pictureBoxFace.Image.Dispose();
                pictureBoxFace.Image = null;
            }

            CHCNetSDK.NET_DVR_FACE_COND struCond = new CHCNetSDK.NET_DVR_FACE_COND();
            struCond.init();
            struCond.dwSize    = Marshal.SizeOf(struCond);
            struCond.dwFaceNum = 1;
            int.TryParse(textBoxCardReaderNo.Text.ToString(), out struCond.dwEnableReaderNo);
            byte[] byTemp = System.Text.Encoding.UTF8.GetBytes(textBoxCardNo.Text);
            for (int i = 0; i < byTemp.Length; i++)
            {
                struCond.byCardNo[i] = byTemp[i];
            }

            int    dwInBufferSize = struCond.dwSize;
            IntPtr ptrstruCond    = Marshal.AllocHGlobal(dwInBufferSize);

            Marshal.StructureToPtr(struCond, ptrstruCond, false);
            m_lSetFaceCfgHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(m_UserID, CHCNetSDK.NET_DVR_SET_FACE, ptrstruCond, dwInBufferSize, null, IntPtr.Zero);
            if (-1 == m_lSetFaceCfgHandle)
            {
                Marshal.FreeHGlobal(ptrstruCond);
                MessageBox.Show("NET_DVR_SET_FACE_FAIL, ERROR CODE" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                return;
            }

            CHCNetSDK.NET_DVR_FACE_RECORD struRecord = new CHCNetSDK.NET_DVR_FACE_RECORD();
            struRecord.init();
            struRecord.dwSize = Marshal.SizeOf(struRecord);

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

            ReadFaceData(ref struRecord);
            int dwInBuffSize = Marshal.SizeOf(struRecord);
            int dwStatus     = 0;

            CHCNetSDK.NET_DVR_FACE_STATUS struStatus = new CHCNetSDK.NET_DVR_FACE_STATUS();
            struStatus.init();
            struStatus.dwSize = Marshal.SizeOf(struStatus);
            int    dwOutBuffSize = struStatus.dwSize;
            IntPtr ptrOutDataLen = Marshal.AllocHGlobal(sizeof(int));
            bool   Flag          = true;

            while (Flag)
            {
                dwStatus = CHCNetSDK.NET_DVR_SendWithRecvRemoteConfig(m_lSetFaceCfgHandle, ref struRecord, dwInBuffSize, ref struStatus, dwOutBuffSize, ptrOutDataLen);
                switch (dwStatus)
                {
                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_SUCCESS:    //成功读取到数据,处理完本次数据后需调用next
                    ProcessSetFaceData(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_lSetFaceCfgHandle);
                    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_lSetFaceCfgHandle);
                    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_lSetFaceCfgHandle);
                    break;
                }
            }

            Marshal.FreeHGlobal(ptrstruCond);
            Marshal.FreeHGlobal(ptrOutDataLen);
        }
        private void btnCapture_Click(object sender, EventArgs e)
        {
            if (m_lCapFaceCfgHandle != -1)
            {
                CHCNetSDK.NET_DVR_StopRemoteConfig(m_lCapFaceCfgHandle);
                m_lCapFaceCfgHandle = -1;
            }
            if (pictureBoxFace.Image != null)
            {
                pictureBoxFace.Image.Dispose();
                pictureBoxFace.Image = null;
            }
            textBoxFilePath.Text = "";

            CHCNetSDK.NET_DVR_CAPTURE_FACE_COND struCond = new CHCNetSDK.NET_DVR_CAPTURE_FACE_COND();
            struCond.init();
            struCond.dwSize = Marshal.SizeOf(struCond);
            int    dwInBufferSize = struCond.dwSize;
            IntPtr ptrStruCond    = Marshal.AllocHGlobal(dwInBufferSize);

            Marshal.StructureToPtr(struCond, ptrStruCond, false);
            m_lCapFaceCfgHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(m_UserID, CHCNetSDK.NET_DVR_CAPTURE_FACE_INFO, ptrStruCond, dwInBufferSize, null, IntPtr.Zero);
            if (-1 == m_lCapFaceCfgHandle)
            {
                Marshal.FreeHGlobal(ptrStruCond);
                MessageBox.Show("NET_DVR_CAP_FACE_FAIL, ERROR CODE" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                return;
            }

            CHCNetSDK.NET_DVR_CAPTURE_FACE_CFG struFaceCfg = new CHCNetSDK.NET_DVR_CAPTURE_FACE_CFG();
            struFaceCfg.init();
            int  dwStatus      = 0;
            int  dwOutBuffSize = Marshal.SizeOf(struFaceCfg);
            bool Flag          = true;

            while (Flag)
            {
                dwStatus = CHCNetSDK.NET_DVR_GetNextRemoteConfig(m_lCapFaceCfgHandle, ref struFaceCfg, dwOutBuffSize);
                switch (dwStatus)
                {
                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_SUCCESS:    //成功读取到数据,处理完本次数据后需调用next
                    ProcessCapFaceData(ref struFaceCfg, 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_lCapFaceCfgHandle);
                    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_lCapFaceCfgHandle);
                    Flag = false;
                    break;

                default:
                    MessageBox.Show("NET_SDK_GET_STATUS_UNKOWN" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                    Flag = false;
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lCapFaceCfgHandle);
                    break;
                }
            }
            Marshal.FreeHGlobal(ptrStruCond);
        }
        private void btnGet_Click(object sender, EventArgs e)
        {
            if (m_lGetFaceCfgHandle != -1)
            {
                CHCNetSDK.NET_DVR_StopRemoteConfig(m_lGetFaceCfgHandle);
                m_lGetFaceCfgHandle = -1;
            }

            if (pictureBoxFace.Image != null)
            {
                pictureBoxFace.Image.Dispose();
                pictureBoxFace.Image = null;
            }

            CHCNetSDK.NET_DVR_FACE_COND struCond = new CHCNetSDK.NET_DVR_FACE_COND();
            struCond.init();
            struCond.dwSize = Marshal.SizeOf(struCond);
            int dwSize = struCond.dwSize;

            if (textBoxCardReaderNo.Text.ToString() == "")
            {
                struCond.dwEnableReaderNo = 0;
            }
            else
            {
                int.TryParse(textBoxCardReaderNo.Text.ToString(), out struCond.dwEnableReaderNo);
            }
            struCond.dwFaceNum = 1;//人脸数量是1
            byte[] byTemp = System.Text.Encoding.UTF8.GetBytes(textBoxCardNo.Text);
            for (int i = 0; i < byTemp.Length; i++)
            {
                struCond.byCardNo[i] = byTemp[i];
            }

            IntPtr ptrStruCond = Marshal.AllocHGlobal(dwSize);

            Marshal.StructureToPtr(struCond, ptrStruCond, false);

            m_lGetFaceCfgHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(m_UserID, CHCNetSDK.NET_DVR_GET_FACE, ptrStruCond, dwSize, null, IntPtr.Zero);
            if (m_lGetFaceCfgHandle == -1)
            {
                Marshal.FreeHGlobal(ptrStruCond);
                MessageBox.Show("NET_DVR_GET_FACE_FAIL, ERROR CODE" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                return;
            }

            bool Flag     = true;
            int  dwStatus = 0;

            CHCNetSDK.NET_DVR_FACE_RECORD struRecord = new CHCNetSDK.NET_DVR_FACE_RECORD();
            struRecord.init();
            struRecord.dwSize = Marshal.SizeOf(struRecord);
            int dwOutBuffSize = struRecord.dwSize;

            while (Flag)
            {
                dwStatus = CHCNetSDK.NET_DVR_GetNextRemoteConfig(m_lGetFaceCfgHandle, ref struRecord, dwOutBuffSize);
                switch (dwStatus)
                {
                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_SUCCESS:    //成功读取到数据,处理完本次数据后需调用next
                    ProcessFaceData(ref struRecord, 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_lGetFaceCfgHandle);
                    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_lGetFaceCfgHandle);
                    Flag = false;
                    break;

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

            Marshal.FreeHGlobal(ptrStruCond);
        }