Creating C# application using Hikvision SDK for DS-7116HVI-SL

curiousDev

Young grasshopper
Joined
Aug 16, 2017
Messages
38
Reaction score
2
Hello Adam

You are probably right about it (that it's not a full union anymore).
Can you provide more details where you are going to use it since the sample wasnt so accurate also there was 'using static' which could cause problem when you tried to make instance in main?
If that is not a problem please paste the part from real app where are you using it.

Best regards
curious
 
Joined
Jan 18, 2019
Messages
5
Reaction score
0
Location
UK
Can you provide more details where you are going to use it
Well, I don't have a good answer to your question.

The app (Winforms, VS2015 ) used to be one project and I made a change to the app:
Split the app into two assemblies.
Dynamically load the assembly that contains those structs.
Use reflection to instantiate classes of the loaded assembly.​
In the process of getting types from the loaded assembly, (19) exceptions ware thrown, all of them about the same problem.

Apparently, there are a bunch of structs that aren't defined properly.

For now, I've commented out those structs. The code still compiles and runs successfully (those structs are not referenced by the code).

I haven't mapped all the APIs that use those structs so I don't know what functionality is lost.

The reason I want to fix this and not sweep it under the rug is that I don't know what features I'll need to support in the future.

Also, this file CHCNetSDK.cs is commonly used (I'm hoping), so I would expect other people to encounter this issue. But searching the web yield no results...

Best regards.

Adam.
 

curiousDev

Young grasshopper
Joined
Aug 16, 2017
Messages
38
Reaction score
2
Hey Adam

I did some test and for now I can say I found a solution for it. Tried few things most of them wasnt working at all (ending up with the same error which you came with here).
I noticed that problem is with simple type like uint, int and so on when we try to nest arrays or struct in the same c# 'union'

Code:
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 1, ArraySubType = UnmanagedType.U4)]
public uint[] dwLocalChannel;
In my humble opinion this is more like workaround or even hack but it works.

For testing purposes I used this piece of code:

Code:
NET_DVR_SLAVE_CHANNEL_UNION dvrSlaveChannelUnion = new NET_DVR_SLAVE_CHANNEL_UNION();
uint test = 360789;
byte[] intBytes = BitConverter.GetBytes(test);
byte[] result = intBytes;
dvrSlaveChannelUnion.byRes = result;
dvrSlaveChannelUnion2.struRemoteChannel.byAddress = result;
dvrSlaveChannelUnion2.struRemoteChannel.dwChannel = 123;
uint testConv = dvrSlaveChannelUnion2.dwLocalChannel[0];
//uint testConv = dvrSlaveChannelUnion2.dwLocalChannel[1]; this one will contain 0 (since result is only 4 bytes length)
Best regards
curiousDev
 

pavel63

n3wb
Joined
Feb 5, 2019
Messages
1
Reaction score
0
Location
italy
hello,
i have to decode frames inside the g_RealDataCallBack_V30 to a c# bitmap object converting from pBuffer.
any suggestion?
 

koo9

n3wb
Joined
Feb 26, 2019
Messages
1
Reaction score
0
Location
Canada
Hi mr. Srinivas.
i have problem when preview camera 16 ch in one page on C# cause have Bandwidth so much.
where can i adjust it from program c# ( "public bool StartPlay(Panel PanelName, int PanelNo, int Index" or another place)
and close green box on video preview.
Please help me.
C# SDK from Hikvision.
did you connect directly to the camera or the DVR? I am having trouble displaying the live view but login is fine.
 

NoobNub

n3wb
Joined
Apr 24, 2019
Messages
4
Reaction score
0
Location
Ph
Hi I am so very noob to this. How can I include my sdk? particularly the hikvision sdk?
 
Joined
Jan 18, 2019
Messages
5
Reaction score
0
Location
UK
Hi I am so very noob to this. How can I include my sdk? particularly the hikvision sdk?
I don't know what do you mean by "my SDK", so I explain how I use the SDK.
First I use the SDK to operate an NVR so I'm using the Device Network SDK (for Windows 64-bit).
download the SDK from Hikvision official site download pageSDK - Download - Hikvision
Then I copy the files from the lib directory to my running folder (where my app is run from, usually the bin\debug folder)
make sure to also copy the subfolder HCNetSDKCom, there are important files in it.
Now you can use the SDK by calling functions in the files. see the help at the file "Device Network SDK Programming Manual.chm".
My app is written in C#, so I use the file CHCNetSDK.cs which you can find in one of the demo apps of the SDK C# apps.
this file is very helpful because It defines the functions and structures of the SDK for easy usability.
Also, look in the help and the demo apps for code examples that you can easily cut and paste into your app.
 

