Announcement

Collapse
No announcement yet.

Problem opening com port in .vb script - Fixed!

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

    Problem opening com port in .vb script - Fixed!

    Someone said I should learn to use vb scripts instead of txt scripts, so I'm trying to do that. Can anyone tell me what's wrong with this script?

    "OpenComPort3.vb" script below runs to open the port:
    Sub Main(parm as object)
    dim e
    e=hs.OpenComPort(3,"9600,n,8,1",1,"DenonReceiver.vb","main", vbcr)
    if e <> "" then
    hs.writelog("Error opening com3",e)
    end if
    End Sub
    "DenonReceiver.vb" script below is called when characters are received:
    Sub Main(ByVal data as String)
    ' when mode is a 1, data is complete string
    ' process the com port data here
    hs.writelog("COM DATA 3",data)
    hs.setdevicestring("v8",data)
    End Sub
    Both scripts run without errors on their own, but when characters are received and DenonReceiver.vb is called, it logs the following error:

    "Error 3 - Running script DenonReceiver.vb :method not found"

    I got it working fine in the .txt version, but for the life of me can't figure out how to call DenonReceiver.vb properly... Help?!!..

    #2
    Try changing

    e=hs.OpenComPort(3,"9600,n,8,1",1,"DenonReceiver.vb","main", vbcr)

    to

    e=hs.OpenComPort(3,"9600,n,8,1",1,"DenonReceiver.vb","Main", vbcr)

    its a subtle difference (capital M for main) vbscript is probably not bothered about, but vb.net is. It is trying to find 'main' rather than 'Main' and failing giving you that error.

    Comment


      #3
      You also need to dimension the e to a valid vb.net type ie
      dim e as String
      Last edited by Rupp; December 5, 2011, 05:51 PM.
      💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

      Comment


        #4
        I have found calls to vb scripts to be case sensitive. Wouldn't want things to be too easy.

        Originally posted by mrhappy View Post
        Try changing

        e=hs.OpenComPort(3,"9600,n,8,1",1,"DenonReceiver.vb","main", vbcr)

        to

        e=hs.OpenComPort(3,"9600,n,8,1",1,"DenonReceiver.vb","Main", vbcr)

        its a subtle difference (capital M for main) vbscript is probably not bothered about, but vb.net is. It is trying to find 'main' rather than 'Main' and failing giving you that error.
        Don

        Comment


          #5
          Matching the case (Main vs main), and dimensioning the variable fixed it all up. Thanks guys!!

          Comment

          Working...
          X