コード例 #1
1
ファイル: ClientDemo.cs プロジェクト: isliulin/07-CRAB310
        public void ReConnect(object source, System.Timers.ElapsedEventArgs e)
        {
            foreach (DEV_INFO devinfo in dictDiscontDev.Values)
            {
                H264_DVR_DEVICEINFO OutDev = new H264_DVR_DEVICEINFO();
                int nError = 0;

                int lLogin = XMSDK.H264_DVR_Login(devinfo.szIpaddress, (ushort)devinfo.nPort, devinfo.szUserName, devinfo.szPsw, out OutDev, out nError, SocketStyle.TCPSOCKET);
                if (lLogin <= 0)
                {
                    int nErr = XMSDK.H264_DVR_GetLastError();
                    if (nErr == (int)SDK_RET_CODE.H264_DVR_PASSWORD_NOT_VALID)
                    {
                        MessageBox.Show(("Password Error"));
                    }
                    else if (nErr == (int)SDK_RET_CODE.H264_DVR_LOGIN_USER_NOEXIST)
                    {
                        MessageBox.Show(("User Not Exist"));
                    }

                    return;
                }
                dictDiscontDev.Remove(devinfo.lLoginID);

                ClientDemo clientForm = new ClientDemo();

                foreach (Form form in Application.OpenForms)
                {
                    if (form.Name == "ClientDemo")
                    {
                        clientForm = (ClientDemo)form;
                        break;
                    }
                }
                DEV_INFO devAdd = new DEV_INFO();
                devAdd          = devinfo;
                devAdd.lLoginID = lLogin;


                foreach (TreeNode node in clientForm.devForm.DevTree.Nodes)
                {
                    if (node.Name == "Device")
                    {
                        DEV_INFO dev = (DEV_INFO)node.Tag;
                        if (dev.lLoginID == devinfo.lLoginID)
                        {
                            node.Text = devAdd.szDevName;
                            node.Tag  = devAdd;
                            node.Name = "Device";

                            foreach (TreeNode channelnode in node.Nodes)
                            {
                                CHANNEL_INFO chInfo = (CHANNEL_INFO)channelnode.Tag;
                                if (chInfo.nWndIndex > -1)
                                {
                                    clientForm.m_videoform[chInfo.nWndIndex].ConnectRealPlay(ref devAdd, chInfo.nChannelNo);
                                    Thread.Sleep(10);
                                }
                            }
                            break;
                        }
                    }
                }

                dictDevInfo.Add(lLogin, devAdd);
                XMSDK.H264_DVR_SetupAlarmChan(lLogin);
            }
            if (0 == dictDiscontDev.Count)
            {
                timerDisconnect.Enabled = false;
                timerDisconnect.Stop();
            }
        }
コード例 #2
0
        int DevLogin(ref DEV_INFO pdev)
        {
            if (pdev.bSerialID)                 //如果之前是DDNS获取ip;这里先获取动态ip
            {
                int         maxDeviceNum = 100; //最大支持设备数量100
                DDNS_INFO[] pDDNSInfo    = new DDNS_INFO[maxDeviceNum];
                SearchMode  searchmode;
                int         nReNum = 0; //实际获得的设备数量
                searchmode.nType        = (int)SearchModeType.DDNS_SERIAL;
                searchmode.szSerIP      = pdev.szSerIP;
                searchmode.nSerPort     = pdev.nSerPort;
                searchmode.szSerialInfo = pdev.szSerialInfo;
                bool bret = Convert.ToBoolean(XMSDK.H264_DVR_GetDDNSInfo(ref searchmode, out pDDNSInfo, maxDeviceNum, out nReNum));
                if (!bret)
                {
                    return(0);
                }
                pdev.szIpaddress = pDDNSInfo[0].IP;
                pdev.nPort       = pDDNSInfo[0].MediaPort;
            }

            H264_DVR_DEVICEINFO OutDev;
            int nError = 0;

            //设置尝试连接设备次数和等待时间
            XMSDK.H264_DVR_SetConnectTime(3000, 1);//设置尝试连接1次,等待时间3s

            int lLogin = XMSDK.H264_DVR_Login(pdev.szIpaddress, Convert.ToUInt16(pdev.nPort), pdev.szUserName,
                                              pdev.szPsw, out OutDev, out nError, SocketStyle.TCPSOCKET);

            if (lLogin <= 0)
            {
                int nErr = XMSDK.H264_DVR_GetLastError();
                if (nErr == (int)SDK_RET_CODE.H264_DVR_PASSWORD_NOT_VALID)
                {
                    MessageBox.Show("Error.PwdErr");
                }
                else
                {
                    MessageBox.Show("Error.NotFound");
                }
                return(lLogin);
            }
            XMSDK.H264_DVR_SetupAlarmChan(lLogin);
            return(lLogin);
        }
