aardio调用NetSDK.dll实现网络摄像头IP Camera的打开和预览

By admin at 2023-03-01 • 0人收藏 • 926人看过

前面说到用ocx实现了这款网络摄像头的打开和操作, 那是因为官方杭州熊迈不提供32位库了, 只有64位的库, 然后我安装官方的摄像头软件VSM lite发现它自己用的倒是32位的.....

于是, 我花了点时间将这个32位的dll研究了下, 网上找了不少之前32位的库的文档,

然后在aar中调用这个netsdk.dll,我用c#简单粗暴的封装了个NetSDKEx.dll类库, 里面只有简单的init和open函数, 可以更简单的使用了.( ̄▽ ̄)"


这种方式与前面ocx方式的优缺点比较:

优点: 不用申请管理员模式去regsvr32 注册ocx

缺点: 这个编译的是dotnet框架4.7.2, 需要你电脑里安装过.net框架


image.png

import win.ui;
/*DSG{{*/
mainForm = win.form(text="aardio工程";right=542;bottom=448)
mainForm.add(
custom={cls="custom";text="自定义控件";left=12;top=8;right=524;bottom=430;bgcolor=15780518;db=1;dl=1;dr=1;dt=1;z=1}
)
/*}}*/

import console
console.open()

import dotNet

//声明
var NetSDKExDLL = dotNet.load("res/NetSDKEx.dll");

var video = NetSDKExDLL.new("NetSDKEx.VideoCard");
var ret = video.Init();
if(ret){
	var ret2 = video.Open("192.168.1.165",34567,"admin","",mainForm.custom.hwnd);
	console.log(ret2)	
}

mainForm.show();
return win.loopMessage();

完整工程示例:

链接:https://pan.baidu.com/s/1wrPZU9H-4_BlGjfRUrTRUQ?pwd=qu19 

提取码:qu19


附上NetSDKEx的c#类库代码工程:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinNetSDK.Class;
using WinNetSDK.Struct;
using static WinNetSDK.Class.CppLibWrapper;
using SDK_HANDLE = System.Int32;

namespace NetSDKEx
{
    public class VideoCard
    {
        public bool Init()
        {
            SDK_HANDLE ret =  H264_DVR_Init(null, IntPtr.Zero);
            if (ret<=0)
            {
                return false;
            }
            return true;
        }

        public bool Open(string ip , ushort dk , string user , string mima ,IntPtr handle)
        {
            int data = 0;
            H264_DVR_DEVICEINFO info = new H264_DVR_DEVICEINFO();
            SDK_HANDLE lgid = H264_DVR_Login(ip, dk, user, mima, ref info, out data, 0);
            if (lgid>0)
            {
                H264_DVR_CLIENTINFO cliinfro = new H264_DVR_CLIENTINFO();
                cliinfro.hWnd = handle;
                SDK_HANDLE playID = H264_DVR_RealPlay(lgid, ref cliinfro);
                return true;
            }
            return false;
        }
    }
}

链接:https://pan.baidu.com/s/1dvFNcn1QRClpG_8uaB4hFw?pwd=1mw7 

提取码:1mw7


如果是c#直接调用NetSDK.dll库的话 , c#代码如下:

private void Form1_Load(object sender, EventArgs e)
{
            
    CppLibWrapper.H264_DVR_Init(null, IntPtr.Zero);
    H264_DVR_DEVICEINFO info = new H264_DVR_DEVICEINFO();

    int data = 0;
    var lgid =  H264_DVR_Login("192.168.1.165", 34567, "admin", "",ref info,out data,0);
    H264_DVR_CLIENTINFO cliinfro= new H264_DVR_CLIENTINFO();
    cliinfro.hWnd = this.pictureBox1.Handle;
    SDK_HANDLE playID = H264_DVR_RealPlay(lgid, ref cliinfro);
            
}

链接:https://pan.baidu.com/s/19Q3b52RDI2jHxS1qqMvsRg?pwd=6ptg 

提取码:6ptg



官方提供的64位XNetSDK.dll库和代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using User.XNetSDK;
using XSDK_HANDLE = System.Int32;

namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        XSDK_HANDLE hLoginID;
        XSDK_HANDLE _hPlayer;

        XSDK_HANDLE hLoginID2;
        XSDK_HANDLE _hPlayer2;

        private void Form1_Load(object sender, EventArgs e)
        {
            SXSDKInitParam InitParam = new SXSDKInitParam();
            XNetSDK.XSDK_Init(ref InitParam);

            SXSDKLoginParam LoginInfo = new SXSDKLoginParam();

            LoginInfo.sDevId = "192.168.1.165";    //IP addrss
            LoginInfo.sUserName = "admin";  //User name
            LoginInfo.sPassword = "";  //Password
            LoginInfo.nDevPort = 34567;  //Port
            LoginInfo.nCnnType = EDEV_CNN_TYPE.EDEV_CNN_TYPE_AUTO;
            hLoginID = XNetSDK.XSDK_DevLoginSyn(ref LoginInfo, 5000);
            if (hLoginID > 0)
            {
                Console.WriteLine("Login sucess");


                SXMediaRealPlayReq param = new SXMediaRealPlayReq();
                param.nChannel = 0;              // Channel (required)
                param.nStreamType = 0;                  // Stream type (required)
                param.nRequestType = (int)EXSDK_DATA_FORMATE.EXSDK_DATA_FORMATE_FRAME;  // Data type
                param.hShowWindows = this.pictureBox1.Handle;       // Window handle
                param.nDecodeType = (int)EXNetSDK_EDECODE_RESULT.DECODE_RESULT_NULL;    // Decoding result
                //var _playCallback = new XNetSDK.PXSDK_MessageCallBack(RealPlayMediaCallBack);
               // param.result.pMsgCallback = _playCallback;   // Result callback (required)

                _hPlayer = XNetSDK.XSDK_MediaRealPlay(hLoginID, ref param, 0, 0);
            }
            else
            {
                Console.WriteLine("Login failed");
            }

            SXSDKLoginParam LoginInfo2 = new SXSDKLoginParam();

            LoginInfo2.sDevId = "192.168.1.150";    //IP addrss
            LoginInfo2.sUserName = "admin";  //User name
            LoginInfo2.sPassword = "";  //Password
            LoginInfo2.nDevPort = 34567;  //Port
            LoginInfo2.nCnnType = EDEV_CNN_TYPE.EDEV_CNN_TYPE_AUTO;
            hLoginID2 = XNetSDK.XSDK_DevLoginSyn(ref LoginInfo2, 5000);
            if (hLoginID2 > 0)
            {
                Console.WriteLine("Login sucess2");


                SXMediaRealPlayReq param = new SXMediaRealPlayReq();
                param.nChannel = 0;              // Channel (required)
                param.nStreamType = 0;                  // Stream type (required)
                param.nRequestType = (int)EXSDK_DATA_FORMATE.EXSDK_DATA_FORMATE_FRAME;  // Data type
                param.hShowWindows = this.pictureBox2.Handle;       // Window handle
                param.nDecodeType = (int)EXNetSDK_EDECODE_RESULT.DECODE_RESULT_NULL;    // Decoding result
                                                                                        //var _playCallback = new XNetSDK.PXSDK_MessageCallBack(RealPlayMediaCallBack);
                                                                                        // param.result.pMsgCallback = _playCallback;   // Result callback (required)

                _hPlayer = XNetSDK.XSDK_MediaRealPlay(hLoginID2, ref param, 0, 0);
            }
            else
            {
                Console.WriteLine("Login failed2");
            }

        }

    }
}

链接:https://pan.baidu.com/s/1870AgzJQuNfRqm4JmwHEaw?pwd=0ec7 

提取码:0ec7



