Announcement

Collapse
No announcement yet.

C# SCripting -- At the end of my rope

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

    C# SCripting -- At the end of my rope

    I've had trouble with C# scripting when I need to reference an assembly not included by default. Because I'm repurposing the machine I was running HomeSeer on, I've installed it on a different machine. Everything looks good except running two scripts that reference System.Net. I've done everything that the help file says to do and the result can be seen below. I NEED TO SEE the full script that HS is compiling to figure out what to do. Moving the code and building an executable, the same code runs fine. THERE IS SOMETHING WRONG WITH THE WAY HOMESEER WRAPS THE SCRIPT FILES.

    I've attached the two scripts in question.

    I cannot believe that nobody else is seeing this kind of problem. I've even filed a bug but crickets.

    It might be time to start looking for an alternative HA system if I can't get this working.

    Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\GetCurrentWeather.cs: {interactive}(4,6): error CS1525: Unexpected symbol `System', expecting `(' {interactive}(4,7): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement {interactive}(5,6): error CS1525: Unexpected symbol `System', expecting `(' {interactive}(5,14): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement {interactive}(6,6): error CS1525: Unexpected symbol `Scheduler', expecting `(' {interactive}(6,7): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement {interactive}(7,6): error CS1525: Unexpected symbol `HomeSeerAPI', expecting `(' {interactive}(7,7): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement {interactive}(8,0): error CS1525: Unexpected symbol `public', expecting `(' {interactive}(8,20): error CS1525: Unexpected symbol `{', expecting `(' {interactive}(10,2): error CS1525: Unexpected symbol `public' {interactive}(10,10): error CS1547: Keyword `void' cannot be used in this context {interactive}(10,20): error CS1525: Unexpected symbol `(' {interactive}(17,0): error CS1525: Unexpected symbol `public' {interactive}(17,8): error CS1547: Keyword `void' cannot be used in this context {interactive}(17,16): error CS1525: Unexpected symbol `(' {interactive}(31,5): error CS1524: Expected catch or finally {interactive}(44,4): error CS1525: Unexpected symbol `catch', expecting `catch' or `finally' {interactive}(48,4): error CS1525: Unexpected symbol `}', expecting `catch' or `finally' {interactive}(55,37): error CS8025: Parsing error
    Attached Files

    #2
    Not many people write scripts in C# for HS3 which is probably why you are not seeing other posts on the subject. To make matters worse, a user has indentified a potential memory leak when running C# scripts.

    Unfortunately, only HST will be able to tell you how they have wrapped up the script with references etc.

    Perhaps it may be better placing your code through a online C# to VB converter and run that?
    Jon

    Comment


      #3
      I can convert to VB.NET easily enough. I'm a C# developer so I'd work in my preferred environment. My feeling is that if you're going to offer the capability, then support it. HST has been totally silent on this issue. I think the scripts were working prior to .280 but can't verify.

      Comment


        #4
        If you are thinking about coding in vb.net instead (recommended) then look here for development tool. Be sure to read and download the HS3 version.

        tenholde
        tenholde

        Comment


          #5
          Originally posted by tenholde View Post
          If you are thinking about coding in vb.net instead (recommended) then look here for development tool. Be sure to read and download the HS3 version.

          tenholde
          Not really looking for vb.net. Just want the C# scripting to work.

          Comment


            #6
            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.
            - Bram

            Send from my Commodore VIC-20

            Ashai_Rey____________________________________________________________ ________________
            HS3 Pro 3.0.0.534
            PIugins: ZMC audio | ZMC VR | ZMC IR | ZMC NDS | RFXcom | AZ scripts | Jon00 Scripts | BLBackup | FritzBox | Z-Wave | mcsMQTT | AK Ikea

            Comment


              #7
              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.

              Comment


                #8
                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.
                Mike____________________________________________________________ __________________
                HS3 Pro Edition 3.0.0.548, NUC i3

                HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

                Comment


                  #9
                  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.
                  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


                    #10
                    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.

                    Comment


                      #11
                      Curious, Mike, did the solution I posted above work for you?
                      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


                        #12
                        Sadly, no. Thanks.

                        Comment


                          #13
                          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.
                          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


                            #14
                            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

                            Comment


                              #15
                              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.

                              Comment

                              Working...
                              X