NoobNub

n3wb
Joined
Apr 24, 2019
Messages
4
Reaction score
0
Location
Ph
I don't know what do you mean by "my SDK", so I explain how I use the SDK.
First I use the SDK to operate an NVR so I'm using the Device Network SDK (for Windows 64-bit).
download the SDK from Hikvision official site download pageSDK - Download - Hikvision
Then I copy the files from the lib directory to my running folder (where my app is run from, usually the bin\debug folder)
make sure to also copy the subfolder HCNetSDKCom, there are important files in it.
Now you can use the SDK by calling functions in the files. see the help at the file "Device Network SDK Programming Manual.chm".
My app is written in C#, so I use the file CHCNetSDK.cs which you can find in one of the demo apps of the SDK C# apps.
this file is very helpful because It defines the functions and structures of the SDK for easy usability.
Also, look in the help and the demo apps for code examples that you can easily cut and paste into your app.

i hope you don't mind but I always ended up in to error error.png




even though I already added all the files in lib folder here in latest SDK of Hikvision to bin folder of my Project.

copy.png

can you help me what should be the problem in here??
 
Joined
Jan 18, 2019
Messages
5
Reaction score
0
Location
UK
i hope you don't mind but I always ended up in to error View attachment 41983




even though I already added all the files in lib folder here in latest SDK of Hikvision to bin folder of my Project.

View attachment 41984

can you help me what should be the problem in here??
It seems that the file is not located where it should be.
when I run the demo app of the SDK my "running folder" also known as "execution folder" is:

"C:\\Users\\adamg.P-CIM\\Desktop\\VideoAnalyse-master\\NVRCsharpDemo\\bin"

You can see that if you call the static property System.Environment.CurrentDirectory

In the CHCNetSDK.cs file, the external method are declared and the path to the dll is defined:
[DllImport(@"..\bin\HCNetSDK.dll")]
this is a relative path. so you can use the method of GetFullPath to retrive the full path:
Path.GetFullPath(@"..\bin")
in my case the method return :
"C:\\Users\\adamg.P-CIM\\Desktop\\VideoAnalyse-master\\NVRCsharpDemo\\bin"

So if I look in C:\Users\adamg.P-CIM\Desktop\VideoAnalyse-master\NVRCsharpDemo\bin
I can see the files are in there. note that also the directory HCNetSDKCom is there
upload_2019-4-30_14-48-48.png
 

paulkovacs

n3wb
Joined
Oct 7, 2019
Messages
1
Reaction score
0
Location
Romania
Hello. This is my first project with HIKVision NET cameras. Whenever I try to use NET_DVR_GetDeviceConfig it returns 23. I have no idea why. Do you have any suggestions ?

PS: I don't even know if this is the right path to follow. I only need two things :
1 - to change the resolution and the encoding quality.
2 - to detect motion

Many thanks for your help.
 
Joined
Dec 16, 2019
Messages
1
Reaction score
0
Location
Malaysia
hello,
i have to decode frames inside the g_RealDataCallBack_V30 to a c# bitmap object converting from pBuffer.
any suggestion?
Hey guys,

I need help to decode pBuffer too, anyone has idea how to do it? But i need to convert it to JPEG instead.

Thank you
 

eltsov_da

n3wb
Joined
May 18, 2020
Messages
1
Reaction score
0
Location
Russia
Hi guys. I am novice in a hikvison sdk. Please tell me, how you create c# wrappers?
By hands based on CHCNetSDK.cs files in examples or may be exist some Swig interface file or some other technology?
 

NoFate

Getting the hang of it
Joined
Oct 24, 2020
Messages
480
Reaction score
63
Location
Belgium
yeah, gonna try this also, can this SDK also be used to make scripts? for linux/windows so without GUI?
i have downloaded Visual studio community edition, but seems hard to make those scripts? i also need some kind of MFC application?
so i started a new C++ project, attached the HCNet.h header file , but get all kind of errors when compiling/building

