Difference between revisions of "TTnScript"
Line 16: | Line 16: | ||
== Methods == | == Methods == | ||
+ | {| | ||
+ | | | [[TTnScript.AddEvent | procedure AddEvent]] |||| Allows adding an event to search for. | ||
+ | |- | ||
+ | | valign="top" | [[TTnScript.RemoveEvent | procedure RemoveEvent]] |||| Removes an event in the search list. | ||
+ | |- | ||
+ | | valign="top" | [[TTnScript.RemoveAllEvents | procedure RemoveAllEvents]] |||| Removes all events in the search list. | ||
+ | |} | ||
+ | |||
+ | == How it works == | ||
+ | The class overrides TriggerDataAvailable, where it calls its internal ProcessInputData virtual procedure if there are any search strings set up. The current search algorithm (Revision 1264) searches the received buffer for each event given in the sequence received, so although for the automatic login example below it can receive both 'login' and 'password' in one call from TriggerDataAvailable, it will search for 'login' first, then 'password' and so the events will trigger in the correct sequence. | ||
+ | |||
+ | == How To == | ||
+ | |||
+ | === Automatic login === | ||
+ | A simple automatic login procedure could look like this: | ||
+ | TnScript1.AddEvent(1, 'login', 'root' + #13#10, [efIgnoreCase], nil); | ||
+ | TnScript1.AddEvent(2, 'password', 'boss' + #13#10, [efIgnoreCase], nil); | ||
+ | TnScript1.Connect; | ||
+ | After the events trigger, they will be removed from the list of strings to search for, unless you include the efPersistent event flag. |
Revision as of 17:57, 4 January 2016
Overview
- unit OverbyteIcsTnScript.pas
- inheritance TTnEmulVT - TComponent
The TTnScript is a descendant of TTnEmulVT that encapsulates searching through received data for a search strings, automatically replying a given string (optional) and triggering an event handler (optional) when a search string is encountered. It links into TTnEmulVT via the TriggerDataAvailable virtual method to get data received and if it has search strings to test for, calls processinputdata.
Properties
InputBufferSize | Size of buffer to use for internal scanning, must be twice as long as longest search string. | |
OnDisplay | When a search string is found, this event handler is triggered. Parameter is displayable text string. | |
OnStringMatch | When a search string is found, this event handler is triggered. Parameter is ID of search string. |
Methods
procedure AddEvent | Allows adding an event to search for. | |
procedure RemoveEvent | Removes an event in the search list. | |
procedure RemoveAllEvents | Removes all events in the search list. |
How it works
The class overrides TriggerDataAvailable, where it calls its internal ProcessInputData virtual procedure if there are any search strings set up. The current search algorithm (Revision 1264) searches the received buffer for each event given in the sequence received, so although for the automatic login example below it can receive both 'login' and 'password' in one call from TriggerDataAvailable, it will search for 'login' first, then 'password' and so the events will trigger in the correct sequence.
How To
Automatic login
A simple automatic login procedure could look like this:
TnScript1.AddEvent(1, 'login', 'root' + #13#10, [efIgnoreCase], nil); TnScript1.AddEvent(2, 'password', 'boss' + #13#10, [efIgnoreCase], nil); TnScript1.Connect;
After the events trigger, they will be removed from the list of strings to search for, unless you include the efPersistent event flag.