Announcement

Collapse
No announcement yet.

C# SCripting -- At the end of my rope

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

  • DNATechnologySolutions
    replied
    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?

    Leave a comment:


  • rmasonjr
    replied
    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.

    Leave a comment:


  • DNATechnologySolutions
    replied
    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.

    Leave a comment:


  • rmasonjr
    replied
    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

    Leave a comment:


  • DNATechnologySolutions
    replied
    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

    Leave a comment:


  • rmasonjr
    replied
    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");

    Leave a comment:


  • mkropp
    replied
    Crickets

    No change. I redid some of my scripts in VB because even the simplest script in C#, while it worked, was causing HS to crash daily (I think a memory leak).

    All the script did was get HomeSeer's up time and set a device string with a formatted representation.

    I haven't even seen as much as an acknowledgement that this is problem and that they're looking at it.

    Personally, I hate working in VB since I work in C# all the time.

    Not at all happy with the non-responses and the ongoing issue.

    Leave a comment:


  • DNATechnologySolutions
    replied
    Has anyone found a solution for C# not compiling

    Any find a working solution for this?

    When I run any .cs file I get compile errors in the log stating multiple references have been made to libraries

    Code:
    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");
    }
    I've gone so far as to isolate just the line hs.writeLog(""); and it wont compile

    This is on the Homeseer Zee S2 with HS3-Pi 3.0.0.293

    Leave a comment:


  • reidfo
    replied
    If you post the script with my changes that you tried, along with the errors I'll see if I can reproduce. I do have HS3 on Windows too. If there are issues with C# scripts in general I want to work them out since I detest VB (and I even used to teach it!) and prefer C# myself.

    Leave a comment:


  • mkropp
    replied
    Sadly, no. Thanks.

    Leave a comment:


  • reidfo
    replied
    Curious, Mike, did the solution I posted above work for you?

    Leave a comment:


  • mkropp
    replied
    Originally posted by Uncle Michael View Post
    Have you submitted a bug report? Although it seems like board posts would be a useful route to gain insights into product performance, HST does not routinely monitor the board, and posting here is not a reliable way to communicate with HST.
    Bug has been filed. Hoped there were more users using C# to help.

    Leave a comment:


  • reidfo
    replied
    I managed to get your script running with a few modifications. I'm running under Linux, but this should work under Windows as well.

    First, I modified settings.ini and added the following:
    Code:
    ScriptingReferences=System.Net;System.Net.dll
    Here's the modified script:
    Code:
    public object Main(object[] Parms)
    {
    
        const string ForecastURL = "http://forecast.weather.gov/MapClick.php?lat=42.542&lon=-71.6529&unit=0&lg=english&FcstType=dwml";
    //    const string ForecastFile = @"D:\Users\Miles\Documents\Homeseer\Weather Data\CurrentForecast.xml";
        const string ForecastFile = "/tmp/reid.xml";
    
        hs.WriteLog("GetWeatherForecast", "Getting current weather forecast from " + ForecastURL);
    
        try {
                System.Net.WebClient client = new System.Net.WebClient();
                client.Headers.Add("User-Agent", "HomeSeer/1.0");
                client.DownloadFile(ForecastURL, ForecastFile);
    
                hs.WriteLog("GetWeatherForecast", "Current weather forecast retrieved to " + ForecastFile);
        }
        catch (Exception ex) {
            hs.WriteLog("GetWeatherForecast", "ERROR: Could not retrieve current weather forecast:" + ex.Message);
        }
    
        return 0;
    }
    A couple of notable things:
    1. The using statement in your try block was causing the syntax error you posted. I got the same thing, so I refactored to remove the using statement.
    2. The @ literal in your string definition also caused syntax errors. I know it's valid C# syntax, but the script compiler didn't like it for whatever reason.
    3. I explicitly referenced System.Net.WebClient and removed the "using System.Net;" statement. The using did not seem to make any difference in the script, and WebClient could only be resolved by explicitly referencing it.

    EDIT: You'll obviously need to change the ForecastFile variable to reflect your path, but do it without the @ operator. Even when I tried with = @"/tmp/reid.xml" the script failed.

    Leave a comment:


  • Uncle Michael
    replied
    Originally posted by mkropp View Post
    Someone from HS needs to address this. They've been silent.
    Have you submitted a bug report? Although it seems like board posts would be a useful route to gain insights into product performance, HST does not routinely monitor the board, and posting here is not a reliable way to communicate with HST.

    Leave a comment:


  • mkropp
    replied
    Originally posted by AshaiRey View Post
    mmm i tought i posted this before but anyway here's it again..
    Have you added the DLL's to the settings.ini file (atleast that's how it work for HS2)?
    Also look carefully at the format because if you put them at the end of the line they will not be referenced is a previous one fails without a warning.
    No, for C# they don't go in settings.ini. I did try that anyway and it made things worse.

    Someone from HS needs to address this. They've been silent.

    Leave a comment:

Working...
X