whats the correct procedure to start with this?
 
Joined
Oct 7, 2022
Messages
1
Reaction score
0
Location
India
It seems that the file is not located where it should be.
when I run the demo app of the SDK my "running folder" also known as "execution folder" is:

"C:\\Users\\adamg.P-CIM\\Desktop\\VideoAnalyse-master\\NVRCsharpDemo\\bin"

You can see that if you call the static property System.Environment.CurrentDirectory

In the CHCNetSDK.cs file, the external method are declared and the path to the dll is defined:
[DllImport(@"..\bin\HCNetSDK.dll")]
this is a relative path. so you can use the method of GetFullPath to retrive the full path:
Path.GetFullPath(@"..\bin")
in my case the method return :
"C:\\Users\\adamg.P-CIM\\Desktop\\VideoAnalyse-master\\NVRCsharpDemo\\bin"

So if I look in C:\Users\adamg.P-CIM\Desktop\VideoAnalyse-master\NVRCsharpDemo\bin
I can see the files are in there. note that also the directory HCNetSDKCom is there
View attachment 41992
Below is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace hikdemo
{
public partial class Preview : System.Windows.Forms.Form
{
private bool m_bInitSDK = false;

CHCNetSDK.REALDATACALLBACK RealData = null;
public CHCNetSDK.NET_DVR_PTZPOS m_struPtzCfg;

/private System.ComponentModel.Container components = null;

public Preview()
{
InitializeComponent();

m_bInitSDK = CHCNetSDK.NET_DVR_Init();
if (m_bInitSDK == false)
{
MessageBox.Show("NET_DVR_Init error!");
return;
}
else
{
/±£´æSDKÈÕÖ¾ To save the SDK log
CHCNetSDK.NET_DVR_SetLogToFile(3, "C:\\SdkLog\\", true);
}
}
}

when i'm running it i'm getting this error:

1665148884430.png

I'm new to this hikvision camera intregation and your reply help me a lot.

Well i'm trying to build a Video wall where i have to Run around 17 Hikvision camera and 6 UNV camera, i used the VLC plugins but the video is blur not satifactory and i'm not able to control it so i'm trying to imporove it by using OEM SDK. any help will be a great.

Regards,
Prashant
 
Joined
Aug 13, 2024
Messages
3
Reaction score
0
Location
Chandigarh
This post has been very helpful with my development. I have just downloaded the latest SDK and have noticed there is a new Login function "
NET_DVR_Login_V40".

I am trying to use it but unfortunately I keep getting error 17, Parameter invalid.

I have spent a long time and I cannot see the error of my way maybe someone can check my wrapper and ensure that it is correct and if they can use the new SDK function correctly. I have a feeling it may be in my wrapper struct declaration.

Thanks in advance.

[DllImport("HCNetSDK.dll")]
/**
* LONG NET_DVR_Login_V40( LPNET_DVR_USER_LOGIN_INFO pLoginInfo,
* LPNET_DVR_DEVICEINFO_V40 lpDeviceInfo);
*/
public static extern int NET_DVR_Login_V40(LPNET_DVR_USER_LOGIN_INFO pLoginInfo,
out LPNET_DVR_DEVICEINFO_V40 lpDeviceInfo);

/**
* typedef struct
{
char sDeviceAddress[NET_DVR_DEV_ADDRESS_MAX_LEN];
BYTE byUseTransport;
WORD wPort;
char sUserName[NET_DVR_LOGIN_USERNAME_MAX_LEN];
char sPassword[NET_DVR_LOGIN_PASSWD_MAX_LEN];
fLoginResultCallBack cbLoginResult;
void *pUser;
BOOL bUseAsynLogin;
BYTE byProxyType;
BYTE byUseUTCTime;
BYTE byRes2[2];
LONG iProxyID;
BYTE byRes3[120];
}NET_DVR_USER_LOGIN_INFO,*LPNET_DVR_USER_LOGIN_INFO;

*/
public struct LPNET_DVR_USER_LOGIN_INFO
{
public string sDeviceAddress;
public byte byRes1;
public ushort wPort;
public string sUserName;
public string sPassword;
public fLoginResultCallBack cbLoginResult;
public IntPtr pUser;
public bool bUseAsynLogin;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
public byte[] byRes2;
}

/**
* typedef void(CALLBACK *fLoginResultCallBack)(
LONG lUserID,
DWORD dwResult,
LPNET_DVR_DEVICEINFO_V30 lpDeviceInfo,
void *pUser
);
*/
public delegate void fLoginResultCallBack(int lUserID, uint dwResult,
NET_DVR_DEVICEINFO_V30 lpDeviceInfo, IntPtr pUser);

/*struct{
NET_DVR_DEVICEINFO_V30 struDeviceV30;
BYTE bySupportLock;
BYTE byRetryLoginTime;
BYTE byPasswordLevel;
BYTE byRes1;
DWORD dwSurplusLockTime;
BYTE byCharEncodeType;
BYTE byRes2[255];
}NET_DVR_DEVICEINFO_V30,*LPNET_DVR_DEVICEINFO_V30;
*/
public struct LPNET_DVR_DEVICEINFO_V40
{
public NET_DVR_DEVICEINFO_V30 struDeviceV30;
public byte bySupportLock;
public byte byRetryLoginTime;
public byte byPasswordLevel;
public byte byRes1;
public uint dwSurplusLockTime;
public byte byCharEncodeType;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 255)]
public byte[] byRes2;

}
can u provide me the dll
 
