Announcement

Collapse
No announcement yet.

C# SCripting -- At the end of my rope

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

  • #16
    This script works on a RPi:

    PHP Code:
    using System.csharp;

    public 
    void Main(object[] parm) {
        
    string controlfunction Convert.ToString(parm[0]);

        
    hs.WriteLog("SpeakerLight""THIS IS A TEST");

    HS3Pro Running on a Raspberry Pi3
    64 Z-Wave Nodes, 168 Events, 280 Devices
    UPB modules via OMNI plugin/panel
    Plugins: Z-Wave, BLRF, OMNI, HSTouch, weatherXML, EasyTrigger
    HSTouch Clients: 3 Android, 1 Joggler

    Comment


    • #17
      Added Using System.csharp;

      This was the response I got:

      Compiling script /usr/local/HomeSeer/scripts/SpeakerLight_Functions.cs: {interactive}(1,15): error CS0234: The type or namespace name `csharp' does not exist in the namespace `System'. Are you missing an assembly reference? {interactive}(1,15): error CS0234: The type or namespace name `csharp' does not exist in the namespace `System'. Are you missing an assembly reference? {interactive}(32,34): error CS0433: The imported type `System.Convert' is defined multiple times Internal(1,1): warning CS1685: The predefined type `System.Object' is defined multiple times. Using definition from `mscorlib.dll' Internal(1,1): warning CS1685: The predefined type `System.ValueType' is defined multiple times. Using definition from `mscorlib.dll' Internal(1,1): warning CS1685: The predefined type `System.Attribute' is defined multiple times. Using definition from `mscorlib.dll' Internal(1,1): warning CS1685: The predefined type `System.Int32' is defined multiple times. Using definition from `mscorlib.dll' Internal(1,1): warning CS1685: The predefined type `System.UInt32' is defined multiple times. Using definition from `mscorlib.dll' Internal(1,1): warning CS1685: The predefined type `System.Int64' is..... etc

      Comment


      • #18
        Can you post your full script?
        Also, what does your ScriptingReferences setting looks like. Mine is set like:
        ScriptingReferences=System.Data.DataSetExtensions;System.Dat a.DataSetExtensions.dll,System.Data.SQLite;bin/System.Data.SQLite.dll
        HS3Pro Running on a Raspberry Pi3
        64 Z-Wave Nodes, 168 Events, 280 Devices
        UPB modules via OMNI plugin/panel
        Plugins: Z-Wave, BLRF, OMNI, HSTouch, weatherXML, EasyTrigger
        HSTouch Clients: 3 Android, 1 Joggler

        Comment


        • #19
          This is the full script
          It has 3 methods that are called explicitly from different events

          Code:
          using System.csharp;
          
          public const int ALARM_TIME = 79;
          public const int WARNING_TIME = 81;
          public const int ALARM_STATUS = 77;
          
          /* =======================================================================================================================
           * START THE TIMER
           * ======================================================================================================================= */
          public void StartTimer(object[] parm) {
              string controlfunction = Convert.ToString(parm[0]);
              //DateTime new_alarm_time = Convert.ToDateTime(hs.DeviceString(ALARM_TIME));
              //    if (new_alarm_time < DateTime.Now) {new_alarm_time = new_alarm_time.AddDays(1);}
          
              //int offset = Int32.Parse(hs.DeviceString(WARNING_TIME).Substring(0,2));
          
              //DateTime new_warning_time = new_alarm_time.AddMinutes(-offset);
              //DateTime new_alarm_time_pester = new_alarm_time.AddMinutes(-2);
          
              //hs.EventSetTimeTrigger(hs.GetEventRefByName("Timed_Warning_Light"), new_warning_time);
              //hs.EnableEvent("Timed_Warning_Light");
              //hs.WriteLog("Speaker Light", " Warn light scheduled for: <font color=blue>" + new_warning_time + "</font>");
          
              //hs.EventSetTimeTrigger(hs.GetEventRefByName("Timed_FinalWarning_Light"), new_alarm_time_pester);
              //hs.EnableEvent("Timed_FinalWarning_Light");
              //hs.WriteLog("Speaker Light", " Final Warn light scheduled for: <font color=blue>" + new_alarm_time_pester + "</font>");
          
              //hs.EventSetTimeTrigger(hs.GetEventRefByName("Timed_Final_Light"), new_alarm_time);
              //hs.EnableEvent("Timed_Final_Light");
              //hs.WriteLog("Speaker Light", " Final Light scheduled for: <font color=blue>" + new_alarm_time + "</font>");
          
              //hs.SaveEventsDevices();
          }
          
          /* =======================================================================================================================
           * END TIMER AND CLEAR EVENTS
           * ======================================================================================================================= */
          public void EndTimer(object[] parm) {
              string controlfunction = Convert.ToString(parm[0]);
              //hs.DisableEvent("Timed_Warning_Light");
              //hs.DisableEvent("Timed_FinalWarning_Light");
              //hs.DisableEvent("Timed_Final_Light");
          
              //hs.SaveEventsDevices();
              //hs.WriteLog("Speaker Light", " Schedule Light Events <b>Disabled</b>");
          }
          
          /* =======================================================================================================================
           * SET Alarm Warning (HOUR, MINUTE, AM/PM)
           * ======================================================================================================================= */
          public void AdjustWarning(object[] parm) {
              string controlfunction = Convert.ToString(parm[0]);
              //if (controlfunction == "-" || controlfunction == "+") {        
              //    string start_time = hs.DeviceString(WARNING_TIME);
          
              //    int minutes = Int32.Parse(start_time.Substring(0,2));
              
              //    minutes = (controlfunction == "+"? (minutes + 5) : (minutes - 5));
                  
              //    if (minutes < 5) {
              //        minutes = 5;
              //    }
              //    else if (minutes > 20) {
              //        minutes = 20;
              //    }
                  
              //    string minutesstr = minutes.ToString() + " Minutes";        
          
              //    hs.SetDeviceString(WARNING_TIME, minutesstr, true);
              //    hs.WriteLog("Speaker Light", " Warning changed to "+ minutesstr);
          
              //}
          }
          
          /* =======================================================================================================================
           * SET Alarm Time (HOUR, MINUTE, AM/PM)
           * ======================================================================================================================= */
          public void AdjustTime(object[] parm) {
              string controlfunction = Convert.ToString(parm[0]);
              //char[] controlfunctions = controlfunction.ToCharArray();
              //if (controlfunctions.Length == 2) {
              //    if ((controlfunctions[0].Equals('-') || controlfunctions[0].Equals('+')) && (controlfunctions[1].Equals('m') || controlfunctions[1].Equals('h'))) {
              //        DateTime new_alarm_time = Convert.ToDateTime(hs.DeviceString(ALARM_TIME));
          
              //        hs.WriteLog("Speaker Light", "Original end service time is " + new_alarm_time.ToString("h:mm tt"));
                      
              //        if (controlfunctions[1].Equals('h')) {
              //            new_alarm_time = new_alarm_time.AddHours((controlfunctions[0].Equals('+'))? 1 : -1);
              //        }
              //        else {
              //            new_alarm_time = new_alarm_time.AddMinutes((controlfunctions[0].Equals('+'))? 5 : -5);
              //        }
                  
              //        hs.WriteLog("Speaker Light", "New end service time is " + new_alarm_time.ToString("h:mm tt"));
                  
              //        hs.SetDeviceString(ALARM_TIME, new_alarm_time.ToString("h:mm tt"), true);
              //        hs.WriteLog("Speaker Light", " Completed");
              //   }
          
              //}
              hs.WriteLog("SpeakerLight", " THIS IS A TEST");
          }
          ScriptingReferences were unset
          According to http://www.homeseer.com/support/homeseer/HS3/HS3Help/ ScriptingReferences is for vb.net only

          I added your ScriptingReference configuration and ran the event, the system crashed.

          Comment


          • #20
            I added a Main sub and the script worked - it just called the Main sub.

            I then called your AdjustTime sub and my system crashed. Hard. Probably just like yours.

            So, I'm sorry to say this just confirmed what you guys were seeing. You are not able to call a sub/function within a csharp script.
            HS3Pro Running on a Raspberry Pi3
            64 Z-Wave Nodes, 168 Events, 280 Devices
            UPB modules via OMNI plugin/panel
            Plugins: Z-Wave, BLRF, OMNI, HSTouch, weatherXML, EasyTrigger
            HSTouch Clients: 3 Android, 1 Joggler

            Comment


            • #21
              In either case, Mason, your input is greatly valued. You have at least determined a potential work around.

              ALL 3 of my methods use parameters which are essentially just a single string that can be split by a char like ','. I can just add an additional parameter to specific which sub to call...

              From there I could use the main to call the function and see if that works. It is still concerning as to what is going on at the compiler level.

              Unlike MCropp, I am actually far more familiar with VB than C#. My motive is that Homeseers documentation plainly states that C# is more efficient on Linux than VB. Considering HS3 is written in VB, and it has to compile the C#, it is interesting to me that that would be the case, but whatever. Considering I am using a Pi2 version Zee, efficiency is huge for me. I was excited to read this and see what sort of positive impact it might have.

              It was frustrating to run into this setback.

              MCropp....
              When you ran from a main instead of a user function did you still get a memory leak issue?

              Comment

              Working...
              X