Ejemplo n.º 1
0
        //进行NVS查询
        private void btnNVSQuery_Click(object sender, EventArgs e)
        {
            //NVS ID 为空时,不能查询
            if (textNVSID.Text.Trim() == "")
            {
                MessageBox.Show("NVS ID 不能为空 ! ");
                return;
            }

            //创建结构体
            REG_NVS stRegNVS = new REG_NVS();

            //进行Byte数组赋值
            Array.Copy(Encoding.ASCII.GetBytes(textNVSID.Text), stRegNVS.m_stNvs.m_btFactoryID, textNVSID.Text.Length);

            //清空DataGridView内容
            dgvNVS.Rows.Clear();

            int    iRet = -1;
            IntPtr pNvs = IntPtr.Zero;

            try
            {
                //申请结构体REG_NVS所需的内存
                pNvs = Marshal.AllocHGlobal(Marshal.SizeOf(stRegNVS));

                //将stRegNVS存入刚申请的内存
                Marshal.StructureToPtr(stRegNVS, pNvs, true);

                //查询NVS设备信息
                iRet = NVSSDK.NSLook_Query(ServerID, IntPtr.Zero, pNvs, NVSSDK.TYPE_NVS);

                //从内存中读出stRegNVS的值
                stRegNVS = (REG_NVS)Marshal.PtrToStructure(pNvs, typeof(REG_NVS));
            }
            catch (Exception ex)
            {
                //将异常输出到Output窗口
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                //释放内存
                Marshal.FreeHGlobal(pNvs);
            }

            //查询失败,退出
            if (iRet != 0)
            {
                MessageBox.Show("NSLook_Query NVS Error ! " + iRet);
                return;
            }

            //为DatagGridView添加新行
            dgvNVS.Rows.Add
            (
                new object[]
            {
                Bytes2Str(stRegNVS.m_stNvs.m_btNvsIP),
                Bytes2Str(stRegNVS.m_stNvs.m_btNvsName),
                stRegNVS.m_stNvs.m_iNvsType,
                Bytes2Str(stRegNVS.m_stNvs.m_btFactoryID)
            }
            );
        }
Ejemplo n.º 2
0
        //进行DNS查询操作
        private void btnDNSQuery_Click(object sender, EventArgs e)
        {
            //创建REG_DNS结构体
            REG_DNS stRegDNS = new REG_DNS();

            //以ID方式进行查询
            if (rdoDNSID.Checked)
            {
                if (textDNSID.Text.Trim() == "")
                {
                    MessageBox.Show("DNS ID 不能为空 ! ");
                    return;
                }

                //Byte数组进行赋值
                Array.Copy(Encoding.ASCII.GetBytes(textDNSID.Text), stRegDNS.m_stDNSInfo.m_stNvs.m_btFactoryID, textDNSID.Text.Length);
            }
            else
            {
                //以域名方式进行查询
                if (textDNSDomainName.Text.Trim() == "")
                {
                    MessageBox.Show("DNS DomainName 不能为空 ! ");
                    return;
                }

                //Byte数组进行赋值
                Array.Copy(Encoding.ASCII.GetBytes(textDNSDomainName.Text), stRegDNS.m_stDNSInfo.m_stNvs.m_btNvsName, textDNSDomainName.Text.Length);
            }
            Array.Copy(Encoding.ASCII.GetBytes(UserName), stRegDNS.m_stDNSInfo.m_btUserName, UserName.Length);
            Array.Copy(Encoding.ASCII.GetBytes(Password), stRegDNS.m_stDNSInfo.m_btPwd, Password.Length);

            //清空DataGridView
            dgvDNS.Rows.Clear();

            int    iRet = -1;
            IntPtr pDns = IntPtr.Zero;

            try
            {
                //申请结构体REG_DNS所需的内存
                pDns = Marshal.AllocHGlobal(Marshal.SizeOf(stRegDNS));

                //将stRegDNS存入刚申请的内存
                Marshal.StructureToPtr(stRegDNS, pDns, true);

                //查询DNS设备信息
                iRet = NVSSDK.NSLook_Query(ServerID, pDns, IntPtr.Zero, NVSSDK.TYPE_DNS);

                //从内存中读出stRegDNS的值
                stRegDNS = (REG_DNS)Marshal.PtrToStructure(pDns, typeof(REG_DNS));
            }
            catch (Exception ex)
            {
                //将异常输出到Output窗口
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                //释放内存
                Marshal.FreeHGlobal(pDns);
            }

            //操作失败
            if (iRet != 0)
            {
                MessageBox.Show("NSLook_Query DNS Error ! " + iRet);
                return;
            }

            //为DataGridView添加新行
            dgvDNS.Rows.Add
            (
                new object[]
            {
                Bytes2Str(stRegDNS.m_stDNSInfo.m_stNvs.m_btNvsName),
                Bytes2Str(stRegDNS.m_stDNSInfo.m_stNvs.m_btFactoryID),
                Bytes2Str(stRegDNS.m_stDNSInfo.m_stNvs.m_btNvsIP),
                Bytes2Str(stRegDNS.m_stDNSInfo.m_stReserve.m_btReserved1),
                stRegDNS.m_stDNSInfo.m_iPort,
                stRegDNS.m_stDNSInfo.m_stNvs.m_iNvsType,
                stRegDNS.m_stDNSInfo.m_iChannel,
                "",
                "",
                DateTime.Now
            }
            );
        }