Beispiel #1
1
        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();
            }
        }
Beispiel #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);
        }
Beispiel #3
0
        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));
        }
        private void button_login_Click(object sender, EventArgs e)
        {
            H264_DVR_DEVICEINFO OutDev = new H264_DVR_DEVICEINFO();
            short         nError       = 0;
            StringBuilder strIP        = new StringBuilder(this.textBox_ip.Text.ToString().Trim());
            ushort        usPort       = Convert.ToUInt16(this.textBox_port.Text.ToString().Trim());
            StringBuilder strUserName  = new StringBuilder(this.textBox_username.Text.ToString());
            StringBuilder strPassword  = new StringBuilder(this.textBox_password.Text.ToString());

            lLoginID = XMSDK.H264_DVR_Login(strIP, usPort, strUserName, strPassword, out OutDev, out nError, SocketStyle.TCPSOCKET);
            if (lLoginID <= 0)
            {
                MessageBox.Show(@"login wrong");
            }
            else
            {
                MessageBox.Show(@"login ok");
            }
        }
Beispiel #5
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (textBoxDevName.Text.Trim() != "" &&
                textBoxIP.Text.Trim() != "" &&
                textBoxport.Text.Trim() != "" &&
                textBoxUsername.Text.Trim() != "")
            {
                H264_DVR_DEVICEINFO dvrdevInfo = new H264_DVR_DEVICEINFO();
                int      nError;
                int      nLoginID = XMSDK.H264_DVR_Login(textBoxIP.Text.Trim(), ushort.Parse(textBoxport.Text.Trim()), textBoxUsername.Text, textBoxPassword.Text, out dvrdevInfo, out nError, SocketStyle.TCPSOCKET);
                DEV_INFO devInfo  = new DEV_INFO();
                if (nLoginID > 0)
                {
                    ClientDemo clientForm = new ClientDemo();

                    foreach (Form form in  Application.OpenForms)
                    {
                        if (form.Name == "ClientDemo")
                        {
                            clientForm = (ClientDemo)form;
                            break;
                        }
                    }


                    TreeNode nodeDev = new TreeNode();
                    nodeDev.Text          = textBoxDevName.Text;
                    devInfo.szDevName     = textBoxDevName.Text;
                    devInfo.lLoginID      = nLoginID;
                    devInfo.nPort         = Int32.Parse(textBoxport.Text.Trim());
                    devInfo.szIpaddress   = textBoxIP.Text.Trim();
                    devInfo.szUserName    = textBoxUsername.Text;
                    devInfo.szPsw         = textBoxPassword.Text;
                    devInfo.NetDeviceInfo = dvrdevInfo;
                    //  nodeDev.Tag = nLoginID;
                    nodeDev.Tag  = devInfo;
                    nodeDev.Name = "Device";
                    for (int i = 0; i < devInfo.NetDeviceInfo.byChanNum + devInfo.NetDeviceInfo.iDigChannel; i++)
                    {
                        TreeNode nodeChannel = new TreeNode(string.Format("CAM{0}", i));
                        nodeChannel.Name = "Channel";
                        CHANNEL_INFO ChannelInfo = new CHANNEL_INFO();
                        ChannelInfo.nChannelNo = i;
                        ChannelInfo.nWndIndex  = -1;
                        nodeChannel.Tag        = ChannelInfo;
                        nodeDev.Nodes.Add(nodeChannel);
                    }

                    clientForm.devForm.DevTree.Nodes.Add(nodeDev);
                    ClientDemo.dictDevInfo.Add(devInfo.lLoginID, devInfo);
                }
                else
                {
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("Please input all data!");
            }
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (textBoxDevName.Text.Trim() != "" &&
                textBoxIP.Text.Trim() != "" &&
                textBoxport.Text.Trim() != "" &&
                textBoxUsername.Text.Trim() != "")
            {
                H264_DVR_DEVICEINFO dvrdevInfo = new H264_DVR_DEVICEINFO();
                int      nError;
                int      nLoginID = XMSDK.H264_DVR_Login(textBoxIP.Text.Trim(), ushort.Parse(textBoxport.Text.Trim()), textBoxUsername.Text, textBoxPassword.Text, out dvrdevInfo, out nError, SocketStyle.TCPSOCKET);
                DEV_INFO devInfo  = new DEV_INFO();
                if (nLoginID > 0)
                {
                    ClientDemo clientForm = new ClientDemo();

                    foreach (Form form in  Application.OpenForms)
                    {
                        if (form.Name == "ClientDemo")
                        {
                            clientForm = (ClientDemo)form;
                            break;
                        }
                    }


                    TreeNode nodeDev = new TreeNode();
                    nodeDev.Text          = textBoxDevName.Text;
                    devInfo.szDevName     = textBoxDevName.Text;
                    devInfo.lLoginID      = nLoginID;
                    devInfo.nPort         = Int32.Parse(textBoxport.Text.Trim());
                    devInfo.szIpaddress   = textBoxIP.Text.Trim();
                    devInfo.szUserName    = textBoxUsername.Text;
                    devInfo.szPsw         = textBoxPassword.Text;
                    devInfo.NetDeviceInfo = dvrdevInfo;
                    //  nodeDev.Tag = nLoginID;
                    nodeDev.Tag  = devInfo;
                    nodeDev.Name = "Device";
                    for (int i = 0; i < devInfo.NetDeviceInfo.byChanNum + devInfo.NetDeviceInfo.iDigChannel; i++)
                    {
                        TreeNode nodeChannel = new TreeNode(string.Format("CAM{0}", i));
                        nodeChannel.Name = "Channel";
                        CHANNEL_INFO ChannelInfo = new CHANNEL_INFO();
                        ChannelInfo.nChannelNo = i;
                        ChannelInfo.nWndIndex  = -1;
                        nodeChannel.Tag        = ChannelInfo;
                        nodeDev.Nodes.Add(nodeChannel);
                    }

                    clientForm.devForm.DevTree.Nodes.Add(nodeDev);
                    ClientDemo.dictDevInfo.Add(devInfo.lLoginID, devInfo);
                    this.Close();
                }
                else
                {
                    string strErr;
                    switch (nError)
                    {
                    case -11301:
                        strErr = string.Format("Passwd is Error");
                        break;

                    case -11300:
                        strErr = string.Format("The user has no permissions");
                        break;

                    case -11302:
                        strErr = string.Format("The user does not exist");
                        break;

                    case -11303:
                        strErr = string.Format("The user is locked");
                        break;

                    case -11304:
                        strErr = string.Format("The user is in the blacklist");
                        break;

                    case -11305:
                        strErr = string.Format("The user has landed");
                        break;

                    case -11307:
                        strErr = string.Format("There is no equipment");
                        break;

                    default:
                    {
                        strErr = string.Format("Login Error:{0}", nError);
                    }
                    break;
                    }
                    MessageBox.Show(strErr);
                }
            }
            else
            {
                MessageBox.Show("Please input all data!");
            }
        }