用c#将64位的这个netsdk给重新封装了下, 只保留一个函数

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Configuration;
using System.Text;
using System.Threading.Tasks;
using User.XNetSDK;
using XSDK_HANDLE = System.Int32;
namespace NetSDKEx
{
    public class Video
    {
        public bool Open( string iPaddrss , IntPtr PicHandle)
        {
            SXSDKInitParam InitParam = new SXSDKInitParam();
            XNetSDK.XSDK_Init(ref InitParam);

            SXSDKLoginParam LoginInfo = new SXSDKLoginParam();
            LoginInfo.sDevId = iPaddrss;    //IP addrss
            LoginInfo.sUserName = "admin";  //User name
            LoginInfo.sPassword = "";  //Password
            LoginInfo.nDevPort = 34567;  //Port
            LoginInfo.nCnnType = EDEV_CNN_TYPE.EDEV_CNN_TYPE_AUTO;
            XSDK_HANDLE hLoginID = XNetSDK.XSDK_DevLoginSyn(ref LoginInfo, 500);
            if (hLoginID > 0)
            {
                SXMediaRealPlayReq param = new SXMediaRealPlayReq();
                param.nChannel = 0;              // Channel (required)
                param.nStreamType = 0;                  // Stream type (required)
                param.nRequestType = (int)EXSDK_DATA_FORMATE.EXSDK_DATA_FORMATE_FRAME;  // Data type
                param.hShowWindows = PicHandle;       // Window handle
                param.nDecodeType = (int)EXNetSDK_EDECODE_RESULT.DECODE_RESULT_NULL;
                XNetSDK.XSDK_MediaRealPlay(hLoginID, ref param, 0, 0);
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}

用的时候, 直接open

var video1 =  new NetSDKEx.Video();
var ret = video1.Open(端口1, pictureBox1.Handle);
if (!ret){
   MessageBox.Show("摄像头1打开失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

Xnet64.zip


1 个回复 | 最后更新于 2023-10-10
2023-10-10   #1

抽空研究了下官方提供的64位XNetSDK.dll库 , 比较坑的是官方没提供参数配置的示例, 而参数配置需要用 json 字符串上传和下载的方式 , c#我不是很熟, 有些奇怪的json格式不知道怎么去转换到c#对象, 所以我就用最原始的方式直接修改json字符串的方式来修改默认参数.

比如: 我需要摄像头 Flip 和Mirror 上下镜像和左右镜像 ,

bool flip = false;
        bool mirror = false;


        private void testtttToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!flip)
            {
               
                IntPtr szOutBuffer = Marshal.AllocHGlobal(40960);
                int nInOutSize = 40960;
                XNetSDK.XSDK_DevGetChnConfigSyn(_hLoginID, 0, "Camera.Param", szOutBuffer, ref nInOutSize, 4000, 1042);
                Console.WriteLine(nInOutSize);
                string result = Marshal.PtrToStringAnsi(szOutBuffer);
                Console.WriteLine(result);

                result = result.Replace(" \"PictureMirror\" : \"0x00000000\",", " \"PictureMirror\" : \"0x00000001\",");
                Console.WriteLine(result);

                XNetSDK.XSDK_DevSetChnConfigSyn(_hLoginID, 0, "Camera.Param", Encoding.Default.GetBytes(result), nInOutSize, szOutBuffer, ref nInOutSize, 4000, 1040);


            }
            else
            {
                IntPtr szOutBuffer = Marshal.AllocHGlobal(40960);
                int nInOutSize = 40960;
                XNetSDK.XSDK_DevGetChnConfigSyn(_hLoginID, 0, "Camera.Param", szOutBuffer, ref nInOutSize, 4000, 1042);
                Console.WriteLine(nInOutSize);
                string result = Marshal.PtrToStringAnsi(szOutBuffer);
                Console.WriteLine(result);

                result = result.Replace(" \"PictureMirror\" : \"0x00000001\",", " \"PictureMirror\" : \"0x00000000\",");
                Console.WriteLine(result);

                XNetSDK.XSDK_DevSetChnConfigSyn(_hLoginID, 0, "Camera.Param", Encoding.Default.GetBytes(result), nInOutSize, szOutBuffer, ref nInOutSize, 4000, 1040);

            }

            flip = !flip;

        }

        
        private void flipToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!mirror)
            {

                IntPtr szOutBuffer = Marshal.AllocHGlobal(40960);
                int nInOutSize = 40960;
                XNetSDK.XSDK_DevGetChnConfigSyn(_hLoginID, 0, "Camera.Param", szOutBuffer, ref nInOutSize, 4000, 1042);
                Console.WriteLine(nInOutSize);
                string result = Marshal.PtrToStringAnsi(szOutBuffer);
                Console.WriteLine(result);

                result = result.Replace(" \"PictureFlip\" : \"0x00000000\",", " \"PictureFlip\" : \"0x00000001\",");
                Console.WriteLine(result);

                XNetSDK.XSDK_DevSetChnConfigSyn(_hLoginID, 0, "Camera.Param", Encoding.Default.GetBytes(result), nInOutSize, szOutBuffer, ref nInOutSize, 4000, 1040);


            }
            else
            {
                IntPtr szOutBuffer = Marshal.AllocHGlobal(40960);
                int nInOutSize = 40960;
                XNetSDK.XSDK_DevGetChnConfigSyn(_hLoginID, 0, "Camera.Param", szOutBuffer, ref nInOutSize, 4000, 1042);
                Console.WriteLine(nInOutSize);
                string result = Marshal.PtrToStringAnsi(szOutBuffer);
                Console.WriteLine(result);

                result = result.Replace(" \"PictureFlip\" : \"0x00000001\",", " \"PictureFlip\" : \"0x00000000\",");
                Console.WriteLine(result);

                XNetSDK.XSDK_DevSetChnConfigSyn(_hLoginID, 0, "Camera.Param", Encoding.Default.GetBytes(result), nInOutSize, szOutBuffer, ref nInOutSize, 4000, 1040);

            }

            mirror = !mirror;

        }

上面就是简单的把1变0 , 0变1 .....

先暂时这样用吧

登录后方可回帖

登 录
信息栏
 私人小站

本站域名

ChengXu.XYZ

投诉联系:  popdes@126.com



快速上位机开发学习,本站主要记录了学习过程中遇到的问题和解决办法及上位机代码分享

这里主要专注于学习交流和经验分享.
纯私人站,当笔记本用的,学到哪写到哪.
如果侵权,联系 Popdes@126.com

友情链接
Aardio官方
Aardio资源网


才仁机械


网站地图SiteMap

Loading...