Announcement

Collapse
No announcement yet.

tenScripting4, the extensions, and C#

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

    tenScripting4, the extensions, and C#

    I'm trying to use the global methods from a C# script and having no luck. From what I read, the ScriptingReferences settings in the settings.ini file only applies for VB scripts. Instead, for C# it sounds like the correct method is the first line in my script. This is the complete script:

    Code:
    //css_reference tenGlobalMethods.dll;
    
    using tenGlobalMethods;
    using HomeSeerAPI;
    using System.Text.RegularExpressions;
    using HomeSeer.PluginSdk.Devices;
    using System.Threading.Tasks;
    using System.Text;
    using System.Linq;
    using System.Collections.Generic;
    using System;
    
    public object Main(string parm)
    {
    CAPI.CAPIControl cc;
    CAPI.CAPIControlResponse cr;
    
    List<int> LightRefs = tenGlobalMethods.GetRefsByCategoryName(hs4, "Lights");
    
    foreach (int LightRef in LightRefs)
    {
    cc = hs.CAPIGetSingleControl(LightRef, true, "Off", false, false);
    cr = hs.CAPIControlHandler(cc);
    }
    
    hs.WriteLog("All Lighs Off", "Done");
    return 0;
    }
    I've tried it using the complete path to the DLL, and with and without the using statement, but all I get in the log is this:

    Code:
    Compiling script (3)AllLightsOff.cs: {interactive}(78,31): error CS0103: The name `tenGlobalMethods' does not exist in the current context {interactive}(78,48): error CS0023: The `.' operator cannot be applied to operand of type `' {interactive}(72,34): warning CS0219: The variable `cr' is assigned but its value is never used {interactive}(41,36): warning CS0414: The private field `Script.hs4' is assigned but its value is never used ->Check your scripting references in settings.ini, they are case sensitive.
    Any ideas?

    #2
    If you are running the current version of HS4, then the ScriptingReferences entry in settings.ini should also apply to C#. Not sure if //css_reference was fixed at the same time, but it has not worked in the recent past. I'll try experimenting with this and see if I can get it to work.
    tenholde

    Comment


      #3
      Thanks. I first tried adding it to the settings file like this:

      Code:
      ScriptingReferences=System.Text.RegularExpressions;System.Text.RegularExpressions.dll,tenGlobalMethods;tenGlobalMethods.dll
      but that resulted in this error in the log:

      Code:
      C# scripting, could not add assembly referenced from settings.ini (item is case sensitive): tenGlobalMethods
      I also get a similar error for the RegularExpressions reference.

      I'm running HS 4.2.13 and all the latest tenScripting bits. I'm interested to hear what you find.

      Comment


        #4
        OK, this works for me:

        Code:
        public void Main(object parm)
        {
        string Result;
        Result = ten.ToggleDeviceOnOff(hs, 174);
        }
        settings.ini entry:

        Code:
        ScriptingReferences=tenGlobalMethods;tenGlobalMethods.dll,System.Data.SQLite;bin\homeseer\System.Data.SQLite.dll
        tenholde

        Comment


          #5
          Originally posted by dlmorgan999 View Post
          Thanks. I first tried adding it to the settings file like this:

          Code:
          ScriptingReferences=System.Text.RegularExpressions;System.Text.RegularExpressions.dll,tenGlobalMethods;tenGlobalMethods.dll
          but that resulted in this error in the log:

          Code:
          C# scripting, could not add assembly referenced from settings.ini (item is case sensitive): tenGlobalMethods
          I also get a similar error for the RegularExpressions reference.

          I'm running HS 4.2.13 and all the latest tenScripting bits. I'm interested to hear what you find.
          tenGlobalMethods.dll on my system is in the root HS4 folder. Make sure you restart HS4 after making changes to settings.ini and moving the file to the root.

          You might find out that you must edit settings.ini while HS4 is not running, or sometimes it reverts back to status before you made the changes.
          tenholde

          Comment


            #6
            Yup. I'm running it as a service, so I stopped the service, copied the latest tenGlobalMethods.dll file to the HS4 root folder, edited the settings file, and started the service.

            This sounds like an HS4 issue and nothing to do with your code, but I figured I would ask if you've tried using the extensions with C# before. Also, unless the documentation is just a bit behind (always a distinct possibility), this page makes it sounds like you still only use settings.ini for VB scripts.

            Comment


              #7
              Also, once you get tenGlobalMethods reference working, you could simplify your script to something like:

              Code:
              List<int> LightRefs = tenGlobalMethods.GetRefsByCategoryName(hs4, "Lights");
              String s2 = DeviceOff(hs, LightRefs);
              You might have to clean up my C# syntax.

              The DeviceOn and DeviceOff tenGlobalMethods take either a single DevRef or a List of Devrefs.

              http://tenholder.net/tenWare2/Script...Reference.aspx
              tenholde

              Comment


                #8
                Yup. Definitely something I was planning to do. I just have to hope I can get the reference working.

                Comment


                  #9
                  Originally posted by dlmorgan999 View Post
                  This sounds like an HS4 issue and nothing to do with your code, but I figured I would ask if you've tried using the extensions with C# before. Also, unless the documentation is just a bit behind (always a distinct possibility), this page makes it sounds like you still only use settings.ini for VB scripts.
                  I've worked with Rich to update the C# support over the last several months, and the last few releases have implemented some of this. The documentation does not reflect these changes. You might check the release info for the last several releases: https://docs.homeseer.com/display/HSPI/HS4+Release+4.2.11.0
                  tenholde

                  Comment


                    #10
                    And actually, per your documentation, I could probably just do this:

                    Code:
                    DeviceOff(hs, GetRefsByCategoryName(hs, "Lights"))

                    Comment


                      #11
                      Would you mind try running HS4 NOT as a service and see if this makes a difference.
                      tenholde

                      Comment


                        #12
                        Originally posted by tenholde View Post

                        I've worked with Rich to update the C# support over the last several months, and the last few releases have implemented some of this. The documentation does not reflect these changes. You might check the release info for the last several releases: https://docs.homeseer.com/display/HSPI/HS4+Release+4.2.11.0
                        In that case, I think I'll post something else regarding the settings.ini error.

                        Comment


                          #13
                          Originally posted by dlmorgan999 View Post
                          And actually, per your documentation, I could probably just do this:

                          Code:
                          DeviceOff(hs, GetRefsByCategoryName(hs, "Lights"))
                          Exactly.
                          tenholde

                          Comment


                            #14
                            Originally posted by tenholde View Post
                            Would you mind try running HS4 NOT as a service and see if this makes a difference.
                            That seems like a reasonable idea. It's been a while since I looked at the docs. I guess I can just stop the service and then run it manually?

                            Comment


                              #15
                              Could you also try a ScriptingReference entry with just tenGlobalMethods defined.
                              tenholde

                              Comment

                              Working...
                              X