The text of a manual · part 24 of 25
Attended Workstations (Catalog Nos. 2708-DH5B2L & -DH5B4L) (Series B) User Manual: M - Application Library Subroutines
Pages 168 to 178 of 186, from Attended Workstations (Catalog Nos. 2708-DH5B2L & -DH5B4L) (Series B) User Manual
The original document is the PDF (513 KB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Allen-Bradley 2708
Page 168
Appendix
A–B
M
Application Library Subroutines In ENV.BAS and ENVPC.BAS OpenLINX . . . . . . Opens all devices to be used by low level I/O routines TestEvent% . . . . . . Tests for an event Read Event% . . . . Waits for an event Send . . . . . . . . . . . Sends a record directly to the host SendQue . . . . . . . . Sends a record indirectly to the host through the queue SetLINE . . . . . . . . Sets the state of the control line SetLED . . . . . . . . . Turns a workstation keyboard LED on or off SendCom . . . . . . . Sends a record to the comm line Set DTR . . . . . . . . Sets the state of Data Terminal Ready SetRTS . . . . . . . . . Sets the state of Request To Send for a comm port GetDSR% . . . . . . . Gets Data Set Ready status for a comm port PENDING% . . . . . TRUE if Send will result in a pause. MEMFULL% . . . . TRUE if less than 1024 bytes remain in RAM ONLINE% . . . . . . TRUE when ONLINE to the network GetDATE$ . . . . . . Translates DATE$ into standard form (MM/DD/YYYY) GetTIME$ . . . . . . Translates TIME$ into standard form (HH:MM:SS) In READ.BAS CL1 . . . . . . . . . . . . Clears the top line of the display and homes cursor CL2 . . . . . . . . . . . . Clears line 2 and left justifies cursor PC1 . . . . . . . . . . . . Prints a string centered on line 1 PC2 . . . . . . . . . . . . Prints a string centered on line 2 ReadFlush . . . . . . . Flushes the keyboard buffer ReadStrField% . . . Edit a string field on the display ReadStr% . . . . . . . Simple edit a string on the screen ReadNumSTR% . . Simple edit of string of numeric characters ReadPassword% . . Inputs a password from the keyboard ReadYN% . . . . . . . Wait for a YES/NO response from user ReadInt% . . . . . . . Input an integer value from the keyboard ReadReal% . . . . . . Input a real value from the keyboard ReadLong% . . . . . Input a long value from the keyboard In MENU.BAS Menu% . . . . . . . . . Displays a menu and waits for a selection LogE! . . . . . . . . . . Returns the natural log of a value Log10! . . . . . . . . . Returns the base 10 log a value Exponential! . . . . . Returns e to the x Power! . . . . . . . . . Relturns x to the power of y SquareRoot! . . . . . Returns the square root of x CubeRoot! . . . . . . Returns the cube root of x M–1
Page 169
Appendix M Application Library Subroutines
In TRIG.BAS FullArcTangent! . . Returns arc tangent using numerator and denominator ArcTangent! . . . . . Relturns the inverse tangent in radians ArcSine! . . . . . . . . Returns the inverse sine in radians ArcCosine! . . . . . . Returns the inverse cosine in radians Tangent! . . . . . . . . Returns the tangent of an angle in radians Sine! . . . . . . . . . . . Returns the sine of an angle in radians Cosine! . . . . . . . . . Returns the cosine of an angle in radians In HYP.BAS TangentH . . . . . . . Hyperbolic tangent SineH . . . . . . . . . . Hyperbolic sine CosineH . . . . . . . . Hyperbolic cosine ArcTangentH . . . . Returns inverse hyperbolic tangent ArcSineH . . . . . . . Relturns inverse hyperbolic cosine for x = 0 ArcCosineH . . . . . Returns inverse hyperbolic cosine for principal values OpenLINX
Opens all devices to be used by low level I/O routines.
This MUST be called before any of the Event or Read routines. This performs the actual BASIC OPEN statements for all of the devices which are accessed by the low level I/O. Note: The global constant PcMode will be TRUE if th is program is running using EnvPC.BAS instead of Env.BAS. You may use this for any operations which are not fully emulated by the EnvPC environment. This also establishes the global environment variables. DSPWIDTH% = 40 or 16 depending on the type of workstation TERMNUM% = The current terminal number TERMTYPE$ = “NORML”, “MASTR”, etc OpenLINX SUB OpenLINX
TestEvent%
M–2
Tests for a low level event returns 0 when no event has occurred. Events are either keys read from the workstation keyboard, or special codes. Special codes are always negative, although some special keys also return negative codes. See OpenLINX for initialization information.
Page 170
Appendix M Application Library Subroutines
The most important events are: TimeoutEvent . . . . The input timer has expired NetEvent . . . . . . . . Read from network has occurred ComEvent . . . . . . . Read from the main comm port AuxEvent . . . . . . . Read from the aux comm port When ComEvent or AuxEvent has occurred, InCom$ contains the LINE INPUT format line which was read from the comm line. When NetEvent has occurred, InNet$ contains the record from the host. The events which you want to test for are indicated by the “mask” parameter. Each device which you want tested MUST have a bit set in the mask. Bits are set by building a mask using the constants: KbdMask, TimeoutMask, BadgeMask, NetMask, ComMask, AuxMask, and SensorMask. To simplify matters, some special mask values are also allowed. These are: 0 = Read from keyboard only 1 = Read from keyboard with timeout (see ReadEvent%) 2 = Read from keyboard and SLOT, etc. with timeout Note: Timeouts only apply to reads which wait for an event. TestEvent% never waits. See ReadEvent% for more info. e = TestEvent%
( mask% )
FUNCTION TestEvent% ( mask% )
SaveEvent
Saves the previous event to allow it to happen again.
Saves the event which has just occurred from TestEvent%. The very next TestEvent% will return this event code. SaveEvent eventcode% SUB SaveEvent ( e% )
ReadEvent%
Waits for a low level event.
Waits for an event to occur. The event(s) to wait for are specified in the same manner as TestEvent%. For timeouts set the global variable TIMEOUT% to the number of 1/100 second intervals you want to wait before a TimeoutEvent is returned. The value of TIMEOUT% is not modified by %. e = % ( mask ); FUNCTION % ( mask% )
M–3
Page 171
Appendix M Application Library Subroutines
SetDTR
Sets the state of Data Terminal Ready.
SetRTS
Sets the state of Request To Send for a comm port.
Set state = TRUE to turn DTR or RTS on. You may examine the global variables RTS1%, DTR1%, RTS2%, and DTR2% to get the current state. n% is 1 for COM and 2 for AUX. SetDTR n%, state% SetRTS n%, state% SUB SetDTR ( n%, s% ) SUB SetRTS ( n%, s% )
GetDSR%
Gets Data Ready status for a comm port.
A TRUE is returned if DSR is ON. n% is 1 for COM and 2 for AUX. state = GetDSR%(n%) FUNCTION etDSR% ( n% )
SendCom
Sends a record to a comm line.
A string is sent to the comm line. The string is sent exactly as is, so append CR or CR and LF if you are sending a line. n% is 1 for COM and 2 for AUX. Note that COMOPEN% must be true for a send to COM to work. COMOPEN% is true only if the TERMTYPE% is TypeNormal.
SendCom n%, s$ SUB SendCom ( n%, s$ + CHR$(CR) )
ONLINE%
TRUE if the workstation is online. IF ONLINE% THEN . . .
MEMFULL%
TRUE if less than 1024 bytes remain in RAM.
This should be checked before any SendQue or outputs to the RAM files to prevent memory full. IF MEMFULL% THEN . . .
M–4
Page 172
Appendix M Application Library Subroutines
PENDING%
TRUE if Send will result in a pause.
This should be checked before any Send, to prevent pauses in execution. WHILE PENDING% ... WEND
Send
Sends a record directly to the host.
A string is sent to the host from this terminal. You should test ONLINE% and PENDING% if you don’t want this to pause. Send
SendQue s$
Sends a record indirectly to the host through the que.
A string is placed into the network queue. The record will in turn be sent to the host as soon as possible. SendQue has a lower priority than Send, and will buffer records even when NOT ONLINE. This subroutine uses the “Host” device, NOT the “Que” device. See “Host Device” discussion. Pause will occur if the unit was not ONLINE% and MEMFULL%. SendQue
SetLED s$
Turns a workstation keyboard LED on or off.
A workstation has up to 10 LEDs. The LEDs are numbered 1 to 10. state% should be TRUE for ON and FALSE for OFF. SetLED
GetTIME$ n%, state%
Translates TIME$ into standard form (HH:MM:SS).
In A-B VBASIC TIME$ is in the form hhmmsshh. This routine drops the hundreth seconds and puts colons between hours/minutes and minute/seconds. GetTIME$
GetDATE$
Translates DATE$ into standard form (MM/DD/YYYY).
In A-B VBASIC DATE$ is in the form yymmddx. This routine ignores the day (the x). GetDATE$
M–5
Page 173
Appendix M Application Library Subroutines
Note: In EnvPC, dashes are returned, not slashes (MM-DD-YYYY). CL1
Clears the top line of the display and homes cursor.
CL2
Clears line 2 and left justifies cursor. SUB CL1 SUB CL2
PC1
Prints a string centered on line 1.
PC2
Prints a string centered on line 2. PC1 s$ SUB PC1 ( s$ ) SUB PC2 ( s$ )
ReadFlush
Flushes the keyboard buffer.
This clears the keyboard buffer of any pending keystrokes. ReadFlush SUB ReadFlush
ReadStrField%
Input a string on the display
The string$ contents are placed on the screen and may be edited by the user. This default may be inhibited using NODEFAULT. The attr% is made by adding the following: AUTOEXIT . . . . . Causes the field to be auto exited BLANKPAD . . . . . Selects blank padding instead of underscores SECURE . . . . . . . . The field is displayed as asterisks NOEDIT . . . . . . . . Displayed but cannot be edited NOCLEAR . . . . . . Inhibits auto clear on input NOCURSOR . . . . Inhibits display of cursor during edit FORMEXIT . . . . . Allow arrows to exit the field entry NODEFAULT . . . . Do not use the default value in the string USETABLE . . . . . Use CHARTABLE$ to restrict legal characters The fieldlength% is in characters. The startingchar% specifies the offset from the beginning of the field at which editing is to start, this begins at 0. Note that the global EXITOFFSET% is set to the cursor position at exit. These may be used to restart a read which was interrupted by some event.
M–6
Page 174
Appendix M Application Library Subroutines
The global MODIFIED% is TRUE when the string was changed in any way. The strlength is the maximum number of characters to allow in the string (not including the terminal null). This must be at least fieldlength% characters long. The return value “e” is an event code. This is 0 on a normal return (operator pressed CR). The devices which are active are defined by the global variable GLOBALMASK% which is in the same format as the mask% used by % and TestEvent%. The field will start at the current cursor location. The cursor is left at its starting locationi when ReadStrField exits. e = ReadStrField%( attr%, fldlen%, strtchar%, string$, stringlen% ) FUNCTION ReadStrField% ( attr%, flength%, strpos%, s$, slen% )
ReadStr%
Edit a string on the screen.
Thhis is a simplified version of ReadStrField% that does not have as many parameters. Any attributes should be in the GLOBALATTR% variable. Don’t forget to set GLOBALMASK% to the devices which can terminate the read. Make sure you include KbdMask. See TestEvent% for more info. e = ReadStr ( length%, s$ ) FUNCTION ReadStr% ( n%, s$ )
An example of reading from the keyboard is as follows: e = ReadStr(Length%, s$) IF e = BadgeEvent THEN . . s$ = InBuf$ END IF
ReadNumStr%
Edit a numeric string on the screen.
The string which is edited may contain only 0 through 9. Any attributes should be in the GLOBALATTR% variable. e = ReadNumStr ( length%, s$ ) FUNCTION ReadNumStr% ( n%, s$ )
ReadYN%
Wait for a YES/NO response from user.
Returns TRUE or FALSE depending on the user’s response. EXITKEY% is set if you really need the event value. Nothing is displayed; this just waits for Enter, Clear, or a Y or N. IF ReadYN% ( default% ) THEN . . . FUNCTION ReadYN% ( defv% )
M–7
Page 175
Appendix M Application Library Subroutines
ReadPassword% Inputs a password from the keyboard. e = ReadPassword% ( length%, string$ ) ; FUNCTION ReadPassword% ( n%, s$ )
ReadInt%
Input an integer value from the keyboard.
To suppress display of the default value, use a negative length. e = ReadInt% ( length%, int% ) FUNCTION ReadInt% ( n%, v% )
ReadLong%
Input a long value from the keyboard.
To suppress display of the default value, use a negative length. e = ReadLong% ( length%, long& ) FUNCTION ReadLong% ( n%, v& )
ReadReal%
Input a real value from the keyboard.
The precision specifies how many decimal points to display. It does not affect the precision of the value input by the user. Use a negative length to suppress the default value. This only8 handles floating point values. NOT scientific forms. e = ReadReal% ( length%, precision%, real! ) ; FUNCTION ReadReal% ( n%, p%, v! )
Menu%
Displays a menu and waits for a selection.
A menu$ is provided which is used to format a menu on the two lines of the workstation display. The operator can select a menu entry by using 1 of 2 methods; these are: 1. Press a LETTER or NUMBER which corresponds to the first UPPER CASE letter or NUMBER of an entry. 2. Using the cursor keys to move to the item to be selected, then pressing Enter. Regardless of the selection method used, Menu% will always return an event code of 1 through 10 for the item which was selected. If the operator pressed Clear or Exit, a functioin key, or an event occurred which was enabled by GLOBALMASK%, then these codes will be returned instead of 1 through 10. See Env.BAS for information on use of GLOBALMASK%.
M–8
Page 176
Appendix M Application Library Subroutines
The menu string is a string in which each menu entry is preceded by a “ | ” (vertical bar). Thus a menu$ such as: “Payment Type: | Mastercard | Visa | Amex \ “ + ” | Other | Cash“ has 5 entries; “Mastercard” is the 1st entry and may also be selected by pressing M. “Cash” is the 4th entry and may also be selected by pressing C. Note the use of “ \ ” to start a new line (the fact that the string was made by adding two strings together cannot be detected by Menu%). The actual menu displayed will look like: Payment Type: <Mastercard> Visa Other
Amex Cash
The startingitem% is a value of 1 to 10, to indicate wh ich entry should be selected first. Note that the global EXITOFFSET% is set to the entry which was selected at exit. e = Menu% ( startingitem%, menu$ ) FUNCTION Menu% ( sitem%, m$ )
LogE!
Returns the natural log of a value. x! = LogE! ( x! ) FUNCTION LogE! ( x )
Log10!
Returns the base 10 log of a value. x! – Log10! ( x! ) FUNCTION Log10! ( x )
Exponential!
Returns e to the x x! = Exponential! ( x! ) FUNCTION Exponential! ( x )
Power!
Returns x to the power of y. z! = Power! ( x!, y! ) FUNCTION Powerl! ( x, y )
CubeRoot!
Returns the cube root of x. x! = CubeRoot! ( x! ) FUNCTION CubeRoot! ( x )
SquareRoot!
Returns the square root of x. x! = SquareRoot! ( x! ) FUNCTION SquareRoot! ( x ) M–9
Page 177
Appendix M Application Library Subroutines
FullArcTangent!
Returns arc tangent using numerator and denominator.
This is similar to ArcTangent (numerator/denominator) except it avoids the divide by 0 problems and sign problems of the normal ArcTangent function. The angle is returned in radians. Example: Usually the numerator and denominator are y and x respectively. When x is zero, y/x is undefined, but the FullArdcTangent of y,x is pi/2 or pi/2 depending on the sign of y. x! = FullArcTangent! ( numerator!, denominator! ) FUNCTION FullcTangent! ( num, den )
ArcTangent!
Returns the inverse tangent in radians. angle! = ArcTangent! ( y!/x! ) FUNCTION ArcTangent! ( x )
ArcSine!
Returns the inverse sine in radians. angle! = ArcSine! ( x! ) FUNCTION ArcSine! ( x1 )
ArcCosine!
Returns the inverse cosine in radians. angle! = ArcCosine! ( x! ) FUNCTION ArcCosine! ( x )
Tangent!
Returns the tangent of an angle in radians. x! = Tangent! ( angle! ) FUNCTION Tangent! ( x1 )
Sine!
Returns the sine of an angle in radians. y! = Sine! ( angle! ) FUNCTION Sine! ( x1 )
Cosine!
Returns the cosine of an angle in radians. x! = Cosine! ( angle! ) FUNCTION Cosine! ( x )
TangentH!
Returns the hyperbolic tangent. y! = TangentH! ( x! ) FUNCTION TangentH! ( x )
M–10
Page 178
Appendix M Application Library Subroutines
SineH!
Returns the hyperbolic sine. y! = SineH! ( x! ) FUNCTION SineH! ( x )
CosineH!
Returns the hyperbolic cosine. y! = CosineH! ( x! ) FUNCTION CosineH! ( x )
ArcTangentH!
Returns the inverse hyperbolic tangent. y! = ArcTangentH! ( x! ) FUNCTION ArcTangentH! ( x )
ArcSineH!
Returns the inverse hyperbolic cosine for x = 0. y! = ArcSineH! ( x! ) FUNCTION ArcSineH! ( x )
ArcCosineH!
Returns the inverse hyperbolic cosine for principal values. y! = ArcCosineH! ( x! ) FUNCTION ArcCosineH! ( x )
M–11