Announcement

Collapse
No announcement yet.

Read temp sensors with vb script

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

    Read temp sensors with vb script

    I have a VB script that I can't run without errors. It requires one extra dll and one extra ocx that has to be registered.

    My script "tac.vb" connects to a PCL and reads the value from one temp sensor called "jonas-Zon01-temp" and updates HS device "K1"

    Is is not working and I get some errors in the HS logfile.

    I have a working vb program written in "Visiual Studio 2008"
    When you press the button "Connect and login" it returns
    Connect success!
    Login success!
    19.66

    Any help would be appreciated.
    Attached Files

    #2
    Code:
    Option Strict Off
    imports Scheduler
    imports System
    Public Module scriptcode2
     #Region "Automatically generated code, do not modify"
     'Automatically generated code, do not modify'
     Event Sources Begin
     <SYSTEM.CONTEXTSTATICATTRIBUTE()> Public WithEvents hs As Scheduler.hsapplication
     <SYSTEM.CONTEXTSTATICATTRIBUTE()> Public WithEvents hsp As scheduler.hsp
     <SYSTEM.CONTEXTSTATICATTRIBUTE()> Public WithEvents hssystem As scheduler.phone0
     'Event Sources End
     'End of automatically generated code
     #End Region
     Dim result As Integer
     Dim ost, ret As Integer
        Dim strErr As String strErr = "-"
    ' Connect
     result = AxTacosOcx1.Connect("192.168.20.111")
     If result <> 0 Then
     hs.writelog ("Connect failed! returned " & Hex(result) & vbCrLf)
        Else
         hs.writelog ("Connect success!" & vbCrLf)
        End If
    ' Login
     ost = AxTacosOcx1.Login("*", "*") 'AxTacosOcx1.Login("system", "system")
        If ost <> 0 Then
         ret = AxTacosOcx1.GetErrorString(ost, strErr)
            hs.writelog ("Login failed! " & strErr & vbCrLf)
        Else
         hs.writelog ("Login success!" & vbCrLf)
        End If
        Dim varData As Object
    ' ReadValue
     Result = AxTacosOcx1.ReadSynchronous("jonas-Zon01-temp", "PV", 0, varData)
        If Result <> 0 And Result <> 1 Then
         ret = AxTacosOcx1.GetErrorString(Result, strErr)
            hs.writelog ("Read failed! - " & strErr & " (" & Hex(Result) & ")" & vbCrLf)
        Else
      hs.setdevicevalue "K1", (varData & vbCrLf)
      hs.setdevicestring "K1", cstr(hs.devicevalue("K1"))
        End If
    End Module
    I see two issues in your code:
    1) the error you are getting is being caused by a syntax error in line 17:
    Code:
    Dim strErr As String strErr = "-"
    Which should be written one of the two following ways:
    Code:
    Dim strErr As String
    strErr = "-"
    -or-
    Code:
    Dim strErr As String = "-"

    2) This section of code does not make sense unless varData is being passed "by reference" to and from the call to AxTacosOcx1.ReadSynchronous (I've not had a chance to dig through the code for this):
    Code:
        Dim varData As Object
    ' ReadValue
     Result = AxTacosOcx1.ReadSynchronous("jonas-Zon01-temp", "PV", 0, varData)
        If Result <> 0 And Result <> 1 Then
         ret = AxTacosOcx1.GetErrorString(Result, strErr)
            hs.writelog ("Read failed! - " & strErr & " (" & Hex(Result) & ")" & vbCrLf)
        Else
      hs.setdevicevalue "K1", (varData & vbCrLf)
      hs.setdevicestring "K1", cstr(hs.devicevalue("K1"))
        End If
    If varData is being passed "by reference" to and from AxTacosOcx1.ReadSynchronous, what data is being returned in varData? If not then perhaps you should be using the value returned in Result instead?

    Also, keep in mind that Device Values in HS are of a variable type 'Long Integer' so you can only assign LongInt values to it. You are trying to assign the object varData (of unknown type) plus a vbCrLf to the Device Value of K1. Assuming this is a value (either string or integer) you need to convert it to a long int:
    Code:
    hs.setdevicevalue "K1", clng(varData)
    Best regards,
    -Mark-

    If you're not out on the edge, you're taking up too much room!
    Interested in 3D maps? Check out my company site: Solid Terrain Modeling

    Comment


      #3
      I changed to

      Code:

      Dim strErr As String
      strErr = "-"</PRE>
      I get the following error

      2010-01-03 21:49:25 - Error - Script compile error: Namespace or type 'Scheduler' has already been imported.on line -1

      Thanks,
      Last edited by jonas.hellgren; January 4, 2010, 06:51 AM.

      Comment

      Working...
      X