Announcement

Collapse
No announcement yet.

Can someone explain how to convert a plugin to support Multiple Instances

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

    #16
    Dirk,
    I'm still at this. I had a lengthy exchange with Rich to get clarification on SupportsMultipleInstancesSingleEXE. i will try to summarize our convo later for others

    I had to do a lot of refactoring on my code to make this little miracle occur.

    I just wanted to check a few assumptions based on SupportsMultipleInstancesSingleEXE returns True
    1. Main only gets called once when the plugin initially loads? that is, it doesn't get called again when a second instance is started
    2. all the objects related to an instance must be contained in the HSPI class? So there is no data bleeding or corruption between instances
    Mark

    HS3 Pro 4.2.19.5
    Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
    Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
    Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

    Comment


      #17
      Originally posted by mnsandler View Post
      1. Main only gets called once when the plugin initially loads? that is, it doesn't get called again when a second instance is started
      TRUE

      Originally posted by mnsandler View Post
      2. all the objects related to an instance must be contained in the HSPI class? So there is no data bleeding or corruption between instances
      TRUE

      On a side note, because all the instances run in the same space (executable), you can pass pointers between the HSPI instances back and forth ..... just in case you need that. I use it because one instance is my "Main" class (initialize, shutdown, system wide behavior etc.) and all other instances are "player specific".




      Comment


        #18
        Dirk,
        I actually have multiple instances running. thanks for helping me get to this point. so i'm now looking at triggers and Actions.

        I see there is an Instance property in the TrigInfo argument for the TriggerBuildUI method

        question: how do i tell HS3 to initiate a definition of a trigger for one instance over other? do i need an Instance selection UI object

        right now when i initiate a trigger definition, hs seems to be referencing an secondary instance, not the Main on the initial call
        Mark

        HS3 Pro 4.2.19.5
        Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
        Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
        Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

        Comment


          #19
          Dirk, i figured out that HS lists triggers and conditions available in the instance; i just needed to add the Instance name to the list.

          How do you identify the Instance when listing triggers, conditions, events, and even hs devices?

          I was considering appending [Instance] to most things, but i already put the instance name in the dv.Address as a prefix.

          thoughts?
          Mark

          HS3 Pro 4.2.19.5
          Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
          Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
          Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

          Comment


            #20
            Originally posted by mnsandler View Post
            Dirk, i figured out that HS lists triggers and conditions available in the instance; i just needed to add the Instance name to the list.

            How do you identify the Instance when listing triggers, conditions, events, and even hs devices?

            I was considering appending [Instance] to most things, but i already put the instance name in the dv.Address as a prefix.

            thoughts?
            Hi Mark, when I build triggers, conditions, actions etc. if for a specific player (ie instance), the user would have to select the right player in the GUI drop downs that the PI created and when the PI builds its "TrigerInfo", it will add a bunch of tags, one of them being the unique name for a player, which I can then associate at any point in time with the instance that is associated with that player. Remember when I wrote about a "main" instance, it is this main instance that deals with triggers, actions, conditions etc. AND keep track of which player is associated with with instance and acts as the "traffic cop" for said functions.

            Hope this helps and sorry for the slow response, I overlooked your posting.

            Dirk

            Comment


              #21
              Originally posted by mnsandler View Post
              Dirk,
              I'm still at this. I had a lengthy exchange with Rich to get clarification on SupportsMultipleInstancesSingleEXE. i will try to summarize our convo later for others

              I had to do a lot of refactoring on my code to make this little miracle occur.

              I just wanted to check a few assumptions based on SupportsMultipleInstancesSingleEXE returns True
              1. Main only gets called once when the plugin initially loads? that is, it doesn't get called again when a second instance is started
              2. all the objects related to an instance must be contained in the HSPI class? So there is no data bleeding or corruption between instances
              Mark,

              I'm now going down this path as well. Can you share what you learned about MultipleInstances?

              Comment


                #22
                The biggest issue I had to resolve was my object model. I had to refactor a lot of my code to make most of my objects a child object of the HSPI object. Any object that is specific to a instance must be created relative to the hspi object so you have access to the correct instancename property value.

                Every hs device you create must have the instancename property set.

                My UI was based on the old genpage, putpage methods. I was able to get this to work with multiple instances. if you are doing the same; i can post some code snippets. But if you are using the newer prefered UI methods, i think those methods already support multiple instances.

                Your existing instance should have the instancename=""; the second instance must have a unique name.

                Your UI needs to account for the instancename that is running

                I used the following settings
                SupportsMultipleInstances=True and SupportsMultipleInstancesSingleEXE=True

                with these settings you have to build the UI to add an Instance (see sample plugin-the code works). The benefit is all instances run under the same exe which makes it easier to debug and manage. Debugging separate running exe isn't easy apparently.

                If you have other questions, just post them here and I will attempt to answer


                Some comments from Rich:

                When you enable that setting HS has the ability to create multiple instances of your plugin with one exe. The key is the instance name which has to be different for each instance. You create a web config page where a user adds an instance. The AddInstance function is called from the web page when the instance needs to be created. A new instance then appears on the plugins config page. HS then treats this as a separate plugin and calls the plugin api based on the instance. You keep track of the instance name in each instance with the global "instance" variable. So in your plugin you need to know which instance is being accessed using this variable.
                If its a multiinstancesingleexe, you have to create the UI page that creates a new instance. If it supports multiinstancemultipleexe then HS will create a new instance from the plugin page.
                There are 2 multiple instance properties, if supportsmultipleinstances is true and supportsmultipleinstancessingleexe is false, then HS will launch a new EXE and pass the new instance name to your main. This instance name is created by HS from the plugins page when the user clicks on the + button.

                Debugging a multiple instance single EXE is easy in VS as there is only one instance of the EXE running and you can just look at the instance name to see which instance you are in. Multiple EXE plugins is a bit more difficult and I am not sure I have debugged one of those but I think you can just attach the debugger to the instance you want to debug.

                The only real difference in operation is that the instance name is passed around so HS and you know which instance is being called and controlled.
                You can use the form from the sample to allow your users to create a new instance. You will see in Main where the AddInstance is called and the instance name is set in your plugin:

                PlugAPI.instance = InstanceName

                Now a new instance will be shown on the plugins page. When the user enables that instance your InitIO is called. In InitIO you can check the instance property to see which instance is being enabled. When any plugin API function is called you check the global instance property to see which instance it is and use that with INI file data to populate web pages, settings, etc. based on the instance. This way everything is kept separate but all your code remains the same for all instances.
                Mark

                HS3 Pro 4.2.19.5
                Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
                Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
                Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

                Comment

                Working...
                X