コード例 #3
0
ファイル: ClientDemo.cs プロジェクト: isliulin/07-CRAB310
        public int Connect(ref DEV_INFO pDev, int nChannel, int nWndIndex)
        {
            int nRet = 0;

            //if device did not login,login first
            if (pDev.lLoginID <= 0)
            {
                H264_DVR_DEVICEINFO OutDev;
                int nError = 0;
                //设置尝试连接设备次数和等待时间
                int lLogin = XMSDK.H264_DVR_Login(pDev.szIpaddress, (ushort)pDev.nPort, pDev.szUserName, pDev.szPsw, out OutDev, out nError, SocketStyle.TCPSOCKET);
                if (lLogin <= 0)
                {
                    int nErr = XMSDK.H264_DVR_GetLastError();
                    if (nErr == (int)SDK_RET_CODE.H264_DVR_PASSWORD_NOT_VALID)
                    {
                        MessageBox.Show(("Error.PwdErr"));
                    }
                    else
                    {
                        MessageBox.Show(("Error.NotFound"));
                    }

                    return(nRet);
                }

                pDev.lLoginID = lLogin;
                XMSDK.H264_DVR_SetupAlarmChan(lLogin);
            }

            int nWnd = m_nCurIndex;

            if (nWndIndex >= 0)
            {
                nWnd = nWndIndex;
            }

            if (nWnd >= m_nTotalWnd)
            {
                return(nRet);
            }

            return(m_videoform[nWnd].ConnectRealPlay(ref pDev, nChannel));
        }
コード例 #4
0
        public int ConnectRealPlay(ref DEV_INFO pDev, int nChannel)
        {
            if (m_iPlayhandle != -1)
            {
                if (0 != XMSDK.H264_DVR_StopRealPlay(m_iPlayhandle, (uint)this.Handle))
                {
                    //TRACE("H264_DVR_StopRealPlay fail m_iPlayhandle = %d", m_iPlayhandle);
                }
                if (m_bSound)
                {
                    OnCloseSound();
                }
            }

            H264_DVR_CLIENTINFO playstru = new H264_DVR_CLIENTINFO();

            playstru.nChannel = nChannel;
            playstru.nStream  = 0;
            playstru.nMode    = 0;
            playstru.hWnd     = this.Handle;
            m_iPlayhandle     = XMSDK.H264_DVR_RealPlay(pDev.lLoginID, ref playstru);
            if (m_iPlayhandle <= 0)
            {
                Int32         dwErr = XMSDK.H264_DVR_GetLastError();
                StringBuilder sTemp = new StringBuilder("");
                sTemp.AppendFormat("access {0} channel{1} fail, dwErr = {2}", pDev.szDevName, nChannel, dwErr);
                MessageBox.Show(sTemp.ToString());
            }
            else
            {
                XMSDK.H264_DVR_MakeKeyFrame(pDev.lLoginID, nChannel, 0);
            }
            m_lLogin   = pDev.lLoginID;
            m_iChannel = nChannel;
            return(m_iPlayhandle);
        }
コード例 #5
0
ファイル: PlayBackForm.cs プロジェクト: isliulin/07-CRAB310
        private void DownloadByTime()
        {
            if (m_DownLoadFileHandle > 0)
            {
                timerDownload.Stop();
                XMSDK.H264_DVR_StopGetFile(m_DownLoadFileHandle);
                m_DownLoadFileHandle         = 0;
                progressBarDownloadPos.Value = 0;

                btnDownload.Text = "Download";

                return;
            }

            string strSaveName = "";

            //strSaveName.Format("c:\\record");
            strSaveName = BrowseForFolder(this.Handle);

            if (strSaveName == "")       //未选择路径时退出
            {
                return;
            }

            H264_DVR_FINDINFO info = new H264_DVR_FINDINFO();

            info.nChannelN0         = comboChannel.SelectedIndex;    //channel No.
            info.nFileType          = comboRecordType.SelectedIndex; //file type
            info.startTime.dwYear   = beginDate.Value.Year;
            info.startTime.dwMonth  = beginDate.Value.Month;
            info.startTime.dwDay    = beginDate.Value.Day;
            info.startTime.dwHour   = beginTime.Value.Hour;
            info.startTime.dwMinute = beginTime.Value.Minute;
            info.startTime.dwSecond = beginTime.Value.Second;
            info.endTime.dwYear     = endDate.Value.Year;
            info.endTime.dwMonth    = endDate.Value.Month;
            info.endTime.dwDay      = endDate.Value.Day;
            info.endTime.dwHour     = endTime.Value.Hour;
            info.endTime.dwMinute   = endTime.Value.Minute;
            info.endTime.dwSecond   = endTime.Value.Second;
            int nRecordFileType = comboRecordType.SelectedIndex;

            info.nFileType = (nRecordFileType <= (int)PlayBackFileType.SDK_RECORD_MANUAL) ? nRecordFileType : ((int)PlayBackFileType.SDK_PIC_ALL + nRecordFileType - (int)PlayBackFileType.SDK_RECORD_MANUAL - 1);

            m_DownLoadFileHandle = XMSDK.H264_DVR_GetFileByTime(m_lLoginID, ref info, strSaveName, false, null, 0);
            if (m_DownLoadFileHandle > 0)
            {
                progressBarDownloadPos.Value = 0;

                btnDownload.Text = "Stop";

                //update the progress control
                timerDownload.Start();
            }
            else
            {
                string sTemp;
                sTemp = string.Format("dowload fail ERROR = {0}", XMSDK.H264_DVR_GetLastError());
                MessageBox.Show(sTemp);
            }
        }
