Announcement

Collapse
No announcement yet.

Cannot use parentheses when calling a Sub

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

    Cannot use parentheses when calling a Sub

    I am trying to update a HS2 script to run in HS3 and am pulling my hair out on a problem I am seeing. (I know it is because of my limited scripting experience, but in most cases I get by)


    I am converting the RFXcom script step by step but when I run the first part:

    Code:
     Sub Main
       Const comport = 7  'com port used
       dim errst
       dim cnt
        errst = hs.OpenComPort(comport,"4800,n,8,2",0,"RFXCOM_ACK.txt","acknowledge")
       
     if errst <> "" then
      hs.writelog ("Error", "opening RF transmitter COM port " & errst)
            else
      errst = hs.DeleteVar("xmit")
      errst = hs.CreateVar("xmit")
      if errst <> "" then
                     hs.writelog ("Error", "creating xmit variable")
      else
       errst = hs.SaveVar("xmit",0) 'set no ACK received
       if errst <> "" then
        hs.writelog ("Error", "setting xmit variable")
       end if
      end if
       errst = hs.DeleteVar("xmitcomport")
      errst = hs.CreateVar("xmitcomport")
      if errst <> "" then
                     hs.writelog ("Error", "creating xmitcomport variable")
      else
       errst = hs.SaveVar("xmitcomport",comport) 'set com port
       if errst <> "" then
        hs.writelog ("Error", "setting xmitcomport variable")
       end if
      end if
    end if
        errst = hs.CloseComPort(comport)
       hs.writelog ("FVH","DONE!!!!")
     End Sub
    I am getting the following error message:
    Running script, script run or compile error in file: C:/Program Files (x86)/HomeSeer HS3/scripts/FvHRFXComInit.txt1044:Cannot use parentheses when calling a Sub in line 9 More info: Cannot use parentheses when calling a Sub

    Anybody have a clue, I guess it is looking at me but I do not see it

    #2
    errst = hs.DeleteVar("xmit")


    DeleteVar does not return a value, it is not a function but a SUB
    tenholde

    Comment


      #3
      Originally posted by tenholde View Post
      errst = hs.DeleteVar("xmit")


      DeleteVar does not return a value, it is not a function but a SUB

      errst = hs.CloseComPort(comport)

      Same with CloseComPort

      tenholde
      tenholde

      Comment


        #4
        dim cnt


        cnt defined but not used
        tenholde

        Comment


          #5
          http://tenholder.net/tenWare2/tenScr...3/default.aspx



          tenholde
          tenholde

          Comment


            #6
            Originally posted by tenholde View Post
            Thanks! Still struggeling from one issue to another

            Comment


              #7
              Originally posted by fvhemert View Post
              Thanks! Still struggeling from one issue to another
              Post your questions here, we can help.

              tenholde
              tenholde

              Comment


                #8
                A very generous offer, more than what I would ever dare to ask!

                Let me provide some background. Several years ago I bought a RFXcom device to control my Harrison electric curtains.

                RFXcom provided a sample script for HS2 that I used and implemented in HS2. It opens a com port to the RFXcom device, configures it for proper protocols and enables communication back and forth.

                I have now migrated to HS3 and am trying to re-use the script. This however is a difficult exercise for somebody with little or no scripting experience....

                Below is the script in its original form, any pointers are welcome


                Code:
                 ' RFXCOM Transmitter script    Version 2.00
                 ' V2.00
                ' changed for global COM port variable 
                '
                ' V1.01
                ' stopbits set to 2
                '
                ' V1.00
                ' Initial version
                 ' This script works with a RFXCOM RF transmitter. see www.rfxcom.com
                 'Add the text that is between the equal signs in the startup.txt script.
                '=========================================================================================
                'THIS SECTION IS FOR THE RFXCOM TRANSMITTER FIRMWARE VERSION 8 AND UP
                'PREVIOUS VERSIONS OF THE TRANSMITTER HAVE OTHER ACTIONS ON THE ENABLE/DISABLE MODE COMMANDS!
                'SCRIPT BELONGING TO THIS SECTION IS: RFXCOM_ACK.txt
                'GLOBAL VARIABLE FOR ACK FLAG IS "xmit"
                 
                Const comport = 9  'com port used
                dim errst
                  errst = hs.OpenComPort(comport,"4800,n,8,2",0,"RFXCOM_ACK.txt","acknowledge")
                 if errst <> "" then
                  hs.writelog "Error", "opening RF transmitter COM port " & errst
                 else
                  errst = hs.CreateVar("xmit")
                  if errst <> "" then
                                 hs.writelog "Error", "creating xmit variable"
                  else
                   errst = hs.SaveVar("xmit",0) 'set no ACK received
                   if errst <> "" then
                    hs.writelog "Error", "setting xmit variable"
                   end if
                  end if
                  errst = hs.CreateVar("xmitcomport")
                  if errst <> "" then
                                 hs.writelog "Error", "creating xmitcomport variable"
                  else
                   errst = hs.SaveVar("xmitcomport",comport) 'set com port
                   if errst <> "" then
                    hs.writelog "Error", "setting xmitcomport variable"
                   end if
                  end if
                 
                    ' send F033F033 to set the RFXCOM transmitter in 48 bits mode
                  errst = hs.SendToComPort(comport,Chr(&HF0) & Chr(&H33) & Chr(&HF0) & Chr(&H33))
                  if errst <> "" then
                                 hs.writelog "Error", "send data to RF transmitter COM port"
                                else
                   hs.writelog "Startup", "48 bits mode enabled in RFXCOM transmitter"
                  end if
                 
                  cnt = 10
                  do while hs.GetVar("xmit") = 0 AND cnt <> 0
                   hs.WaitSecs 1
                   cnt = cnt - 1
                   hs.writelog "Info", "wait for ACK"
                        loop
                  if cnt = 0 then
                   hs.writelog "Error", "no ACK received on set 48 bit mode"
                  end if
                  errst = hs.SaveVar("xmit",0) 'got ACK
                  if errst <> "" then
                   hs.writelog "Error", "setting xmit variable"
                  end if
                         
                            ' send F03DF03D to enable KlikOn-KlikOff transmission of the RFXCOM transmitter
                  errst = hs.SendToComPort(comport,Chr(&HF0) & Chr(&H3D) & Chr(&HF0) & Chr(&H3D))
                  if errst <> "" then
                                 hs.writelog "Error", "send data to RF transmitter COM port"
                  else
                   hs.writelog "Startup", "KlikOn-KlikOff enabled in RFXCOM transmitter"
                  end if
                   cnt = 10
                  do while hs.GetVar("xmit") = 0 AND cnt <> 0
                   hs.WaitSecs 1
                   cnt = cnt - 1
                   hs.writelog "Info", "wait for ACK"
                        loop
                  if cnt = 0 then
                   hs.writelog "Error", "no ACK received on enable KlikOn-KlikOff"
                  end if
                  errst = hs.SaveVar("xmit",0) 'got ACK
                  if errst <> "" then
                   hs.writelog "Error", "setting xmit variable"
                  end if
                            ' send F03CF03C to enable Harrison transmission of the RFXCOM transmitter
                  errst = hs.SendToComPort(comport,Chr(&HF0) & Chr(&H3C) & Chr(&HF0) & Chr(&H3C))
                  if errst <> "" then
                                 hs.writelog "Error", "send data to RF transmitter COM port"
                  else
                   hs.writelog "Startup", "Harrison enabled in RFXCOM transmitter"
                  end if
                   cnt = 10
                  do while hs.GetVar("xmit") = 0 AND cnt <> 0
                   hs.WaitSecs 1
                   cnt = cnt - 1
                   hs.writelog "Info", "wait for ACK"
                        loop
                  if cnt = 0 then
                   hs.writelog "Error", "no ACK received on enable Harrison"
                  end if
                  errst = hs.SaveVar("xmit",0) 'got ACK
                  if errst <> "" then
                   hs.writelog "Error", "setting xmit variable"
                  end if
                 
                           ' send F03EF03E to enable Flamingo (older transmitters Ikea-Koppla) transmission of the RFXCOM transmitter
                  errst = hs.SendToComPort(comport,Chr(&HF0) & Chr(&H3E) & Chr(&HF0) & Chr(&H3E))
                  if errst <> "" then
                                 hs.writelog "Error", "send data to RF transmitter COM port"
                  else
                   hs.writelog "Startup", "Koppla enabled in RFXCOM transmitter"
                  end if
                   cnt = 10
                  do while hs.GetVar("xmit") = 0 AND cnt <> 0
                   hs.WaitSecs 1
                   cnt = cnt - 1
                   hs.writelog "Info", "wait for ACK"
                        loop
                  if cnt = 0 then
                   hs.writelog "Error", "no ACK received on enable Koppla"
                  end if
                  errst = hs.SaveVar("xmit",0) 'got ACK
                  if errst <> "" then
                   hs.writelog "Error", "setting xmit variable"
                  end if
                            ' send F03FF03F to disable X10 transmission of the RFXCOM transmitter
                  errst = hs.SendToComPort(comport,Chr(&HF0) & Chr(&H3F) & Chr(&HF0) & Chr(&H3F))
                  if errst <> "" then
                                 hs.writelog "Error", "send data to RF transmitter COM port"
                  else
                   hs.writelog "Startup", "X10 disabled in RFXCOM transmitter"
                  end if
                   cnt = 10
                  do while hs.GetVar("xmit") = 0 AND cnt <> 0
                   hs.WaitSecs 1
                   cnt = cnt - 1
                   hs.writelog "Info", "wait for ACK"
                        loop
                  if cnt = 0 then
                   hs.writelog "Error", "no ACK received on disable X10"
                  end if
                 
                 end if
                '=========================================================================================
                  
                 'Add the text that is between the plus signs in a text file RFXCOM_ACK.txt
                'and save this file in the homeseer script directory
                '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                'this routine handles the received ack command.
                 sub acknowledge()
                 comport = hs.GetVar("xmitcomport")
                  comcnt = hs.GetComPortCount(comport) ' get number of bytes available on com port
                 comstr = hs.GetComPortData(comport) ' get data from com port
                 
                 do while comcnt > 0
                 'proces received character(s)
                  hs.writelog "Info", "ACK received from RFXCOM transmitter"
                  comcnt = comcnt - 1
                 loop
                  errst = hs.SaveVar("xmit",1) 'set ACK received
                 if errst <> "" then
                  hs.writelog "Error", "setting xmit variable"
                 end if
                end sub
                '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                  
                 
                'Save the text below in a text file for example as ARM.txt in the homeseer script directory.
                'This script can then be activated using an Event.
                 
                sub main()
                dim errst
                 comport = hs.GetVar("xmitcomport")
                 cnt = 10
                 do while hs.GetVar("xmit") = 0 AND cnt <> 0
                  hs.WaitSecs 1
                  cnt = cnt - 1
                  hs.writelog "Info", "wait for ACK"
                        loop
                 'transmit an ARM command 29F6F906F94B00  29hex=41bits, F6F9=KR10 addr, 06F9=arm, 4B00=KR10 ext addr
                 errst = hs.SendToComPort(comport,Chr(&H29) & Chr(&HF6) & Chr(&HF9) & Chr(&H06) & Chr(&HF9) & Chr(&H4B) & Chr(&H00))
                 if errst <> "" then
                  hs.writelog "Error", "send data to RF transmitter COM port"
                 end if
                 
                'transmit a DISARM command 29F6F986794B00  29hex=41bits, F6F9=KR10 addr, 8679=disarm, 4B00=KR10 ext addr
                 errst = hs.SendToComPort(comport,Chr(&H29) & Chr(&HF6) & Chr(&HF9) & Chr(&H86) & Chr(&H79) & Chr(&H4B) & Chr(&H00))
                 if errst <> "" then
                  hs.writelog "Error", "send data to RF transmitter COM port"
                 end if
                end sub

                Comment


                  #9
                  Try this in your startup.vb:

                  Code:
                   Public Sub Main(ByVal Parms As Object)
                          'THIS SECTION IS FOR THE RFXCOM TRANSMITTER FIRMWARE VERSION 8 AND UP
                          'PREVIOUS VERSIONS OF THE TRANSMITTER HAVE OTHER ACTIONS ON THE ENABLE/DISABLE MODE COMMANDS!
                          'SCRIPT BELONGING TO THIS SECTION IS: RFXCOM_ACK.txt
                          'GLOBAL VARIABLE FOR ACK FLAG IS "xmit"
                  
                          Const comport = 9  'com port used
                          Dim errst As String
                          Dim cnt As Integer
                          errst = hs.OpenComPort(comport, "4800,n,8,2", 0, "RFXCOM_ACK.txt", "acknowledge")
                          If errst <> "" Then
                              hs.WriteLog("Error", "opening RF transmitter COM port " & errst)
                          Else
                              errst = hs.CreateVar("xmit")
                              If errst <> "" Then
                                  hs.WriteLog("Error", "creating xmit variable")
                              Else
                                  errst = hs.SaveVar("xmit", 0) 'set no ACK received
                                  If errst <> "" Then
                                      hs.WriteLog("Error", "setting xmit variable")
                                  End If
                              End If
                              errst = hs.CreateVar("xmitcomport")
                              If errst <> "" Then
                                  hs.WriteLog("Error", "creating xmitcomport variable")
                              Else
                                  errst = hs.SaveVar("xmitcomport", comport) 'set com port
                                  If errst <> "" Then
                                      hs.WriteLog("Error", "setting xmitcomport variable")
                                  End If
                              End If
                  
                              ' send F033F033 to set the RFXCOM transmitter in 48 bits mode
                              hs.SendToComPort(comport, Chr(&HF0) & Chr(&H33) & Chr(&HF0) & Chr(&H33))
                              'If errst <> "" Then
                              '    hs.WriteLog("Error", "send data to RF transmitter COM port")
                              'Else
                              '    hs.WriteLog("Startup", "48 bits mode enabled in RFXCOM transmitter")
                              'End If
                  
                              cnt = 10
                              Do While hs.GetVar("xmit") = 0 And cnt <> 0
                                  hs.WaitSecs(1)
                                  cnt = cnt - 1
                                  hs.WriteLog("Info", "wait for ACK")
                              Loop
                              If cnt = 0 Then
                                  hs.WriteLog("Error", "no ACK received on set 48 bit mode")
                              End If
                              errst = hs.SaveVar("xmit", 0) 'got ACK
                              If errst <> "" Then
                                  hs.WriteLog("Error", "setting xmit variable")
                              End If
                  
                              ' send F03DF03D to enable KlikOn-KlikOff transmission of the RFXCOM transmitter
                              hs.SendToComPort(comport, Chr(&HF0) & Chr(&H3D) & Chr(&HF0) & Chr(&H3D))
                              'If errst <> "" Then
                              '    hs.WriteLog("Error", "send data to RF transmitter COM port")
                              'Else
                              '    hs.WriteLog("Startup", "KlikOn-KlikOff enabled in RFXCOM transmitter")
                              'End If
                              cnt = 10
                              Do While hs.GetVar("xmit") = 0 And cnt <> 0
                                  hs.WaitSecs(1)
                                  cnt = cnt - 1
                                  hs.WriteLog("Info", "wait for ACK")
                              Loop
                              If cnt = 0 Then
                                  hs.WriteLog("Error", "no ACK received on enable KlikOn-KlikOff")
                              End If
                              errst = hs.SaveVar("xmit", 0) 'got ACK
                              If errst <> "" Then
                                  hs.WriteLog("Error", "setting xmit variable")
                              End If
                              ' send F03CF03C to enable Harrison transmission of the RFXCOM transmitter
                              hs.SendToComPort(comport, Chr(&HF0) & Chr(&H3C) & Chr(&HF0) & Chr(&H3C))
                              'If errst <> "" Then
                              '    hs.WriteLog("Error", "send data to RF transmitter COM port")
                              'Else
                              '    hs.WriteLog("Startup", "Harrison enabled in RFXCOM transmitter")
                              'End If
                              cnt = 10
                              Do While hs.GetVar("xmit") = 0 And cnt <> 0
                                  hs.WaitSecs(1)
                                  cnt = cnt - 1
                                  hs.WriteLog("Info", "wait for ACK")
                              Loop
                              If cnt = 0 Then
                                  hs.WriteLog("Error", "no ACK received on enable Harrison")
                              End If
                              errst = hs.SaveVar("xmit", 0) 'got ACK
                              If errst <> "" Then
                                  hs.WriteLog("Error", "setting xmit variable")
                              End If
                  
                              ' send F03EF03E to enable Flamingo (older transmitters Ikea-Koppla) transmission of the RFXCOM transmitter
                              hs.SendToComPort(comport, Chr(&HF0) & Chr(&H3E) & Chr(&HF0) & Chr(&H3E))
                              'If errst <> "" Then
                              '    hs.WriteLog("Error", "send data to RF transmitter COM port")
                              'Else
                              '    hs.WriteLog("Startup", "Koppla enabled in RFXCOM transmitter")
                              'End If
                              cnt = 10
                              Do While hs.GetVar("xmit") = 0 And cnt <> 0
                                  hs.WaitSecs(1)
                                  cnt = cnt - 1
                                  hs.WriteLog("Info", "wait for ACK")
                              Loop
                              If cnt = 0 Then
                                  hs.WriteLog("Error", "no ACK received on enable Koppla")
                              End If
                              errst = hs.SaveVar("xmit", 0) 'got ACK
                              If errst <> "" Then
                                  hs.WriteLog("Error", "setting xmit variable")
                              End If
                              ' send F03FF03F to disable X10 transmission of the RFXCOM transmitter
                              hs.SendToComPort(comport, Chr(&HF0) & Chr(&H3F) & Chr(&HF0) & Chr(&H3F))
                              'If errst <> "" Then
                              '    hs.WriteLog("Error", "send data to RF transmitter COM port")
                              'Else
                              '    hs.WriteLog("Startup", "X10 disabled in RFXCOM transmitter")
                              'End If
                              cnt = 10
                              Do While hs.GetVar("xmit") = 0 And cnt <> 0
                                  hs.WaitSecs(1)
                                  cnt = cnt - 1
                                  hs.WriteLog("Info", "wait for ACK")
                              Loop
                              If cnt = 0 Then
                                  hs.WriteLog("Error", "no ACK received on disable X10")
                              End If
                          End If
                      End Sub
                  tenholde
                  tenholde

                  Comment


                    #10
                    Put this to RFXCOM_ACK.vb

                    Code:
                     Sub acknowledge()
                            'this routine handles the received ack command.
                            Dim comport, comcnt As Integer
                            Dim comstr, errst As String
                            comport = CInt(hs.GetVar("xmitcomport"))
                            comcnt = hs.GetComPortCount(comport) ' get number of bytes available on com port
                            comstr = CStr(hs.GetComPortData(comport)) ' get data from com port
                    
                            Do While comcnt > 0
                                'proces received character(s)
                                hs.WriteLog("Info", "ACK received from RFXCOM transmitter")
                                comcnt = comcnt - 1
                            Loop
                            errst = hs.SaveVar("xmit", 1) 'set ACK received
                            If errst <> "" Then
                                hs.WriteLog("Error", "setting xmit variable")
                            End If
                        End Sub
                    tenholde
                    tenholde

                    Comment


                      #11
                      put this in ARM.vb

                      Code:
                      Public Sub Main(ByVal Parms As Object)
                              Dim comport, cnt As Integer
                              comport = CInt(hs.GetVar("xmitcomport"))
                              cnt = 10
                              Do While CInt(hs.GetVar("xmit")) = 0 And cnt <> 0
                                  hs.WaitSecs(1)
                                  cnt = cnt - 1
                                  hs.WriteLog("Info", "wait for ACK")
                              Loop
                      
                              'transmit an ARM command 29F6F906F94B00  29hex=41bits, F6F9=KR10 addr, 06F9=arm, 4B00=KR10 ext addr
                              hs.SendToComPort(comport, Chr(&H29) & Chr(&HF6) & Chr(&HF9) & Chr(&H6) & Chr(&HF9) & Chr(&H4B) & Chr(&H0))
                              'If errst <> "" Then
                              '    hs.writelog("Error", "send data to RF transmitter COM port")
                              'End If
                      
                              'transmit a DISARM command 29F6F986794B00  29hex=41bits, F6F9=KR10 addr, 8679=disarm, 4B00=KR10 ext addr
                              hs.SendToComPort(comport, Chr(&H29) & Chr(&HF6) & Chr(&HF9) & Chr(&H86) & Chr(&H79) & Chr(&H4B) & Chr(&H0))
                              'If errst <> "" Then
                              '    hs.writelog("Error", "send data to RF transmitter COM port")
                              'End If
                          End Sub
                      tenholde

                      Comment


                        #12
                        I have no way of testing the above code, but the syntax and obvious errors have been corrected.

                        I defined several variables.

                        Also, SendToComPort does not return a value. It is a SUB not a FUNCTION so I adjusted the code accordingly.

                        Good luck. Let us know what is happening.

                        tenholde
                        tenholde

                        Comment


                          #13
                          Wow, thanks for this!

                          I have copied the modified scripts and I believe we are getting closer.

                          This where am at now:

                          • Removed Public Sub Main(ByVal Parms As Object) from the part I put into the startup.vb (I believe we do not need it, otherwise we would have two in startup.vb)
                          • Changed hs.OpenComPort(comport, "4800,n,8,2", 0, "RFXCOM_ACK.txt", "acknowledge") into hs.OpenComPort(comport, "4800,n,8,2", 0, "RFXCOM_ACK.vb", "acknowledge") because it is now a .vb

                          When I now run restart, it has issues with finding the correct sub in RFXCOM_ACK.VB:

                          Running script RFXCOM_ACK.vb :Parameter count mismatch.->Does entry point acknowledge exist in script? at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Obj ect obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at A.c17b105f989efe61e5979e67bec1ef734.cffd66cb0782c50126727e3f a75582d7a()

                          Comment


                            #14
                            Originally posted by fvhemert View Post
                            Wow, thanks for this!

                            I have copied the modified scripts and I believe we are getting closer.

                            This where am at now:

                            • Removed Public Sub Main(ByVal Parms As Object) from the part I put into the startup.vb (I believe we do not need it, otherwise we would have two in startup.vb)
                            • Changed hs.OpenComPort(comport, "4800,n,8,2", 0, "RFXCOM_ACK.txt", "acknowledge") into hs.OpenComPort(comport, "4800,n,8,2", 0, "RFXCOM_ACK.vb", "acknowledge") because it is now a .vb

                            When I now run restart, it has issues with finding the correct sub in RFXCOM_ACK.VB:

                            Running script RFXCOM_ACK.vb :Parameter count mismatch.->Does entry point acknowledge exist in script? at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Obj ect obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at A.c17b105f989efe61e5979e67bec1ef734.cffd66cb0782c50126727e3f a75582d7a()
                            Try:

                            Sub acknowledge(ByVal data As String)

                            tenholde
                            tenholde

                            Comment


                              #15
                              Yes that did it! Thanks for your help, I could not have done it without you. True power of a user community!

                              Next step, create a device with two buttons, "open" and "close". Clicking the button will run a script to open or close the curtain, changing the status will do the same.

                              But that's for tomorrow hope I can find some examples that I can use.

                              Comment

                              Working...
                              X