Announcement

Collapse
No announcement yet.

XML Script works with tenScripting, not HS

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

    XML Script works with tenScripting, not HS

    I am using XML to access data from a TED power monitor. I found the code fragments at: http://board.homeseer.com/showpost.p...7&postcount=36

    My code is:

    PHP Code:
    Dim oXML As MSXML2.DOMDocument CreateObject("Msxml.DOMDocument")

            
    oXML.async False
            
    If oXML.load("http://172.16.10.29:3080/api/LiveData.xml"Then
                Dim Solar_Power 
    As String oXML.selectSingleNode("/LiveData/Power/MTU3/PowerTDY").text
                Solar_PowerWH 
    CDec(Solar_Power)
                
    ' Note: currently all values are negative, but with upcoming release, consumption will be positive (Inverters using some current)
                ' 
    and generation negativeExclude values when no generation is going on.
                If 
    Solar_PowerWH 0 Then
                    Solar_PowerWH 
    = -Solar_PowerWH
                
    Else
                    
    Solar_PowerWH 0
                End 
    If
                
    hs.SetDeviceValue(virt_device_SolarPVGeneratedWhSolar_PowerWH)
                
    hs.SetDeviceString(virt_device_SolarPVGeneratedWhCStr(Solar_PowerWH) & " Wh")
                
    hs.SetDeviceLastChange(virt_device_SolarPVGeneratedWhCurrentUpdateDateTime)
            Else
                
    LogIt_
                  
    "Your XML Document failed to load" _
                  
    " due the following error." _
                  
    " Error #: " oXML.parseError.errorCode ": " oXML.parseError.reason _
                  
    " Line #: " oXML.parseError.line _
                  
    " Line Position: " oXML.parseError.linepos _
                  
    " Position In File: " oXML.parseError.filepos _
                  
    " Source Text: " oXML.parseError.srcText _
                  
    " Document URL: " oXML.parseError.url)
                
    Solar_PowerWH 0
            End 
    If
            
    TraceIt(4"TED MTU Power Generated=" CStr(Solar_PowerWH)) 
    When I run it using tenScripting it runs fine. When I export it to HS Pro, I get the following error:
    Script compile error: Type 'MSXML2.DOMDocument' is not defined.on line 215
    I suspect I'm missing an Include or something that is different with the environments, but I haven't be able to track it down.

    #2
    You need to add MSXML2 to the ScriptingReference item in the HS configuration file. See:

    http://board.homeseer.com/showthread...46001&t=127177

    tenholde
    tenholde

    Comment


      #3
      I've tried following those instructions and am still having problems:

      Looked at tenScripting project References in VB Express and saw MSXML2 DLL as:
      C:\Users\Lakehouse\Documents\Visual Studio 2010\Projects\tenScripting\tenScripting\obj\Debug\Interop.MS XML2.dll


      Copied Interop.MSXML2.dll into HomeSeer base directory.

      Set settings.ini to:
      ScriptingReferences=MSXML2;Interop.MSXML2.dll


      Getting error:
      Scripting runtime error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->

      System.IO.FileNotFoundException: Could not load file or assembly 'Interop.MSXML2, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its

      dependencies. The system cannot find the file specified.File name: 'Interop.MSXML2, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null' at

      scriptcode23.scriptcode23.CalculateDailySolarRadiation(Objec t Parms)WRN: Assembly binding logging is turned OFF.To enable assembly bind failure

      logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.Note: There is some performance penalty associated with

      assembly bind failure logging.To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. --- End of inner

      exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes

      methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig,

      MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr,

      Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,

      BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[]

      parameters) at Scheduler.VsaScriptHost.Invoke(String ModuleName, String MethodName, Object[] Arguments)
      Have also tried scripting reference path DLL to point to original location. Same results.

      Any ideas?

      Comment


        #4
        Could you zip up your tenScripting project and send it to me.

        tenholde
        tenholde

        Comment


          #5
          I am far from a coding expert but is your code a mix of vbscript and .net? I thought the scripting references were for .net DLL's, when I have worked with XML in .net it does require the reference but I created the XML document using Dim xy As New XmlDocument and had Imports System.XML at the top of the script.

          If you were using .net then the scriptingreferences entry I used was;

          SriptingReferences=System.XML;System.XML.dll

          For VBScript I used;

          set objelec = CreateObject("Microsoft.XMLDOM")
          objelec.loadXML(data)
          Set objelec = objelec.selectSingleNode("msg/ch1/watts")
          hs.writelog "Test", objelec.text & " Watts"

          And there was no need for any references IIRC.

          Comment


            #6
            The reference:

            ScriptingReferences=MSXML2;Interop.MSXML2.dll


            refers to an interop assembly that is created when you reference a non .net class from a .net program -- VS creates it and adds it to the VS project.

            The code should be changed to reference a .net XML class (and then make sure that the .net XML dll is referenced by HS using ScriptingReferences.). Similar to your .net code.

            tenholde
            tenholde

            Comment


              #7
              Working - thanks for the help

              Thanks for the assistance. For the record, here is the vb.net program I ended up with:

              Code:
              Set settings.ini to:[INDENT] ScriptingReferences=System.XML;System.XML.dll 
              [/INDENT]program.vb code fragment:[INDENT]Imports System.Xml
              
              ...
              
                      Try
                          Dim oXML As XmlDocument
                          oXML = New XmlDocument()
                          oXML.Load("http://172.16.10.29:3080/api/LiveData.xml")
                          Dim XMLnode As XmlNode = oXML.SelectSingleNode("/LiveData/Power/MTU3/PowerTDY")
                          SolarPVWh = CDec(XMLnode.InnerText)
                         ' Code doing what i want with SolarPVWh
              
                      Catch ex As Exception
                          'Error trapping
                          LogIt("Exception Caught while trying to retrieve TED /LiveData/Power/MTU3/PowerTDY ")
                          LogIt(ex.Message.ToString())
                      End Try
              [/INDENT]
              Editorial comment: It seems mixing vbscript code and vb.net code is a common error - examples in forum contain both and usually not identified in example. I realize the compatibility issue, but having one scripting language would make things alot easier.

              Comment

              Working...
              X