Joined
Aug 13, 2024
Messages
3
Reaction score
0
Location
Chandigarh
Hey Vilius,

I have found few errors in ur code. Changes marked with red bolded font. Let me know if it worked and if not I will paste my code snippets.


NET_DVR_RealPlay_V40 import (class SDKMethods):
[DllImport("HCNetSDK.dll")]
public static extern int NET_DVR_RealPlay_V40(int lUserID, ref Structs.LPNET_DVR_PREVIEWINFO lpPreviewInfo, Structs.REALDATACALLBACK fRealDataCallBack_V30, IntPtr pUser);

here my structures (class Structs):
public delegate void REALDATACALLBACK(int lPlayHandle, uint dwDataType, byte[] pBuffer, uint dwBufSize, IntPtr pUser);

public struct LPNET_DVR_PREVIEWINFO
{
public int lChannel; / Channel no.
public uint dwStreamType; / Stream type 0-main stream,1-sub stream,2-third stream,3-forth stream,4-fifth stream,5-sixth stream,7-seventh stream,8-eighth stream,9-ninth stream,10-tenth stream
public uint dwLinkMode; / Protocol type: 0-TCP, 1-UDP, 2-Muticast, 3-RTP,4-RTP/RTSP, 5-RSTP/HTTP
public IntPtr hPlayWnd; / Play window's handle; set NULL to disable preview
public uint bBlocked; /If data stream requesting process is blocked or not: 0-no, 1-yes
/if true, the SDK Connect failure return until 5s timeout , not suitable for polling to preview.
public uint bPassbackRecord; /0- not enable ,1 enable
public byte byPreviewMode; / Preview mode 0-normal preview,2-delay preview
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = Defines.STREAM_ID_LEN, ArraySubType = UnmanagedType.I1)]
public byte[] byStreamID;/Stream ID
public byte byProtoType; /0-private,1-RTSP
public byte byRes1;
public byte byVideoCodingType;
public uint dwDisplayBufNum; /soft player display buffer size(number of frames), range:1-50, default:1
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 216, ArraySubType = UnmanagedType.I1)]
public byte[] byRes;
}

and there is my calling function:
Structs.LPNET_DVR_PREVIEWINFO PrevInfo = new Structs.LPNET_DVR_PREVIEWINFO();
PrevInfo.hPlayWnd = this.host1.Handle;
PrevInfo.lChannel = 33; /check your digital channels for DVR, number 1 which you assigned is probably analog one. For example my digital channels starts with 33
PrevInfo.dwStreamType = 0;
PrevInfo.dwLinkMode = 1;
PrevInfo.bBlocked = 0;
PrevInfo.byPreviewMode = 0;



int player = SDKMethods.NET_DVR_RealPlay_V40(UserID, ref PrevInfo, null, IntPtr.Zero);
Console.WriteLine(player);


Best regards
can you provide me this [DllImport("HCNetSDK.dll")]
 
Top