Announcement

Collapse
No announcement yet.

Calling hs.PluginFunction for Z-Wave Configuration_Set

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

    Calling hs.PluginFunction for Z-Wave Configuration_Set

    I am calling hs.PluginFunction in a C# script in order to set a Z-Wave parameter value as follows:

    hs.PluginFunction("Z-Wave", "", "Configuration_Set", new object[] { parms[0], nodeNumber, parameterNumber, (byte)1, (int)Byte.Parse(parms[3]) });

    This works just fine, but I don't know how to process the result. The type of the result is HSPI_ZWave.HSPI+ConfigResult, and if I display it using hs.WriteLog, it displays as "Success," but no matter what type I try to cast this to, I get a runtime casting error (i.e., "Specified cast is not valid."). What can I cast this to in order to validate that "Success" was returned?

    #2
    It looks like it just returns "Success" string, that's it

    Comment


      #3
      Is the return value an enum?

      Comment


        #4
        Looking at the source code it is enum

        Code:
        public enum ConfigResult : byte
        {
            Unknown,
            Success,
            Queued,
            Failed
        }
        
        public ConfigResult Configuration_Set(string HomeID, byte NodeID, byte Param, byte Size, int Value);
        And probably you can verify the result using
        Code:
        public int Configuration_Get(string HomeID, byte NodeID, byte Param)

        Comment


          #5
          Thank you, alexbk66! Thank you very much! I was able to cast the return of hs.PluginFunction to the enum as you suggested:

          ConfigResult result = (ConfigResult)hs.PluginFunction("Z-Wave", "", "Configuration_Set", new object[] { parms[0], nodeNumber, parameterNumber, parameterSize, int.Parse(parms[4]) });

          hs.WriteLog("CSHARP", "hs.PluginFunction result: " + result);

          if(result == ConfigResult.Success)
          {
          hs.WriteLog("Error", "hs.PluginFunction result: SUCCESS!");
          }

          This works perfectly! So now I must ask, when you say "Looking at the source code it is enum," where did you find this source code? That would have saved me a lot of time and trouble!

          Comment


            #6
            David, if you have any experience using Visual Studio, then you should definitely check out the tenScripting way of writing HomeSeer scripts. It is a bit funky to learn, but once you do, it is a far easier way to write HS4 scripts as you can use the Vs debugger and you can also (as in this case) easily view the data type of any variable and when it’s an enum, easily see what the enum values are.

            see:

            http://tenholder.net/tenWare2/tenScripting/default.aspx

            Comment


              #7
              Originally posted by david.i.tanzer@gmail.com View Post
              Thank you, alexbk66! Thank you very much! I was able to cast the return of hs.PluginFunction to the enum as you suggested:

              This works perfectly! So now I must ask, when you say "Looking at the source code it is enum," where did you find this source code? That would have saved me a lot of time and trouble!
              I had to decompile the ZWave plugin when working on my AKHeatmiserNeo - because for a few months I couldn't get an answer from HST how to properly create thermostat device, and ZWave plugin code shows all different device types for thermostats.

              Regarding scripting, I really don't like it, I prefer creating proper plugins.

              Just wondering, what do you do in your scripts?

              Comment


                #8
                Originally posted by alexbk66 View Post
                Just wondering, what do you do in your scripts?
                I don't do a lot--in this case, I'm retrieving the sound setting for a Dome Siren and changing it, but only if necessary. Usually I do things when HomeSeer's Event capabilities can't do what I need (or make it unseemly awkward).

                Thanks again for your help!


                Comment

                Working...
                X