コード例 #6
0
ファイル: PlayBackForm.cs プロジェクト: isliulin/07-CRAB310
        private void DownloadByName()
        {
            if (m_DownLoadFileHandle > 0)
            {
                timerDownload.Stop();
                XMSDK.H264_DVR_StopGetFile(m_DownLoadFileHandle);
                m_DownLoadFileHandle         = 0;
                progressBarDownloadPos.Value = 0;

                btnDownload.Text = "Download";

                return;
            }

            string csFileName;

            //inCount;
            //if ( nSelected < 0 )
            //{
            //    MessageBox.Show("SelectFile !");
            //    return;
            //}


            H264_DVR_FILE_DATA FileInfo = (H264_DVR_FILE_DATA)listFile.FocusedItem.Tag;


            string strSaveName;
            //strSaveName.Format("c:\\record\\record.h264");
            int nSelectedIndex = comboDev.SelectedIndex;

            if (nSelectedIndex < 0)
            {
                MessageBox.Show("SelectDevice !");
                return;
            }
            DEV_INFO DevTemp = (DEV_INFO)((ComboxItem)comboDev.SelectedItem).Value;

            string strInitDir;

            strInitDir = Application.StartupPath;
            if (strInitDir.EndsWith("\\"))
            {
                strInitDir += "Download";
            }
            else
            {
                strInitDir += "\\Download";
            }

            DirectoryInfo dir = new DirectoryInfo(strInitDir);

            //if ( dir.Attributes )
            {
                dir.Create();
            }

            string strFileTpye = "h264";
            string strFileName = FileInfo.sFileName;

            if (strFileName.EndsWith(".h264"))
            {
                strFileTpye = "h264";
            }
            else
            {
                strFileTpye = "jpg";
            }
            strFileName = string.Format("{0}_{1}_{2}{3}_{4}{5}{6}.{7}",
                                        DevTemp.szDevName, FileInfo.ch + 1,
                                        FileInfo.stBeginTime.year, FileInfo.stBeginTime.month,
                                        FileInfo.stBeginTime.day, FileInfo.stBeginTime.hour,
                                        FileInfo.stBeginTime.minute, FileInfo.stBeginTime.second, strFileTpye);

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.AddExtension     = true;
            dlg.CheckPathExists  = true;
            dlg.DefaultExt       = ".h264";
            dlg.Filter           = "All File(*.h264;*.jpg)|*.*||";
            dlg.InitialDirectory = strInitDir;          //默认路径
            dlg.ShowDialog();

            if (dlg.DereferenceLinks)
            {
                strSaveName = dlg.FileName;
                //m_lSaveHandle = H264_DVR_GetFileByName(m_lLoginID, pstrFileInfo,strSaveName.GetBuffer(0),SDKDownLoadPosCallback,(DWORD)this);
                m_DownLoadFileHandle = XMSDK.H264_DVR_GetFileByName(m_lLoginID, ref FileInfo, strSaveName, null, 0);
                if (m_DownLoadFileHandle >= 0)
                {
                    progressBarDownloadPos.Value = 0;
                    btnDownload.Text             = "Stop";
                    //update the progress control
                    //SetTimer(1,0,NULL);
                }
                else
                {
                    string sTemp = string.Format("dowload fail ERROR = {0}", XMSDK.H264_DVR_GetLastError());
                    MessageBox.Show(sTemp);
                }
            }
        }