Announcement

Collapse
No announcement yet.

HikVision camera plugin for motion alerts - C# example

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    HikVision camera plugin for motion alerts - C# example

    I generated a HS3 plugin to pull the motion detection alerts from HikVision cameras. The C# source is posted to GitHub, https://github.com/sgieseking/HSPI_HikAlarmCheck.

    This is based on the example from aXis, http://board.homeseer.com/showthread.php?t=178122. The sample HSPI class has been changed to provide virtual functions so that you only need to override the functions that you need for your plugin. For a simple plugin, this is really only a few.

    Like aXis, I found getting started with a C# plugin from the sample VB and the available C# templates was a bit difficult.

    #2
    Is this windows only?

    Comment


      #3
      There is really nothing that is specific to Windows but when compiling on Ubuntu 14.04 with mono, I'm running into a few issues. I will see if I can resolve these.

      Comment


        #4
        I checked in a change for compatibility with Ubuntu 14.04 and Mono 3.2.8. The changes are related to how it specifies access to certain classes.

        Comment


          #5
          Any chance you could help me out in terms of a starting point on how to get this working...?

          Comment


            #6
            Could you be more specific:
            Github? Compilation? Setup inside the plugin? Configuration of HikVision Camera?

            Comment


              #7
              compilation please.

              Comment


                #8
                You may want to use monodevelop as the IDE to manage the compilation. The current project is really setup for Visual Studio 2015 so you probably need to delete this and start over with a new project in monodevelop.

                Add new empty project.
                Add files to the project.
                Edit References.
                * In the tab .Net Assembly, browse to the HomeSeer install directory, select HomeSeerApi.dll, HSCF.dll, and Scheduler.dll. Press the Add button near the bottom of the tab.
                * In the tab All, select the assemblies: System, System.Web, System.Xml, and System.Net.
                You can select a debug or release compilation on the toolbar, then Build.
                Compiled exe with be under bin/Release or bin/Debug.

                If you are on the computer with HomeSeer, then just start the program. If on a different computer, then add a command line parameter server=IpAddress. You can also place the exe in the HomeSeer directory, restart HS3, and it should be in the list of installed plugins.

                Comment


                  #9
                  Thank you for the sample AND the template. Trying to read the vb.net sample was becoming... annoying.

                  VB is a very inelegant language andalso is like reading a long run-on sentence andalso feels clunky andalso isnot even consistent with upper/lower case.

                  (In all fairness, MS's perversion of C++ (C#) isn't all that great itself, but at least it has some format.)

                  Comment


                    #10
                    I'm glad that you have found it useful. I mostly program in C++ and Python but since HomeSeer requires .net plugins, I preferred C# to VB. I hope that your plugin development goes well.

                    Comment


                      #11
                      I am noticing one oddity with any plugin I create with the template: The plugin .exe never exits.

                      (Compiled with VS2015, running HS3 under Win10)

                      For example, I might "disconnect" the plugin from within HS, which causes the IOShutdown() to run (as expected) and then the while() loop in Program.Main() sees that the plugin should exit, and breaks the while() loop.

                      I see that Program.Main() exits (as expected) and that the main thread ends, but the process sticks around and doesn't exit.

                      (If I do the same actions with the HS supplied HSPI_Sample, the process does end properly)

                      Any idea what might be going on? Do others have the same issue when using this template?

                      Thanks
                      Gary

                      Comment


                        #12
                        I'm still looking into this, but I think that it needs the following call at the end of main:
                        System.Environment.Exit(0);

                        This will exit a console application with an indication of no error.

                        In the VB sample, you will see the statement 'End' as the last statement executed in Main() which is equivalent to this call.

                        Comment


                          #13
                          Originally posted by sgieseking View Post
                          I'm still looking into this, but I think that it needs the following call at the end of main:
                          System.Environment.Exit(0);

                          This will exit a console application with an indication of no error.

                          In the VB sample, you will see the statement 'End' as the last statement executed in Main() which is equivalent to this call.
                          Well, that does work. It's the same as calling exit() in a normal C/C++ program.

                          However, I really hate doing that to terminate a .net process. It short circuits any destructors, etc. (However, you ARE correct that it's the same thing that the VB.net sample is doing with "End" in the middle of the code.) If I comment out the vb.net sample's "End", I see the VB.Net sample doing the same thing as the C# template.

                          From what I can tell, it leaves several worker threads running, along with threads in:

                          Microsoft.Win32.SystemEvents.WindowThreadProc
                          HSCD.Threading.QueueProcessorThread<>.DoProcess
                          System.Net.Sockets.Socket.Receive

                          This is the same for both vb.net and c#. I wonder if there's a good way to signal those threads to terminate properly instead of the equivalent of TerminateThread(). (Actually, those appear to be created by HS's code, so it'd be up to them to fix their problem.)

                          Well, thank you for the work-around. It's ugly, but it appears to be the HomeSeer condoned method for working around their sloppiness.

                          Take care
                          Gary

                          Comment


                            #14
                            Installation question

                            Newbie Question....

                            I looked at the GITHUB site and read through the readme file.

                            The instructions say to put the executable in the installation directory but, I do not know which file or files are required.

                            Please advise.

                            Comment


                              #15
                              Sorry about the delay in responding but I didn't get an email that there was a post to the thread.

                              When you compile the code, you will get a new directory that is something like bin\x86\Release or bin\x86\Debug. The file that you need is HSPI_HikAlarmCheck.exe. Copy this file into the HomeSeer install directory. On my computer it is at "c:\Program Files (x86)\HomeSeeer HS3". You will see the file HS3.exe in the install directory. For testing purposes, you can also run the program directly from Visual Studio.
                              Last edited by sgieseking; March 6, 2017, 02:15 PM.

                              Comment

                              Working...
                              X