www.homeseer.com

Go Back   HomeSeer Message Board > HomeSeer > Home Automation Software > HomeSeer HS2™ Specific

HomeSeer HS2™ Specific General discussion about HomeSeer HS2.

Reply
 
Thread Tools Display Modes
  #1  
Old February 5th, 2010, 02:53 PM
Twisted Twisted is offline
Seer
 
Join Date: Nov 2009
Location: Wisconsin
Posts: 20
Red face Useing Com ports, did I miss something?

I developed and tested the following code in tenScripting. During testing I used a forced callback and the program works. When the program is triggered 60 seconds after startup this message is posted to the HS log:

Error 1 Running script W800RF32.vb :method not found

Did I miss something in the help file, or is something more required? It just sits waiting, in the 'threads'.

Public Sub main(ByRef Param As Object)
Dim ErrorMsg As String = ""
Dim PortConfiguration As String = "4800,N,8,1"
Dim W800RF32Script As String = "W800RF32.vb"
Dim W800RF32callback As String = "callback"
Dim ComPort As Integer = 1
Dim Hail1 As Char = ChrW((15 * 16) + 0) ' xF0 = Hail1
Dim Hail2 As Char = ChrW((2 * 16) + 9) ' x29 = Hail2
ErrorMsg = hs.OpenComPort(ComPort, PortConfiguration, 0, W800RF32Script, W800RF32callback, "")
If ErrorMsg = "" Then
hs.SetComPortRTSDTR(ComPort, True, True) ' Switch to transmit
hs.SendToComPort(ComPort, Hail1) ' Send wake up
hs.WaitEvents()
hs.SendToComPort(ComPort, Hail2) ' send Hail
hs.SetComPortRTSDTR(ComPort, False, True) ' Switch to receive
hs.WaitEvents()
DataBufferIn = hs.GetComPortData(ComPort) ' Get & Discard Echo
Else
Button = MsgBox(ErrorMsg) ' Post port problem
End If
End Sub

Public Sub callback(ByVal Param As String)
Dim DataBufferIn As String = ""
Dim ComPort As Integer = 1
DataBufferIn = hs.GetComPortData(ComPort) ' Get new Data
' Process DataIn
End Sub
Reply With Quote
  #2  
Old February 5th, 2010, 03:38 PM
Twisted Twisted is offline
Seer
 
Join Date: Nov 2009
Location: Wisconsin
Posts: 20
Default The use of literal strings

that parameter needs to be a "literal string" and can not be used as a defined variable W800RF32callback?
Reply With Quote
  #3  
Old February 5th, 2010, 04:58 PM
tenholde tenholde is offline
Seer Master
 
Join Date: Jun 2002
Posts: 946
Default

Don't see why the function and script names couldn't be supplied via string variables as you did.

In searching for functions in a namespace ( as homeseer must be doing to find your method) there must be a match for the calling sequence as well.

I would try various combinations of parameters. Perhaps ByValue and ByRef. Also, you might specify the parameter in your function as an object and cast it to a string. Something like:

Code:
Public Sub callback(ByVal Param As Object)
dim s as string
s=ctype(Param,String)
I might not have the cast correct, I didn't look it up or try it, but you get the idea?

tenholde
Reply With Quote
  #4  
Old February 5th, 2010, 05:10 PM
Twisted Twisted is offline
Seer
 
Join Date: Nov 2009
Location: Wisconsin
Posts: 20
Default The problem is getting the callback

The Parm is not used, as the data arrives on the com port. There is no callback happening. It has to do with the error:
Error 1 Running script W800RF32.vb :method not found
as far as I can tell, there is no mention of any other requirements in the help file. It appears when the script is launched, then nothing, after opening the port, it just sits, no amount of data arriving at the com port will cause the app to trigger again.
Reply With Quote
  #5  
Old February 5th, 2010, 05:26 PM
tenholde tenholde is offline
Seer Master
 
Join Date: Jun 2002
Posts: 946
Default

I assume you want HS to send the data it receives to your callback method. You specify what method you want to receive data by specifying a script name and a method name. Your code specifies a method called callback.

When HS executes the OpenComPort function from your script, it saves the name of the script and method that it will invoke when it receives data.

When HS receives data from the COM port, it must go find the script/method to call to send the data (in your case, callback).

To find your method, HS probably uses .net reflection to locate the method in memory. The inflection routines search for a method definition -- that method definition consists of both the method name and the method calling sequence. This is necessary because you can define (in .net) multiple methods with the same name but different calling sequences.

I am guessing that the reason HS is telling you that it cannot find your callback method is not because it cannot find a method named callback, but it cannot find a method named callback with a calling sequence of ........ (whatever HS is looking for). Note in the documentation (which unfortunately is for vbScript, not .net) that the parameter for the callback method is just a variable named data. In vbScript, all undefined variables are of type Object. It may be that for a .net script it is searching for the method with a name that your specified (callback) and a parameter of type Object. That is why I suggested you try changing the parameter defintion of your callback method (in your case callback) to something other than the one that is not working for you (ByVal Param As String).

Hope that helps,

tenholde
Reply With Quote
  #6  
Old February 5th, 2010, 05:59 PM
tenholde tenholde is offline
Seer Master
 
Join Date: Jun 2002
Posts: 946
Default

I've finally found an example of .net com port script, and the callback routine is defined exactly like yours. As I look again at your error message, it is not clear that it is complaining about the callback routine.

I would try placing several hs.writelog calls into the routine to see how far it gets before you receive the error (if the script starts running at all).

Let me know what you find out,

tenholde
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:17 PM.


Copyright 1998-2008 HomeSeer Technologies, LLC