|
Archive for the 'Scripting' Category
Thursday, April 19th, 2007
The Value field in the keyboard mapper has a 4,096-character limit. When mapping CScript commands to a key, TinyTERM versions prior to 4.12 do not allow the full 4,096 characters. There is no patch for earlier versions.
CR 107, fixed in TinyTERM 4.12.
Posted in CScript, Keyboard | Comments Off on Keyboard Mapper Character Limit
Wednesday, April 18th, 2007
Connecting via modem, when TERM tries to XMIT a string the connection dies. This was tracked to the parity not being sent. There was no option to set parity in the modem initialization string.
The workaround was to use the TERM Script Language command SET MASKPAR ON. This masks the parity being sent.
CR 176
Posted in Modem, TERM, TSL, UNIX | Comments Off on Can’t Set Parity in UNIX
Wednesday, April 18th, 2007
TinyTERM includes a sample script called noprefs.cs. This allows you to remove the Preferences item from the Edit menu. But what if you want to remove more items from the menus? Where are the MENUITEM numbers listed?
You don’t actually have to use the MENUITEM number to remove a menu item. If you’ll take a look at the first RemoveMenuItem() command in the script noprefs.cs, it does its work entirely by position:
RemoveMenuItem( GetSubMenu( hMenu, 1 ), 3 , 1024 );
The first parameter, GetSubMenu( hMenu, 1), is the menu number of menu index 1, the Edit menu. The menus are indexed from left to right, with the first menu (File) being index 0. So you can use GetSubMenu(hMenu,3) to indicate the Tools menu, for example.
The second parameter, 3, is the index number of the menu item. Again, these are indexed starting at 0. Item 3 in the sample script is the separator bar on the Edit menu. It’s actually a separate menu item, though you can’t click it.
The third parameter, 1024, is an internal command which tells RemoveMenuItem() to delete by position index instead of by actual number. This is required when using RemoveMenuItem() in this fashion.
Please note that removing one item reindexes every item below it. So if you remove item 3, the next item down becomes item 3, etc. When removing menu items in this fashion, it’s best to remove them from the bottom up.
Posted in CScript | Comments Off on Removing Menu Items in TinyTERM 4
Wednesday, April 18th, 2007
It is possible to open multiple sessions over a single serial connection. It requires software such as mscreen or FacetTerm on the host system. Without that, only one session can run on a serial connection.
You also need to set the screen pages. That’s handled differently by different versions of TERM and TinyTERM:
- TERM: Use the TERM Script Language command PAGES:
pages 4
- TinyTERM (up to 3.3) or TERM for Windows: Go to the Configure menu and select Emulation. Change the Screen Pages line.
- TinyTERM for DOS: From the main menu, select Emulation. Change the Screen Pages line.
- TinyTERM 4.00-4.20: Edit the .tpx file in Notepad or another text editor. Search for the “pages=” line. Edit the number there.
- TinyTERM 4.21 and higher: Go to the Edit menu and select Preferences. Change the Screen Pages drop-down.
Regardless of which product you’re using, accepted values for the screen pages are 1-6.
CR 26, added to user interface in TinyTERM 4.21
Posted in Serial (RS232), TSL | Comments Off on Multiple Sessions Over a Serial Connection
Monday, April 16th, 2007
Using the TERM Script Language included in TERM for UNIX, the ABORT command and ^C both fail to stop the script. This is normal. You will need to add:
SET ABORT ON
near the beginning of the script, before you would type ^C or enter the ABORT command in the script. Otherwise, the abort attempt is ignored.
Posted in TSL | Comments Off on Aborting a TERM Script
Friday, April 13th, 2007
Any version of TERM or TinyTERM that can run a script can also have the host system it’s connected to execute a TSL or CScript command. To do that, precede the command with an escape character ^[ (ASCII 27) and the string &oF, then follow it with a carriage return ^M (ASCII 13). Send the entire sequence as screen display information. When TinyTERM receives the ^[&oF string, it stops screen display and accepts everything until the ^M carriage return is received. It then processes the appropriate data as script commands.
A sample shell script for Linux might look like this (\033 is the octal value of the escape character, and \015 is the octal value of the carriage return):
echo -e “\033&oFspawn(1,”notepad.exe”,”notepad readme.txt”);\015″
Sent to TinyTERM 4.x, this string executes the CScript command spawn(), which in turn runs Notepad and opens the file readme.txt. A similar command in TERM Script Language would read:
echo -e “\033&oFrun vi readme.txt\015”
This feature is not documented in most releases of TERM or TinyTERM. It was added to the TinyTERM 4.30 CScript documentation.
CR 384
Posted in CScript, Scripting, TSL | Comments Off on Execute Script Command from Host
Friday, April 13th, 2007
There is a command in the CScript language that will launch a Windows-based application: spawn(). Here is the function definition from the TinyTERM Programmers Reference Manual:
Void Spawn(iWait, sCmdString, sArguments )
Passes sCmdString to the operating system to be run with the arguments sArguments. Note that the command name, without an extension, must always be the first argument in sArguments. Note that you cannot use quotes as part of sCmdString or sArguments, so if you must launch an application with a space in its Windows filename, you must use DOS 8.3 filenames to refer to that application with the spawn command.
iWait
0 Wait until spawned process ends before running next command
1 No wait
2 Detach spawned process from the console
3 Wait for spawned process to complete its startup procedures before continuing with the next command
For example, the following script command will launch the Notepad application and open the file untitled.txt:
spawn( 0, “notepad.exe”, “notepad untitled.txt”);
A similar command would look like this for Acrobat Reader 5.0:
spawn(1,”C:\Progra~1\\Adobe\\Acroba~1\\Reader\\AcroRd32.exe”,”AcroRd32 D:\path\document.pdf”);
Note the use of \\ as a directory separator. You can also use / if you prefer.
This doesn’t work with some command-line programs, like the ECHO command and batch files. Batch files and a number of Windows internal commands run through the COMMAND.COM or CMD.EXE program. You have to make that program part of the spawn() string, using the /C option. Whether you use COMMAND.COM or CMD.EXE depends on your version of Windows.
For example, suppose you need to copy a text file to the printer port. COPY is part of COMMAND.COM, so the equivalent spawn() item would be:
spawn(1,”command.com”,”command /c copy file.txt > lpt1:”);
The same syntax will work for a Windows batch file:
spawn(1,”command.com”,”command /c execute.bat”);
You can also use this to launch any document with the Windows START command. Again turning to Adobe as an example, the following command will run any version of Acrobat Reader that’s installed, loading the file document.pdf:
spawn(1,”cmd.exe”,”cmd /c start D:\\path\\document.pdf”);
Century Software, Inc., has had a request to bypass the need for START. When a file name is passed, it would use the existing Windows file associations to determine the correct application.
CR 687
Posted in CScript | Comments Off on Launch Windows-Based Application from TinyTERM
Friday, April 13th, 2007
You can do this in TinyTERM 4.x by mapping a key to the CScript command SessionNew(). To do this, open the keyboard map and click on the key you want to use. Change the Action to COMMAND. In the Value field, enter:
SessionNew(“default.tpx”);
Replace default.tpx with the name of the session you want to open, enclosed in quotation marks.
If you don’t want to open a specific file each time, but select one on the fly instead, combine SessionNew() with StdOpen(), which will give you a standard file browse dialog. That command is:
SessionNew(StdOpen(“C:\\Program Files\\Century\\TinyTERM”,”tpx files|*.tpx|”,”tpx”,”TinyTERM Connection Files”));
Posted in CScript, Keyboard | Comments Off on Open Session on a Keystroke
Thursday, April 12th, 2007
The events listed in the TinyTERM version 4 CScript documentation can be handled by overloading the event handler functions. These functions often contain code that is neccessary to handle the event properly within TinyTERM, and this code must not be changed. You should only add additional code that you wish to execute when these events fire.
For example, if you would like to display a dialog when the user disconnects from the server that gives the user the option of reconnecting to the server or closing TinyTERM, you could use the following script :
/////////////////////////////////////
//
// Reconnect.cs
//
// This function displays a message when the user disconnects from the server
// and allows them to reconnect to the server by clicking the OK button
// in the message box.
//
// Written 7/17/03 by Jeremy Wolfe
//
/////////////////////////////////////////////
var nResponse;
var szTitle;
var szMsg;
szTitle = “Disconnected…”;
szMsg = “Click OK to Connect\rClick Cancel to Exit TinyTERM”;
// called when the session is closed
function
Reconnect()
{
nResponse = msgbox(szMsg, szTitle, 1);
if(nResponse == 0)
{
te.connect();
}else
{
quit();
}
}
function
TE_EDisconnect(DlgObj, CtlObj, nCode)
{
DisConnected(FindSessionByTE(CtlObj));
Reconnect();
}
The following is a list of the event handler functions :
TE_EExit()
This event fires when the user has pressed ALT-F4. This can only happen when the UseAlt property is set to FALSE. This can be used by the application to shut down.
function
TE_EExit()
{
File_Exit();
}
TE_EDisconnect()
This event fires when a connection has terminated (either through user action or a remote disconnection; i.e., when a socket is disconnected). This event also fires when an attempted connection fails. You will not receive this event if a given TE control is destroyed before the connection is terminated.
function
TE_EDisconnect(DlgObj, CtlObj, nCode)
{
DisConnected(FindSessionByTE(CtlObj));
}
TE_EConnect()
This event fires when a connection has occurred successfully.function
TE_EConnect(DlgObj, CtlObj, nCode)
{
local nSess;
local tfile;
nSess = FindSessionByTE(CtlObj);
Connected(nSess);
tfile = field(TESESS[nSess][556], _val(TESESS[nSess][438]) +1, _asc("|"));
if( exists( tfile) && _val(TESESS[nSess][438]) != -1) {
dprintln("Compile and Run Post Session Connect = ",tfile);
script_run(tfile);
}
script_sessconnect();
}
TE_EPrint(bON)
This event fires when printing commences or stops. bON is set to TRUE when printing starts, and FALSE when printing ends.
function
TE_EPrint(DlgObj, CtlObj, nCode, bOn)
{
local nSess;
nSess = FindSessionByTE(CtlObj);
if(bOn)
TESESS[nSess][dPRINTICON] = "1";
else
TESESS[nSess][dPRINTICON] = "0";
SessionIcons_Draw(); // draw Session Icons
dprintln("TE_Print Sess # = ", nSess, " OnOff = ",bOn);
}
TE_ENumLockOn()
This event fires when Num Lock is turned on.
function
TE_ENumLockOn()
{
dprintln("***ENumLockOn");
FrameStatBar.SetText(4,"NUM",SEBT_FLAT);
}
TE_ENumLockOff()
This event fires when Num Lock is turned off.
function
TE_ENumLockOff()
{
dprintln("***ENumLockOff");
FrameStatBar.SetText(4," ",SEBT_FLAT);
}
TE_ECapsLockOn()
This event fires when Caps Lock is turned on.
function
TE_ECapsLockOn()
{
dprintln("***ECapsLockOn");
FrameStatBar.SetText(3,"CAPS",SEBT_FLAT);
}
TE_ECapsLockOff()
This event fires when Caps Lock is turned off.
function
TE_ECapsLockOff()
{
dprintln("***ECapsLockOff");
FrameStatBar.SetText(3," ",SEBT_FLAT);
}
TE_ECapture(bON,iCaptureType,sDevice)
This event fires when a capture operation starts or stops. bON is TRUE when capture is being turned on, FALSE when it is being turned off. iCaptureType is the type of capture that is currently configured. sDevice is the device that is being used for capture.
function
TE_ECapture(oParent,oTE,nCode,bCaptureOn,nCaptureType, sToolTip )
{
local nSession;
nSession = FindSessionByTE(oTE);
if(bCaptureOn)
TESESS[nSession][dCAPTICON] = "1";
else
TESESS[nSession][dCAPTICON] = "0";
if(Props[dTEObj] == TESESS[nSession][dTEObj])
Props[dCAPTICON] = TESESS[nSession][dCAPTICON];
if(nSession != nil)
SessionIcons_Draw(); // draw Session Icons
}
TE_ENextSession()
This event fires when the user has indicated (via a keystroke) that they want to advance to the next session. The actual switching of sessions must be handled by the application.
function
TE_ENextSession(oParent,oTE,nCode)
{
local nSession;
nSession = FindSessionByTE(oTE);
if(nSession != nil) {
if(nSession == TOTSESS-1) {
SwitchSess(0,1);
}
SwitchSess(nSession+1,0);
}
}
TE_EMouseDown(iButton,iShift,x,y)
This event fires when a mouse button is depressed in the control. iButton is the number of the mouse button that is depressed. The left button is 1, the right button is 2, and the middle button is 4. iShift is the status of the shifting keys at the time of the keypress. iShift is a bit field with the least-significant bits corresponding to the SHIFT key (bit 0), the CTRL key (bit 1), and the ALT key (bit 2 ). These bits correspond to the values 1, 2, and 4, respectively. iShift indicates the state of these keys. Some, all, or none of the bits can be set, indicating that some, all, or none of the keys are pressed. For example, if both CTRL and ALT were pressed, the value of iShift would be 6. x and y are the x and y positions of the mouse cursor, relative to the upper left hand corner of the control.
function
TE_EMouseDown(oParent,oTE,nCode,nButton,nFlags,x,y)
{
var ret;
var nCode;
var pmenu;
dprintln("TE_EMouseDown ",nButton, " ",nFlags," ",x," ",y);
if(gTTType == "WC" && nButton == 2) {
dprintln("turning on menu");
if(CSESS[dCONNECT] == "1" || CSESS[dCONNECT] == "3")
pmenu = ResLoadMenu("#401");
else
pmenu = ResLoadMenu("#400");
nCode = TrackPopupMenu(GetSubMenu(pmenu, 0), 0, x, y, Frame);
DestroyMenu(pmenu);
dprintln("ret from pop up menu =%d\n", nCode);
TE_Frame_Command(oParent,oTE,nCode,nCode);
}
}
TE_EMouseUp(iButton,iShift,x,y)
This event fires when a mouse button is released in the control. The arguments are identical to those for MouseDown.
function
TE_EMouseUp(oParent,oTE,nCode,nButton,nFlags,x,y)
{
dprintln("TE_EMouseUp ",nButton, " ",nFlags," ",x," ",y);
}
TE_ELoginStart()
This event fires just before a login or logout scheme is performed.
function
TE_ELoginStart(DlgObj,nMsg,nCode )
{
local tfile;
var nSess = FindSessionByTE(nMsg);
if(nSess == -1)
nSess = 0;
// Activate on start of Logout
if(TESESS[nSess][dLOGINOUTFLAG] == "1") {
tfile = field(TESESS[nSess][434], _val(TESESS[nSess][440]) +1, _asc("|"));
if( exists( tfile) && _val(TESESS[nSess][440]) != -1) {
dprintln("Compile and Run Logout File = ",tfile);
script_run(tfile);
}
if(script_logout()) // Non Zero Return Cancel
nMsg.canceldialog();
TESESS[nSess][dLOGINOUTFLAG] == "0";
}
}
TE_ELoginStop()
This event fires just after a login or logout scheme has been performed.
function
TE_ELoginStop(DlgObj,nMsg,nCode)
{
local tfile;
var nSess = FindSessionByTE(nMsg);
if(nSess == -1)
nSess = 0;
// Activate on end of Login
if(TESESS[nSess][dLOGINOUTFLAG] == "0") {
tfile = field(TESESS[nSess][433], _val(TESESS[nSess][439]) +1, _asc("|"));
if( exists( tfile) && _val(TESESS[nSess][439]) != -1) {
dprintln("Compile and Run Login = ",tfile);
script_run(tfile);
}
script_login();
TESESS[nSess][dLOGINOUTFLAG] = "1";
}
}
Posted in CScript | Comments Off on Scripting Events
Thursday, April 12th, 2007
You can map TERM Script Language commands to a key in any version of TERM. Simply use the SETKEY command. For example, to map the command XMIT “This is a test” to Ctrl-F8, the command is:
setkey cf8 “@@xmit “This is a test””
To map multiple commands to a single key, put them all in a script file. You can then map that file to a key with the DO command. For example, to map the script myscript.cmd to the F5 function key, the command is:
setkey f5 “@@do myscript.cmd”
CScript handles this through the keyboard mapper instead. To map one or more script commands to a key, change the Action field to COMMAND, then enter the commands in one long string. For example:
te.cls();te.displaynl(“Hello World!”);
If you need to map a script to a key, use the CompileFile() command:
CompileFile(“scriptname.cs”);
You can also view this information in a screencast by clicking here.
Posted in Keyboard, Screencast, Scripting | Comments Off on Map Script to Key
|