Announcement

Collapse
No announcement yet.

tenScripting Now Available for HS3

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

    Here's a translation of one of your vb.net classes.
    SpeakAndLogMultipleParms.cs:

    public object Main(object[] parms)
    {
    // Simple Sample Using Multiple Parms
    // Specify two parms, separated by a vertical bar character ("|")
    // The 1st parm is the text spoken
    // The 2nd parm is the text written to the HS log
    string parmString;
    string[] parmArray;
    parmString = System.Convert.ToString(parms[0]);
    parmArray = parmString.Split('|'); // split parameter string into parm array
    hs.Speak(parmArray[0]); // speak 1st parm
    hs.WriteLog("Info", "This is 2nd parm: " + parmArray[1]); // log 2nd parm
    return 0;
    }

    // EDIT: sorry, but don't know why indentation doesn't properly show up after pasting to this forum :-)

    Comment


      I tried translating your ScriptWithEmbeddedClassDefinition.
      ScriptWithEmbeddedClassDefinition.cs:
      ///////////////////////////
      public class TestClass
      {
      private string _LogMessage;

      private HomeSeerAPI.IHSApplication _hs;
      public TestClass(string LogMessage, HomeSeerAPI.IHSApplication hs)
      {
      _LogMessage = LogMessage;
      _hs = hs;
      }
      public void Logit()
      {
      _hs.WriteLog("Logit", _LogMessage);
      }
      }

      public object Main(object[] parms)
      {
      hs.WriteLog("Info", "Running in Main.");
      Testclass o;
      o = new TestClass("Hello World", hs);
      o.Logit();
      return 0;
      }
      ////////////////////////

      Unfortunately, I get the error:

      "Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\ScriptWithEmbeddedClassDefinition.cs: {interactive}(49,4): error CS0246: The type or namespace name `Testclass' could not be found."

      If I comment out the 2nd, 3rd, and 4th lines of Main (so it doesn't use Testclass), then it compiles fine and runs. It's not clear to me what sort of environment HomeSeer is using when calling C# scripts. Maybe I need to preface TestClass with a namespace name (used by HomeSeer)? Still need to try to debug this more. I found another thread with someone else having a similar problem when trying to declare a class within a script.

      Comment


        Originally posted by randman View Post
        Unfortunately, I get the error:

        "Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\ScriptWithEmbeddedClassDefinition.cs: {interactive}(49,4): error CS0246: The type or namespace name `Testclass' could not be found."
        Haven't tried your code so there could be other errors, but you are trying to declare an instance of Testclass instead of TestClass. It's case sensitive.
        HS Pro 3.0 | Linux Ubuntu 16.04 x64 virtualized under Proxmox (KVM)
        Hardware: Z-NET - W800 Serial - Digi PortServer TS/8 and TS/16 serial to Ethernet - Insteon PLM - RFXCOM - X10 Wireless
        Plugins: HSTouch iOS and Android, RFXCOM, BlueIris, BLLock, BLDSC, BLRF, Insteon PLM (MNSandler), Device History, Ecobee, BLRing, Kodi, UltraWeatherWU3
        Second home: Zee S2 with Z-Wave, CT101 Z-Wave Thermostat, Aeotec Z-Wave microswitches, HSM200 occupancy sensor, Ecolink Z-Wave door sensors, STI Driveway Monitor interfaced to Zee S2 GPIO pins.

        Comment


          Originally posted by reidfo View Post
          Haven't tried your code so there could be other errors, but you are trying to declare an instance of Testclass instead of TestClass. It's case sensitive.
          Duh!! Thanks, reidfo! Yeah, I know it's case sensitive, but when I was using vim for editing, I somehow overlooked the typo. That's where Visual Studio & tenScripting would have helped :-). Changing Testclass to TestClass resolved the issue.

          Comment


            Originally posted by tenholde View Post
            C# is on my list to do. It will require a lot of rework of the text scanning code, but is certainly doable.

            Would you be interested in working with me on this? I'm not a C# coder, but not concerned about that. I'd need 3 or 4 sample scripts to test with, something that would be easy to translate to my HS3 installation.

            tenholde
            Hi tenfolde. Attached are 3 sample scripts. Basically, they are C# versions of your vb.net ScriptWithEmbeddedClassDefinition, SpeakAndLogMultipleParms, and ToggleDeviceSample classes.

            Note that scripts should have ".cs" as their extension. However, I had to append ".txt" to the filenames when uploading, since the HomeSeer forum won't let me upload files that end with ".cs".
            Attached Files

            Comment


              Originally posted by randman View Post
              Duh!! Thanks, reidfo! Yeah, I know it's case sensitive, but when I was using vim for editing, I somehow overlooked the typo. That's where Visual Studio & tenScripting would have helped :-). Changing Testclass to TestClass resolved the issue.
              Can I tell you about the time I spent three days searching for a bug in my code that just wouldn't compile? This was in the days before compilers actually told you what the error was, or even what line of code it was on... I finally printed my code and took it to the computer room operator who knew nothing about coding (it was COBOL back then) and said, "There's an error here somewhere, and I think it's in these 4 or 5 lines." He looked at it for about 5 seconds and said, "Oh, well that's a zero where I think you meant to type an O." I was embarrassed and grateful at the same time.

              P.S. I can't believe I just dated myself that badly.
              HS Pro 3.0 | Linux Ubuntu 16.04 x64 virtualized under Proxmox (KVM)
              Hardware: Z-NET - W800 Serial - Digi PortServer TS/8 and TS/16 serial to Ethernet - Insteon PLM - RFXCOM - X10 Wireless
              Plugins: HSTouch iOS and Android, RFXCOM, BlueIris, BLLock, BLDSC, BLRF, Insteon PLM (MNSandler), Device History, Ecobee, BLRing, Kodi, UltraWeatherWU3
              Second home: Zee S2 with Z-Wave, CT101 Z-Wave Thermostat, Aeotec Z-Wave microswitches, HSM200 occupancy sensor, Ecolink Z-Wave door sensors, STI Driveway Monitor interfaced to Zee S2 GPIO pins.

              Comment


                Comment


                  Have you added the script vb files to the project? What does the log say?
                  tenholde

                  Comment


                    Originally posted by tenholde View Post
                    Have you added the script vb files to the project? What does the log say?
                    I think so. Is there a step I missed. I thought I followed the video setup to a T.

                    Here is an example from the log:

                    05 Connected, waiting to be initialized...
                    06 Homeseer Connection Successful
                    07 tenScripting Initialization Complete
                    12 Running EtherRain.Main
                    13 >>> Exception
                    14 >>> Method 'tenScripting3.tenScripting.Main' not found.
                    16 EtherRain.Main Finished

                    Not only that. Homeseer crashes just about everytime after I stop running the debugger.

                    Comment


                      Please see private message I just sent to you.

                      tenholde
                      tenholde

                      Comment


                        Originally posted by tenholde View Post
                        Please see private message I just sent to you.



                        tenholde

                        Comment


                          Try your email
                          tenholde

                          Comment


                            Originally posted by tenholde View Post
                            Try your email

                            Comment


                              Out of town, back tonight. Will check then
                              tenholde

                              Comment


                                Originally posted by tenholde View Post
                                Out of town, back tonight. Will check then


                                Thanks

                                Comment

                                Working...
                                X