jezzzzy Posted June 23, 2009 Posted June 23, 2009 Ok. I have a custom DLL that has many methods that return events. I have studied up on ObjEvent but nearly everything has to do with IE.au3. The documentation that came with this DLL identifies lots of events that have a visual basic syntax like this: Public Event SiriusEventAntennaStatus As Sirius.AntennaStatusParamsEvent or Public Event SiriusEventChannelData As Sirius.ChannelDataParamsEvent or Public Event SiriusEventCommError As Sirius.StringParamsEvent The Class Library also identifies "Delegates". They are the following: Sirius.AntennaStatusParamsEvent Sirius.ChannelDataParamsEvent Sirius.ChannelParamsEvent Sirius.NoParamsEvent Sirius.SignalParamsEvent Sirius.SongInfoDataParamsEvent Sirius.StringParamsEvent Sirius.VBChannelDataParamsEvent Sirius.VBSongInfoDataParamsEvent Here is the test code i have started: expandcollapse popup$oSirius = ObjCreate("SiriusComm.Sirius") $oEvent = ObjEvent($oSirius,"NoParamsEvent") WITH $oSirius .PowerOn .ComPort = 6 .Open ENDWITH ;--Wait for open connection While $oSirius.isopen = 0 sleep(1000) ConsoleWrite("Waiting...") ;stuff Wend ConsoleWrite("Done" & @CRLF) ;--Try to receive an event notification $var = $oSirius.GetSignalStrength MsgBox(0,"var",$var) While 1 Sleep(500) ConsoleWrite("Testing Event Retrieval...Waiting for event" & @CRLF) WEnd ;~ $oSirius.Close Func NoParamsEvent($Eventname) MsgBox(0,"EVENT: " & $Eventname) EndFunc Func SiriusEventRadioReady($text) MsgBox(0,"RADIO_READY: " & $Text) EndFunc Func SiriusEventPortOpened($Text) ; In the complete script (see link below) we show the contents in a GUI Edit box. MsgBox(0,"PORT_OPEN: " & $Text) EndFunc Func SIRIUS_EVENT_RADIO_NOT_FOUND($Text) ; In the complete script (see link below) we show the contents in a GUI Edit box. MsgBox(0,"RADIO_NOT_FOUND: " & $Text) EndFunc Func SIRIUS_EVENT_COMM_ERROR($Text) ; In the complete script (see link below) we show the contents in a GUI Edit box. MsgBox(0,"COMM_ERROR: " & $Text) EndFunc I guess in short, I'm not sure what is supposed to go in this line: $oEvent = ObjEvent($oSirius,"NoParamsEvent") I have tried many combinations of the various event names listed in the Class Library to no success. The help file seemed to say that I could set up a universal catch for events like this: Func NoParamsEvent($Eventname) MsgBox(0,"EVENT: " & $Eventname) EndFunc But it doesn't work.
Authenticity Posted June 23, 2009 Posted June 23, 2009 The second parameter of ObjEvent() function is the prefix literal that the event should be posted to: ObjEvent($oSirius,"NoParamsEvent_") ; ... Func NoParamsEvent_NoParamsEvent($Eventname) MsgBox(0,"EVENT: " & $Eventname) EndFunc Func NoParamsEvent_SiriusEventRadioReady($text) MsgBox(0,"RADIO_READY: " & $Text) EndFunc Func NoParamsEvent_SiriusEventPortOpened($Text) ; In the complete script (see link below) we show the contents in a GUI Edit box. MsgBox(0,"PORT_OPEN: " & $Text) EndFunc Func NoParamsEvent_SIRIUS_EVENT_RADIO_NOT_FOUND($Text) ; In the complete script (see link below) we show the contents in a GUI Edit box. MsgBox(0,"RADIO_NOT_FOUND: " & $Text) EndFunc Func NoParamsEvent_SIRIUS_EVENT_COMM_ERROR($Text) ; In the complete script (see link below) we show the contents in a GUI Edit box. MsgBox(0,"COMM_ERROR: " & $Text) EndFunc
jezzzzy Posted June 23, 2009 Author Posted June 23, 2009 (edited) Where does that prefix come from? Is it something that I choose, or does it correspond to one of the delegates or something in the event syntax?: Public Event SiriusEventSignalStrength As Sirius.SignalParamsEvent The AutoIT help file says "The prefix is appended by the Objects method name." I'm not sure what that means. The method in my SignalStrength example is "GetSignalStrength". The visual basic event syntax is: "Public Event SiriusEventSignalStrength As Sirius.SignalParamsEvent". So it seems like the 'As Sirius.SignalParamsEvent' is a type that the event is being cast as. So I'm guessing that the part I need to use is the 'SiriusEventSignalStrength' part. Just don't know what do do with it. edit: typo Edited June 23, 2009 by jezzzzy
Authenticity Posted June 23, 2009 Posted June 23, 2009 You don't need to care about what the event or function implements as long as it's possible to invoke your defined handler using the prefix you've supplied. The AutoIt help file is quite clear: the prefix (NoParamsEvent_ as in the example) is appended by the object method (event) so: Public Event SiriusEventSignalStrength As Sirius.SignalParamsEvent can be defined in AutoIt as: ; Example 1 ObjEvent($Obj, 'MyPrefix') ; ... Func MyPrefixSiriusEventSignalStrength() ; 'SiriusEventSignalStrength' concatenated to the literal 'MyPrefix' ; Do stuff EndFunc ; Example 2 ObjEvent($Obj, 'SiriusEvent_') ; ... Func SiriusEvent_SiriusEventSignalStrength() ; Stuff EndFunc Don't know what are the variables the handler should be invoked with.
jezzzzy Posted June 23, 2009 Author Posted June 23, 2009 (edited) So ObjEvent() catches all events no matter their originating method? And then I just have to have function names that start with the prefix defined in ObjEvent()?If Yes to both of those questions, then how does ObjEvent know which of my functions go with which event? Based on your example, I think I need to use the bolded portion of this: Public Event SiriusEventSignalStrength As Sirius.SignalParamsEventwith my prefix concatenated on the front. Sorry if it seems like i'm being elementary about this - I'm just trying to get a solid grasp the fundamentals.edit: bold Edited June 23, 2009 by jezzzzy
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now