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

Discussion in 'Cameras, NVR / DVR's, hardware & more' started by Srinivas Cheruku, Aug 3, 2017.

Share This Page

  1. Srinivas Cheruku

    Srinivas Cheruku n3wb

    Joined:
    Aug 3, 2017
    Messages:
    4
    Likes Received:
    0
    Dear All,

    I am writing a Windows desktop application (x64 - C#) to embed DVR utilities by consuming Hikvision SDK for Windows.

    I downloaded the SDK (Filename: Device Network SDK V5.2.3.3 (for Windows 64-bit)) from -> Hikvision Europe

    I am able to Login, Play live Video, Audio.etc well, but not able to Use the Voice talk feature.

    Here is my code for triggering the two way Audio.

    try

    {
    int voiceHandle = NativeMethods.NET_DVR_StartVoiceCom_V30(userID, 1, false, new NativeMethods.VoiceDataCallBack(f_VoiceDataCallBack), IntPtr.Zero);
    if (voiceHandle == -1)
    {
    uint l = NativeMethods.NET_DVR_GetLastError();
    MessageBox.Show("Error code: " + l);
    }

    }
    catch (Exception ex) {
    }

    The application Crashes when I call NativeMethods.NET_DVR_StartVoiceCom_V30.

    Error: Unhandled exception at 0x00007FFE9D9CC695 (AudioIntercom.dll) in HikVisionWinforms.exe: 0xC0000005: Access violation reading location 0x000000006A5F4178.

    I had been struggling since days to fruitlessly figure out the reason for this. Looks like the Exception occurs in the code from API.

    Please help me!

    Thanks,
     
  2. curiousDev

    curiousDev n3wb

    Joined:
    Aug 16, 2017
    Messages:
    4
    Likes Received:
    0
    Hi,

    Any progress with this issue? I noticed you are able to play live video and just wondering how your code looks for this part, can you share it?
    Basically, I stuck on calling method NET_DVR_GetFileByTime which results with following error 17: Parameter error. Input or output parameter in the SDK API is NULL.
    Maybe you had similar difficulties?

    Best regards and thanks in advance.
     
  3. Srinivas Cheruku

    Srinivas Cheruku n3wb

    Joined:
    Aug 3, 2017
    Messages:
    4
    Likes Received:
    0
    Can you try using the C# Code that contains "P invoke" Calls, for consuming C/C++ functions from below link.
    HCNetSDK.cs in longchang | source code search engine
    I used the funtion NET_DVR_RealPlay_V30 (After NET_DVR_Init and NET_DVR_Login_V30), to do a Live Preview.
    Found helpful?
     
  4. curiousDev

    curiousDev n3wb

    Joined:
    Aug 16, 2017
    Messages:
    4
    Likes Received:
    0
    Hey,

    Not really helpful. I see you are using function which isn't having time struct as parameters. Let me explain by showing my code below.

    Extern function from C++
    [DllImport(@"D:\Projekty\HIK\Hikvision\EN-HCNetSDK(Windows32)V5.2.7.5_build20170217\lib\HCNetSDK.dll", EntryPoint = "NET_DVR_GetFileByTime")]
    public static extern int NET_DVR_GetFileByTime(long lUserID, long lChannel, ref LPNET_DVR_TIME lpStartTime, ref LPNET_DVR_TIME lpStopTime, [MarshalAs(UnmanagedType.LPStr)] string sSavedFileName);

    here is struct for time object:

    [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
    [Serializable]
    public struct LPNET_DVR_TIME
    {
    public uint dwYear;
    public uint dwMonth;
    public uint dwDay;
    public uint dwHour;
    public uint dwMinute;
    public uint dwSecond;
    }

    and finally call (of course before that I called NET_DVR_Init and NET_DVR_Login_V30):

    LPNET_DVR_TIME lpStartTime = new LPNET_DVR_TIME();
    lpStartTime.dwYear = 2017;
    lpStartTime.dwMonth = 7;
    lpStartTime.dwDay = 10;
    lpStartTime.dwHour = 10;
    lpStartTime.dwMinute = 10;
    lpStartTime.dwSecond = 1;

    LPNET_DVR_TIME lpStopTime = new LPNET_DVR_TIME();
    lpStopTime.dwYear = 2017;
    lpStopTime.dwMonth = 7;
    lpStopTime.dwDay = 10;
    lpStopTime.dwHour = 10;
    lpStopTime.dwMinute = 15;
    lpStopTime.dwSecond = 1;

    int channel = 33;
    int result = NET_DVR_GetFileByTime(0, channel, ref lpStartTime, ref lpStopTime, file);
    if (result < 0)
    {
    Console.WriteLine("GetFileByTime error: {1}", NET_DVR_GetLastError());
    //NET_DVR_Cleanup();
    }

    This code ending up with result mentioned by me before which is: GetFileByTime error: 17 (Parameter error. Input or output parameter in the SDK API is NULL).
    Tried many diffrent way of calling this function always ending up the same (or in most cases - dont remember others errors though).
    Also when I tired call functions which had similar input parameter (with time struct) result was the same - examples of other functions: NET_DVR_FindFile, NET_DVR_FindPDCInfo.


    Best regards
     
    Last edited: Sep 12, 2017
  5. Srinivas Cheruku

    Srinivas Cheruku n3wb

    Joined:
    Aug 3, 2017
    Messages:
    4
    Likes Received:
    0
    Looks like you are talking about Playback (Playing a past recording). I was talking about Live Preview.
    I haven't worked on Playback as such.
     
  6. Srinivas Cheruku

    Srinivas Cheruku n3wb

    Joined:
    Aug 3, 2017
    Messages:
    4
    Likes Received:
    0
    Let me know if I can be of any help further. I would like to know if you have ever worked on integrating Cp Plus or Dahua DVR?
     
  7. curiousDev

    curiousDev n3wb

    Joined:
    Aug 16, 2017
    Messages:
    4
    Likes Received:
    0
    That's true. I am interested in past records. Thought maybe I can find any helpful info in your issue.

    I havent been doing anything with Dahua... yet. I am working with Hikvision NVR device basically in this moment I am interested in getting storaged video on this recorder but so far no luck. Login in works fine, and all tracks leads to problem with this time struct not sure though.
     
  8. curiousDev

    curiousDev n3wb

    Joined:
    Aug 16, 2017
    Messages:
    4
    Likes Received:
    0
    Hello,

    Several days ago I have found a reason why it wasnt working just reminded myself about this topic here. Maybe it will help somebody.
    Problem was with type mismatch.


    [DllImport(@"D:\Projekty\HIK\Hikvision\EN-HCNetSDK(Windows32)V5.2.7.5_build20170217\lib\HCNetSDK.dll", EntryPoint = "NET_DVR_GetFileByTime")]
    public static extern int NET_DVR_GetFileByTime(long lUserID, long lChannel, ref LPNET_DVR_TIME lpStartTime, ref LPNET_DVR_TIME lpStopTime, [MarshalAs(UnmanagedType.LPStr)] string sSavedFileName);

    [DllImport(@"D:\Projekty\HIK\Hikvision\EN-HCNetSDK(Windows32)V5.2.7.5_build20170217\lib\HCNetSDK.dll", EntryPoint = "NET_DVR_GetFileByTime")]
    public static extern int NET_DVR_GetFileByTime(int lUserID, int lChannel, ref LPNET_DVR_TIME lpStartTime, ref LPNET_DVR_TIME lpStopTime, [MarshalAs(UnmanagedType.LPStr)] string sSavedFileName);

    Best regards
     
Tags: