Free 14-Day Evaluations    
Product Downloads    

Sign in     


DESKTOP MOBILE DOWNLOAD PURCHASE SUPPORT INFO COMPANY
 Home  >>  Support  >>  Knowledge Base

Archive for the 'CScript' Category

Removing Menu Items in TinyTERM 4

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.

Execute Script Command from Host

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

Launch Windows-Based Application from TinyTERM

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

Open Session on a Keystroke

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”));

Scripting Events

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";
    }
    }

  • Bright White Background

    Thursday, April 12th, 2007

    If you set the background color to WHITE, it comes out grey. The TinyTERM background colors (BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN and WHITE) are the “darker” versions of the colors. The bright colors are reserved for the foreground.

    You can make the background bright white in TinyTERM version 4.02 or higher using the CScript scripting language. No other Century Software, Inc., product allows this.

    To write the script, go to TinyTERM’s Tools menu and select Script Editor. The command:

    te.SetRGBEntry(7,16777215);

    will make the WHITE background color bright white. You can change any of TinyTERM’s 16 colors the same way.

    To set the colors to change automatically when you start TinyTERM, save the script you created using the Script Editor’s Save button. Once you’ve saved the script, go to TinyTERM’s Edit menu and select Session Properties. Click the radio button by “Post session start,” then click the Browse button below that. Select the script you created and click OK. Click OK again to close the Session Properties, then save the settings. The next time you open that session, your color settings will load automatically. You will need to do this for each session separately.

    In TinyTERM version 4.9.0 or higher, you can instead edit the .tpx file in use, using any text editor. Locate the line:

    RGBMap7=

    Change it to read:

    RGBMap7=FFFFFF

    This is the hexadecimal value for bright white in the RGB color map. Other colors may be set the same way. You can use http://www.colorpicker.com to get RGB color values if desired.

    Script Debugger

    Thursday, April 12th, 2007

    If you need to debug a script, there are two ways to do it. If you are using TERM Script Language, add the following two commands, to the beginning of your script:

    SET VIEW ON
    SET ECHO ON

    This will cause all script output and error messages to display to the TERM window.

    If you are using CScript from TinyTERM version 4, you will need the Debug Monitor. Running the executable called DBMon32.exe located in the C:\Program Files\Century\TinyTERM\dbmon32 directory. After launching the DBMon32 program, you will need to launch TinyTERM with the -debug switch. For example, you could change your shortcut target to:

    “C:\Program Files\Century\TinyTERM\tt.exe” -debug -PL3 default

    You can also type this in at a command prompt. The quotation marks are required. After doing this, TinyTERM will display all debug information in the Debug Monitor, including script errors.

    Macro Recorder

    Thursday, April 12th, 2007

    If you need to repeat the same keyboard actions repeatedly in TinyTERM 4.x, the CScript scripting language can do it. In TinyTERM 4.30 and higher, you can do this automatically through the Macro Recorder.

    This tool copies the keys you type in, watches for responses from the host system, and records it all to a CScript file. To use the Macro Recorder:

    1. On the Tools menu, click Macro Recorder.
    2. In the list box, type a name for the macro. If you accept the default name, the ## signs will be replaced by numbers; e.g., KeyMac00.cs. Every new macro will be assigned a new number, one higher than the last macro created.
    3. Click the Record button to begin recording.
    4. Type the commands and other keystrokes you wish to record. You must hit Enter at least once, or the macro will not be recorded.
    5. Click the Pause button to temporarily halt recording and to start recording again later.
    6. Click the Stop button to end recording and write the macro file.

    There are two ways to execute the resulting macro:

    1. Open the Macro Recorder. In the list box, type the name of the macro. Click the Play button.
    2. Click on Tools | Execute Script File. Select the macro from the list of scripts, then click the Open button.

    If the macro isn’t doing quite what you expected, you can record a new macro or edit the existing one. To edit, go to the Tools menu and select Script Editor. Click the Open button to select your macro, then edit it as you need to.

    You can also view a screencast that demonstrates this process. For more information on script commands, see the TinyTERM Programmers Reference Manual. You can also contact our Support department for help writing and debugging macros and other CScript files.

    CR 130, added in TinyTERM 4.30
    CR 724, not enabled in TN3270 or TN5250
    CR 800, must hit Enter

    Hostmode

    Thursday, April 12th, 2007

    All versions of TERM for UNIX, Windows or DOS include a hostmode utility that’s accessed by typing term -x, term -1x or term-2x at the command prompt. TinyTERM Application Developer version 3.3 includes a similar feature accessed through the Action menu.

    Hostmode capability was added to TinyTERM 4.x in version 4.30 through the hostmode.cs script. If your copy of TinyTERM doesn’t have hostmode.cs, you can download it here. The download version includes a utility that creates the user data file. Download the file and save it to your TinyTERM install directory, which is usually C:\Program Files\Century\TinyTERM.

    To use hostmode.cs, your PC needs a modem, so you can set it up to accept an incoming call. For best results, the modem must accept typed commands. If it has a Winmodem, a modem specifically designed to work only with Microsoft Windows, the hostmode.cs script won’t be able to communicate with it properly, and the script will fail.

    Nex, you’ll set up a connection on the controlling PC. To do this, open TinyTERM. Click on the Edit menu and select Session Properties.

    In the Session Properties dialog, change the connection type to RS232 (Serial). Under the Available devices, select the COM port your modem is on. Then click the Setup button next to that line to set the connection speed. You probably won’t need to change anything else in that dialog.

    Once you’ve set up the connection, click OK until the Session Properties dialog closes. Go to the File menu and select Save Session or Save As to save the settings.

    Next you’ll need to edit hostmode.cs. To do this, Go to TinyTERM’s Tools menu and select Script Editor. In the Script Editor, click the Open button and select hostmode.cs. It will will open in a separate Notepad window.

    About 25 lines down you’ll see a section labeled, “Variable declaration and initial values.” Each line after that has a variable setting and a description. These need to be changed to match your PC’s requirements.

    The settings in this section of the script are fairly common and may work for your modem. But then again, they may not. If they don’t work, try to get the correct settings from your modem documentation. Most modems come with a manual or other documentation that lists the best values for these functions. If you don’t seem to have the information, gather all the documentation you can for your modem and call or email our Technical Support for assistance.

    The other values in this section are mainly personal preference. If you don’t like the setting, feel free to change it. Just remember to keep the quotation marks in place, and be sure the upload and download directories you choose exist on the PC.

    Once that’s done, close Notepad and save the changes. You can then click the Run button to start hostmode. If everything has been set up properly, you’ll see messages telling you that hostmode is running.

    To stop hostmode, wait until no one is currently dialed in, then type Ctrl-C to exit the script. You won’t need to make further changes, so to start it again, go to TinyTERM’s Tools menu and select Execute Script File. You can run hostmode.cs from there.

    CR 32

    Using Older Configuration Files

    Thursday, April 12th, 2007

    When upgrading to a newer version of TERM or TinyTERM, you can still use the older configuration files, provided they have the same extension. For example, any version of TinyTERM for Windows that uses a .tap file can use them interchangeably with earlier or later versions of TinyTERM.

    If the extension for the connection file has changed, such as from .con to .tap, you will need to recreate the file, or convert the older file. TinyTERM 3.x and TERM 7.x include a utility CONVTAP.EXE. This will convert a .con file to .tap format. TinyTERM 4.x includes a CScript named TAPtoTPX.cs that will convert a .tap file to .tpx format. But there is no utility to go from .con format to .tpx.

      Copyright © 2024 Century Software, Inc. All Rights Reserved999 TERMS OF USE PRIVACY POLICY EULA