Index Manuals FANUC Robotics SYSTEM R-30iA and R-30iB Controller. KAREL Reference Manual (MARRC75KR07091E Rev D)
|
|
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
BEGIN
--- GEN_HEX
-----------------------------------------------------------------------------
----
Section 4-A: Connect timer, set uframe, call routines
-----------------------------------------------------------------------------
clock = 0
-- Initialize clock value to zero
CONNECT TIMER TO clock
-- Connect the timer
WRITE (’Moving to the center of the HEXAGON’,CR) -- update user of process
r_hex_center
-- position the face plate of robot.
WRITE (’Calculating the sides of HEXAGON’,CR)
-- update user
r_calc_hex
-- Calculate the hexagon points
-----------------------------------------------------------------------------
----
Section 4-B: Move on sides of hexagon
-----------------------------------------------------------------------------
WRITE (’Moving along the sides of the Hexagon’,CR) -- Update user
t_start = clock
-- Record the time before motion begins
FOR p_indx = 1 TO 6 DO
-- Verify that the position is reachable
CHECK_EPOS ((p_xyzwpr[p_indx]), $UFRAME, $UTOOL, status)
IF (status <> 0) THEN
WRITE (’Unable to move to p_xyzwpr[’, p_indx,’]’,CR);
ELSE
SET_POS_REG(1, p_xyzwpr[p_index], status)
movl_to_pr
-- Call TP program to move to PR[1]
-- Move to each vertex of hexagon
ENDIF
ENDFOR
SET_POS_REG(1, p_xyzwpr[1], status)
movl_to_pr
-- Call TP program to move to PR[1]
-- Move back to first vertex of hexagon
tmp_xyz = p_cntr
SET_POS_REG(1, tmp_xyz, status)
movl_to_pr
-- Move TCP in a straight
-- line to the center position
t_end = clock
-- Record ending time
WRITE(’Total motion time = ’,t_end-t_start,CR) --Display the total time
for
-- motion.
-- NOTE that the total was
-- computed in the WRITE
-- statement.
END GEN_HEX
B-53
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
B.9
USING THE FILE AND DEVICE BUILT-INS
This program demonstrates how to use the File and Device built-ins. This program FORMATS and
MOUNTS the RAM disk. Then copies files from the FLPY: device to RD:. If the RAM disk gets full
the RAM disk size is increased and reformatted. This program continues until either all the files are
copied successfully, or the built-in operations fail.
File and Device Built-ins Program - Overview
------------------------------------------------------------------------------
----
FILE_EX.Kl
------------------------------------------------------------------------------
----
Section 0: Detail about FILE_EX.kl
------------------------------------------------------------------------------
----
Elements of KAREL Language Covered:
In Section:
----
Action:
----
Clauses:
----
FROM
Sec 3
----
Conditions:
----
Data types:
----
BOOLEAN
Sec
2
----
INTEGER
Sec
2
----
STRING
Sec
2
----
Directives:
----
COMMENT
Sec
1
----
NOLOCKGROUP
Sec
1
----
Built-in Functions & Procedures:
----
CNV_TIME_STR
Sec
4-A
----
COPY_FILE
Sec
4-B
----
DISMOUNT_DEV
Sec
4-B
----
FORMAT_DEV
Sec
4-B
----
GET_TIME
Sec
4-A
----
MOUNT_DEV
Sec
4-B
----
PURGE_DEV
Sec
4-B
----
SUB_STR
Sec
4-A
----
Statements:
----
IF...THEN...ELSE...ENDIF
Sec
4-B
----
REPEAT...UNTIL
Sec
4-A
----
ROUTINE
Sec
3
----
SELECT...ENDSELECT
Sec
4-B
----
WRITE
Sec
4-A,B
File and Device Built-ins Program - Overview Continued
----
Reserve Words:
----
BEGIN
Sec 4
B-54
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
----
CONST
Sec 2
----
CR
Sec 4-A,B
----
END
Sec 4-B
----
PROGRAM
Sec 4
----
VAR
Sec 2
----
Devices Used:
----
FLPY
Sec 4-B
----
MF3
Sec 4-B
----
RD
Sec 4-B
----
FR
Sec 4-B
File and Device Built-ins Program - Declaration Section, Declare Routines
------------------------------------------------------------------------------
----
Section 1: Program and Environment Declaration
------------------------------------------------------------------------------
PROGRAM FILE_EX
%nolockgroup
%comment = ’COPY FILES’
------------------------------------------------------------------------------
----
Section 2: Variable Declaration
------------------------------------------------------------------------------
CONST
SUCCESS
= 0
-- Success status from builtins
FINISHED
= TRUE
-- Finished Copy
TRY_AGAIN
= FALSE
-- Try to copy again
RD_FULL
= 85020
-- RAM disk full
NOT_MOUNT
= 85005
-- Device not mounted
FR_FULL
= 85001
-- FROM disk is full
MNT_RD
= 85004
-- RAM disk must be mounted
--Refer to
FANUC Robotics Controller KAREL
Setup and Operations Manual for an Error Code listing
VAR
time_int
: INTEGER
time_str
: STRING[30]
status
: INTEGER
cpy_stat
: BOOLEAN
to_dev
: STRING[5]
------------------------------------------------------------------------------
----
Section 3: Routine Declaration
------------------------------------------------------------------------------
ROUTINE tp_cls FROM ROUT_EX
------------------------------------------------------------------------------
----
Section 4: Main program
B-55
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
------------------------------------------------------------------------------
BEGIN
-- FILE_EX
tp_cls
-- from rout_ex.kl
------------------------------------------------------------------------------
----
Section 4-A: Get Time and FORMAT ramdisk with date as volume name
------------------------------------------------------------------------------
GET_TIME(time_int)
-- Get the system time
CNV_TIME_STR(time_int, time_str)
-- Convert the INTEGER time
-- to readable format
WRITE (’Today is ’, SUB_STR(time_str, 2,8),CR)
-- Display the date part
WRITE (’Time is ’, SUB_STR(time_str, 11,5),CR)
-- Display the time part
File and Device Built-ins Program - Mount and Copy to RAM Disk
-----------------------------------------------------------------------------
----
Section 4-B: Mount RAMDISK and start copying from FLPY to
MF3:
-----------------------------------------------------------------------------
to_dev = ’MF3:’
REPEAT
-- Until all files have been copied
cpy_stat = FINISHED
WRITE(’COPYing
’,cr)
-- Copy the files from FLPY: to to_dev and overwrite the file if it
-- already exists.
COPY_FILE(’FLPY:*.kl’, to_dev, TRUE, FALSE, status)
SELECT (status) OF
CASE (RD_FULL):
-- RAM disk is full
-- Dismount and re-size the RAM-DISK
WRITE (’DISMOUNTing RD:
’,cr)
DISMOUNT_DEV(’RD:’, status)
-- Verify DISMOUNT was successful or that
-- the device was not already mounted
IF (status = SUCCESS) OR (status = NOT_MOUNT) THEN
-- Increase the size of RD:
WRITE(’Increasing RD: size...’,cr)
$FILE_MAXSEC = ROUND($FILE_MAXSEC * 1.2)
-- Increase the RAM disk size
-- Format the RAM-DISK
WRITE(’FORMATTING RD:
’,cr)
FORMAT_DEV(’RD:’,’’ ,FALSE, status) -- Format the RAM disk
IF (status <> SUCCESS) THEN
WRITE (’FORMAT of RD: failed, status:’, status,CR)
WRITE (’Copy incomplete’,cr)
ELSE
cpy_stat = TRY_AGAIN
ENDIF
B-56
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
WRITE(’MOUNTing RD:
’,cr)
MOUNT_DEV (’RD:’, status)
IF (status <> SUCCESS) THEN
WRITE (’MOUNTing of RD: failed, status:’, status,CR)
WRITE (’Copy incomplete’,cr)
ELSE
cpy_stat = TRY_AGAIN
ENDIF
ELSE
WRITE (’DISMOUNT of RD: failed, status:’, status,cr)
WRITE (’Copy incomplete’,cr)
ENDIF
File and Device Built-ins Program - Mount and Copy to RAM Disk Continued
CASE (FR_FULL):
-- FROM disk is full
WRITE (’FROM disk is full’,CR, ’PURGING FROM
’, CR)
PURGE_DEV (’FR:’, status)
-- Purge the FROM
IF (status <> SUCCESS) THEN
WRITE (’PURGE of FROM failed, status:’, status, CR)
WRITE (’Copy incomplete’, CR)
ELSE
cpy_stat = TRY_AGAIN
ENDIF
CASE (NOT_MOUNT, MNT_RD):
-- Device is not mounted
WRITE (’MOUNTing ’,to_dev,’
’,CR)
MOUNT_DEV(to_dev, status)
IF (status <> SUCCESS) THEN
WRITE (’MOUNTing of ’,to_dev,’: failed, status:’, status,
CR)
WRITE (’Copy incomplete’, CR)
ELSE
cpy_stat = TRY_AGAIN
ENDIF
CASE (SUCCESS):
WRITE (’Copy completed successfully!’,CR)
ELSE:
WRITE (’Copy failed, status:’, status,CR)
ENDSELECT
UNTIL (cpy_stat = FINISHED)
END file_ex
B-57
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
B.10
USING DYNAMIC DISPLAY BUILT-INS
This program demonstrates how to use the dynamic display built-ins. This program initiates the
dynamic display of various data types. It then executes another task, CHG_DATA, which changes
the values of these variables.
Before exiting this program the dynamic displays are cancelled and the other task is aborted.
If DYN_DISP is aborted, it will set a variable which CHG_DATA detects. This ensures that
CHG_DATA cannot continue executing once DYN_DISP is aborted.
Using Dynamic Display Built-ins - Overview
-----------------------------------------------------------------------------
----
DYN_DISP.Kl
-----------------------------------------------------------------------------
----
Section 0: Detail about DYN_DISP.KL
-----------------------------------------------------------------------------
---- Elements of KAREL Language Covered:
In Section:
----
Actions:
----
Clauses:
----
FROM
Sec 3-C
----
IN CMOS
Sec 2
----
WHEN
Sec 4
----
Conditions:
----
ABORT
Sec 4
----
Data types:
----
BOOLEAN
Sec 2
----
INTEGER
Sec 2
----
REAL
Sec 2
----
STRING
Sec 2
----
Directives:
----
ALPHABETIZE
Sec 1
----
COMMENT
Sec 1
----
NOLOCKGROUP
Sec 1
Using Dynamic Display Built-ins - Overview Continued
----
Built-in Functions & Procedures:
----
ABORT_TASK
Sec 4-C
----
CNC_DYN_DISI
Sec 4-C
----
CNC_DYN_DISR
Sec 4-C
----
CNC_DYN_DISB
Sec 4-C
----
CNC_DYN_DISE
Sec 4-C
----
CNC_DYN_DISP
Sec 4-C
----
CNC_DYN_DISS
Sec 4-C
----
INI_DYN_DISI
Sec 3-A, 4-A
B-58
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
----
INI_DYN_DISR
Sec
3-B, 4-A
----
INI_DYN_DISB
Sec
3-C, 4-A
----
INI_DYN_DISE
Sec
3-D, 4-A
----
INI_DYN_DISP
Sec
3-E, 4-A
----
INI_DYN_DISS
Sec
3-F, 4-A
----
LOAD_STATUS
Sec
4-B
----
LOAD
Sec
4-B
----
RUN_TASK
Sec
4-B
----
----
Statements:
----
CONDITION...ENDCONDITION
Sec
4
----
IF...THEN...ENDIF
Sec
4-A,B,C
----
READ
Sec
4-C
----
ROUTINE
Sec
3-A,B,C
----
WRITE
Sec
4-A,B,C
----
----
Reserve Words:
----
BEGIN
Sec
3-A,B; 4
----
CR
Sec
4-A
----
CONST
Sec
2
----
END
Sec
3-A,B; 4-C
----
PROGRAM
Sec
4
----
VAR
Sec
2
----
Predefined File Variables:
----
TPPROMPT
Sec
4-B,C
----
Predefined Windows:
----
T_FU
Sec
3-A,B
Using Dynamic Display Built-ins - Declaration Section
-----------------------------------------------------------------------------
----
Section 1: Program and Environment Declaration
-----------------------------------------------------------------------------
PROGRAM DYN_DISP
%nolockgroup
%comment = ’Dynamic Disp’
%alphabetize
%INCLUDE KLIOTYPS
-----------------------------------------------------------------------------
----
Section 2: Variable Declaration
-----------------------------------------------------------------------------
CONST
cc_success
= 0
-- Success status
cc_clear_win
= 128
-- Clear window
cc_clear_eol
= 129
-- Clear to end of line
cc_clear_eow
= 130
-- Clear to end of window
B-59
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
CH_ABORT
=
1
-- Condition Handler to detect when program aborts
VAR
Int_wind
:STRING[10]
Rel_wind
:STRING[10]
Field_Width
:INTEGER
Attr_Mask
:INTEGER
Char_Size
:INTEGER
Row
:INTEGER
Col
:INTEGER
Interval
:INTEGER
Buffer_Size
:INTEGER
Format
:STRING[7]
bool_names
:ARRAY[2] OF STRING[10]
enum_names
:ARRAY[4] OF STRING[10]
pval_names
:ARRAY[2] OF STRING[10]
bool1 IN CMOS
:BOOLEAN
enum1 IN CMOS
:INTEGER
port_type
:INTEGER
port_no
:INTEGER
Str1
IN CMOS
:STRING[10]
Int1
IN CMOS
:INTEGER
-- Using IN CMOS will create the variables
Real1 IN CMOS
:REAL
-- in CMOS RAM, which is permanent memory.
status
:INTEGER
loaded,
initialized
:BOOLEAN
dynd_abrt
:BOOLEAN
-- Set to true when program aborts.
Using Dynamic Display Built-ins - Declare Routines
-----------------------------------------------------------------------------
----
Section 3: Routine Declaration
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
----
Section 3-A: SET_INT Declaration
----
Set all the input parameters for the INI_DYN_DISI call.
-----------------------------------------------------------------------------
ROUTINE Set_Int
Begin
-- Valid predefined windows are described in
-- Chapter 7.9.1, "USER MENU on the Teach Pendant
--
Error Line
--> ’ERR’
1
line
--
Status Line
--> ’T_ST’
3
lines
--
Display Window
--> ’T_FU’
10 lines
--
Prompt Line
--> ’T_PR’
1
line
--
Function Key
--> ’T_FK’
1
line
Int_Wind
= ’T_FU’
-- Use the predefined display window
B-60
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
Field_Width
= 0
-- Use the minimum width necessary
Attr_Mask
= 1 OR 4
-- BOLD and UNDERLINED
Char_Size
= 0
-- Normal
Row
= 1
-- Specify the location within ’T_FU’
Col
= 16
--
to dynamically displayed
Interval
= 250
-- 250ms between updates
Buffer_Size
= 10
-- Minimum value required.
Format
= ’%-8d’
-- 8 character minimum field width
--- With this specification the INTEGER will be displayed as follows:
---
--------
---
|xxxxxxxx|
---
--------
---
Where the integer value will be left justified.
---
The x’s will be the integer value unless the integer value is
---
less then 8 characters, then the right side will be blanks up to
---
a total 8 characters. If the integer value is greater than the 8
---
characters the width is dynamically increased to display the whole
---
integer value. The INTEGER value will also be bold and underlined.
End Set_Int
Using Dynamic Display Built-ins - Declare Routines Continued
-----------------------------------------------------------------------------
----
Section 3-B: SET_REAL Declaration
----
Set all the input parameters for the INI_DYN_DISR call.
-----------------------------------------------------------------------------
ROUTINE Set_Real
Begin
Rel_Wind
= ’T_FU’
-- Use the predefined display window
Field_Width
= 10
-- Maximum width of display.
Attr_Mask
= 2 OR 8
-- blinking and reverse video
Char_Size
= 0
-- Normal
Row
= 2
-- Specify the location within ’TFU’
Col
= 16
--
to dynamically display
Interval
= 200
-- 200ms between update
Buffer_Size
= 10
-- Minimum value required.
Format
= ’%2.2f’
--- With the format and field_width specification the REAL will be
--- displayed as follows:
---
----------
---
|xxxx.xx
|
---
----------
---
Where the real value will be left justified.
---
There will always be two digits after the decimal point.
---
A maximum width of 10 will be used.
---
If the real value is less then 10 characters the right side will be
B-61
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
---
padded with blanks up to 10 character width.
---
If the real value exceeds 10 characters, the display width will not
---
expand but will display a ">" as the last character, indicating the
---
entire value is not displayed.
---
The value will also be blinking and in reverse video.
End Set_Real
Using Dynamic Display Built-ins - Declare Routines Continued
-----------------------------------------------------------------------------
----
Section 3-C: SET_BOOL Declaration
----
Set all the input parameters for the INI_DYN_DISB call
-----------------------------------------------------------------------------
ROUTINE Set_Bool
Begin
-- Valid predefined windows are described in
-- Chapter 7.9.1, "USER MENU on the Teach Pendant
--
Error Line
--> ’ERR’
1
line
--
Status Line
--> ’T_ST’
3
lines
--
Display Window
--> ’T_FU’
10 lines
--
Prompt Line
--> ’T_PR’
1
line
--
Function Key
--> ’T_FK’
1
line
Int_Wind
= ’T_FU’
-- Use the predefined display window
Field_Width
= 10
-- Display 10 chars
Attr_Mask
= 2
-- Blinking
Char_Size
= 0
-- Normal
Row
= 3
-- Specify the location within ’T_FU’
Col
= 16
--
to dynamically displayed
Interval
= 250
-- 250ms between updates
Buffer_Size
= 10
-- Minimum value required
bool_names[1]
= ’YES’
-- string display in bool_var is FALSE
bool_names[2]
= ’NO’
-- string display in bool_var is TRUE
--- With this specification the BOOLEAN will be displayed as follows:
---
--------
---
|xxxxxxxx|
---
--------
---
Where the boolean value will be left justified.
---
The x’s will be one of the strings ’YES’ or ’NO’, depending on
---
the value of bool1. The string will be blinking.
End Set_Bool
Using Dynamic Display Built-ins - Declare Routines Continued
-----------------------------------------------------------------------------
----
Section 3-D: SET_ENUM Declaration
B-62
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
----
Set all the input parameters for the INI_DYN_DISE call.
-----------------------------------------------------------------------------
ROUTINE Set_Enum
Begin
-- Valid predefined windows are described in
-- Chapter 7.9.1, "USER MENU on the Teach Pendant
--
Error Line
--> ’ERR’
1
line
--
Status Line
--> ’T_ST’
3
lines
--
Display Window
--> ’T_FU’
10 lines
--
Prompt Line
--> ’T_PR’
1
line
--
Function Key
--> ’T_FK’
1
line
Int_Wind
= ’T_FU’
-- Use thE predefined display window
Attr_Mask
= 8
-- REVERSED
Field_Width
= 10
-- Display to characters
Char_Size
= 0
-- Normal
Row
= 4
-- Specify the location within ’T_FU’
Col
= 16
--
to dynamically displayed
Interval
= 250
-- 250ms between updates
Buffer_Size
= 10
-- Minimum value required
enum_names[1]
= ’Enum-0’
-- value displayed if enum_var = 0
enum_names[2]
= ’Enum-1’
-- value displayed if enum_var = 1
enum_names[3]
= ’Enum-2’
-- value displayed if enum_var = 2
enum_names[4]
= ’Enum-3’
-- value displayed if enum_var = 3
--- With this specification enum_var will be displayed as follows:
---
--------
---
|xxxxxxxx|
---
--------
---
Where one of the strings enum_names will be displayed,
---
depending on the integer value enum1. If enum1 is outside
---
the range 0-3, a string of 10 ’?’s will be displayed.
---
The string will be displayed in reversed video.
End Set_Enum
Using Dynamic Display Built-ins - Declare Routines Continued
-----------------------------------------------------------------------------
----
Section 3-E: SET_PORT Declaration
----
Set all the input parameters for the INI_DYN_DISP call.
-----------------------------------------------------------------------------
ROUTINE Set_Port
Begin
-- Valid predefined windows are described in
-- Chapter 7.9.1, "USER MENU on the Teach Pendant
--
Error Line
--> ’ERR’
1
line
--
Status Line
--> ’T_ST’
3
lines
--
Display Window
--> ’T_FU’
10 lines
B-63
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
--
Prompt Line
--> ’T_PR’
1
line
--
Function Key
--> ’T_FK’
1
line
Int_Wind
= ’T_FU’
-- Use the predefined display window
Field_Width
= 10
-- Display to characters
Attr_Mask
= 1
-- BOLD
Char_Size
= 0
-- Normal
Row
= 5
-- Specify the location within ’T_FU’
Col
= 16
--
to dynamically displayed
Interval
= 250
-- 250ms between updates
Buffer_Size
= 10
-- Minimum value required.
pval_names[1]
= ’RELEASED’
-- text displayed if key is not pressed
pval_names[2]
= ’PRESSED’
-- text displayed if key is pressed
port_type
= io_tpin
-- port type = TP key
port_no
= 175
-- user-key 3
--- With this specification PRESSED or RELEASED will be displayed as follows:
---
--------
---
|xxxxxxxx|
---
--------
---
Where the string will be left justified.
---
The x’s will be either ’RELEASED’ or ’PRESSED’.
---
The string will also be normal video.
---
(Bold is not supported on the teach pendant.)
End Set_Port
Using Dynamic Display Built-ins - Declare Routines Continued
-----------------------------------------------------------------------------
----
Section 3-F: SET_STR Declaration
----
Set all the input parameters for the INI_DYN_DISS call.
-----------------------------------------------------------------------------
ROUTINE Set_Str
Begin
-- Valid predefined windows are described in
-- Chapter 7.9.1, "USER MENU on the Teach Pendant
--
Error Line
--> ’ERR’
1
line
--
Status Line
--> ’T_ST’
3
lines
--
Display Window
--> ’T_FU’
10 lines
--
Prompt Line
--> ’T_PR’
1
line
--
Function Key
--> ’T_FK’
1
line
Int_Wind
= ’T_FU’
-- Use th predefined display window
Field_Width
= 10
-- Use the minimum width neccessary
Attr_Mask
= 1 OR 4
-- BOLD and UNDERLINED
Char_Size
= 0
-- Normal
Row
= 6
-- Specify the location within ’T_FU’
Col
= 16
--
to dynamically displayed
Interval
= 250
-- 250ms between updates
B-64
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
Buffer_Size
= 10
-- Minimum value required.
Format
= ’%10s’
-- 10 character minimum field width
--- With this specification the STRING will be displayed as follows:
---
--------
---
|xxxxxxxx|
---
--------
---
Where the string value will be left justified.
---
The x’s will be the string value.
---
The STRING will also be underlined.
End Set_Str
-----------------------------------------------------------------------------
----
Section 3-G: TP_CLS Declaration
----
Clear the TP USER menus screen and force it to be visible.
-----------------------------------------------------------------------------
ROUTINE tp_cls FROM rout_ex
Using Dynamic Display Built-ins - Initiate Dynamic Displays
-----------------------------------------------------------------------------
----
Section 4: Main program
-----------------------------------------------------------------------------
BEGIN --- DYN_DISP
dynd_abrt = FALSE
CONDITION[CH_ABORT]:
WHEN ABORT DO
-- When the program is aborting set dynd_abrt flag.
-- This will be triggered if this program aborts itself
-- or if an external mechanism aborts this program.
dynd_abrt = TRUE -- CHG_DATA will detect this and complete execution.
ENDCONDITION
ENABLE CONDITION [CH_ABORT]
-----------------------------------------------------------------------------
----
Section 4-A: Setup variables, initiate dynamic display
-----------------------------------------------------------------------------
TP_CLS
-- Clear the TP USER screen
-- Force display of the TP USER screen
STATUS = cc_success
-- Initialize the status variable
-- Initialize the dynamically displayed variables
Int1
= 1
Real1
= 1.0
Bool1
= FALSE
Enum1
= 0
Strl
= ’’
-- Display messages to the TP USER screen
WRITE (’Current INT1 =’,CR)
WRITE (’Current REAL1=’,CR)
WRITE (’Current BOOL1=’,CR)
B-65
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
WRITE (’Current ENUM1=’,CR)
WRITE (’Current PORT =’,CR)
WRITE (’Current STR1 =’,CR)
Set_Int
-- Set parameter values for INTEGER DYNAMIC DISPLAY
INI_DYN_DISI(Int1,Int_Wind,Field_Width,Attr_Mask,Char_Size,
Row,Col, Interval, Buffer_Size, Format ,Status)
IF Status <> cc_success THEN -- Check the status
WRITE(’ INI_DYN_DISI failed, Status=’,status,CR)
ENDIF
Set_Bool
-- Set parameter values for BOOLEAN DYNAMIC
DISPLAY
INI_DYN_DISB(Bool1,Int_Wind,Field_Width,Attr_Mask,Char_Size,
Row,Col, Interval, bool_names,Status)
IF Status <> cc_success THEN -- Check the status
WRITE(’ INI_DYN_DISB failed, Status=’,status,CR)
ENDIF
Using Dynamic Display Built-ins - Initiate Dynamic Displays
Set_Enum
-- Set parameter values for Enumerated Integer
--
DYNAMIC DISPLAY
INI_DYN_DISE(Enum1,Int_Wind,Field_Width,Attr_Mask,Char_Size,
Row,Col, Interval, enum_names,Status)
IF Status <> cc_success THEN -- Check the status
WRITE(’ INI_DYN_DISE failed, Status=’,status,CR)
ENDIF
Set_Port
-- Set parameter values for Port DYNAMIC DISPLAY
INI_DYN_DISP(port_type, port_no ,Int_Wind,Field_Width,Attr_Mask,Char_Size,
Row,Col, Interval, pval_names, Status)
IF Status <> cc_success THEN -- Check the status
WRITE(’ INI_DYN_DISP failed, Status=’,status,CR)
ENDIF
Set_Real
-- Set parameter values for REAL DYNAMIC DISPLAY
INI_DYN_DISR(Real1,Rel_Wind,Field_Width,Attr_Mask,Char_Size,
Row,Col, Interval, Buffer_Size, Format ,Status)
IF Status <> cc_success THEN -- Check the status
WRITE(’ INI_DYN_DISR failed, Status=’,status,CR)
ENDIF
Set_Str
-- Set parameter values for STRING DYNAMIC
DISPLAY
INI_DYN_DISS(Str1,Int_Wind,Field_Width,Attr_Mask,Char_Size,
Row,Col, Interval, Buffer_Size, Format ,Status)
IF Status <> cc_success THEN -- Check the status
WRITE(’ INI_DYN_DISS failed, Status=’,status,CR)
ENDIF
B-66
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
Using Dynamic Display Built-ins - Execute Subordinate Task
-----------------------------------------------------------------------------
----
Section 4-B: Check on subordinate program and execute it.
-----------------------------------------------------------------------------
-- Check the status of the other program which will change the value
-- of the variables.
LOAD_STATUS(’chg_data’, loaded, initialized)
IF (loaded = FALSE ) THEN
WRITE TPPROMPT(CHR(cc_clear_win))
-- Clear the prompt line
WRITE TPPROMPT(’CHG_DATA is not loaded. Loading now...’)
LOAD(’chg_data.pc’,0,status)
IF (status = cc_success) THEN
-- Check the status
RUN_TASK(’CHG_DATA’,1,false,false,1,status)
IF (Status <> cc_success) THEN
-- Check the status
WRITE (’Changing the value of the variables’,CR)
WRITE (’by another program failed’,CR)
WRITE (’BUT you can try changing the values’,CR)
WRITE (’from KCL’,CR)
ENDIF
ELSE
WRITE (’LOAD Failed, status = ’,status,CR)
ENDIF
ELSE
RUN_TASK(’CHG_DATA’,1,false,false,1,status)
IF (Status <> cc_success) THEN
-- Check the status
WRITE (’Changing the value of the variables’,CR)
WRITE (’by another program failed’,CR)
WRITE (’BUT you can try changing the values’,CR)
WRITE (’from KCL’,CR)
ENDIF
ENDIF
Using Dynamic Display Built-ins - User Response Cancels Dynamic Displays
-----------------------------------------------------------------------------
----
Section 4-C: Wait for user response, and cancel dynamic displays
-----------------------------------------------------------------------------
WRITE TPPROMPT(CHR(cc_clear_win))
-- Clear the prompt line
WRITE TPPROMPT(’Enter a number to cancel DYNAMIC display: ’)
READ (CR)
-- Read only one character
-- See Chapter 7.7.1,
-- "Formatting INTEGER Data Items"
ABORT_TASK(’CHG_DATA’,TRUE, TRUE,status)
-- Abort CHG_DATA
IF (status <> cc_success) THEN
-- Check the status
WRITE(’ ABORT_TASK failed, Status=’,status,CR)
B-67
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
ENDIF
CNC_DYN_DISI(Int1, Int_Wind,Status)
-- Cancel display of Intl
IF Status <> 0 THEN
-- Check the status
WRITE(’ CND_DYN_DISI failed, Status=’,status,CR)
ENDIF
CNC_DYN_DISR(Real1,Rel_Wind,Status)
-- Cancel display of Real1
IF Status <> 0 THEN
-- Check the status
WRITE(’ CND_DYN_DISR failed, Status=’,status,CR)
ENDIF
CNC_DYN_DISB(Bool1, Int_Wind,Status)
-- Cancel display of Bool1
IF Status <> 0 THEN
-- Check the status
WRITE(’ CND_DYN_DISB failed, Status=’,status,CR)
ENDIF
CNC_DYN_DISE(Enum1, Int_Wind,Status)
-- Cancel display of Enum1
IF Status <> 0 THEN
-- Check the status
WRITE(’ CND_DYN_DISE failed, Status=’,status,CR)
ENDIF
CNC_DYN_DISP(port_type, Port_no, Int_Wind,Status) -- Cancel display of
Port
IF Status <> 0 THEN
-- Check the status
WRITE(’ CND_DYN_DISP failed, Status=’,status,CR)
ENDIF
CNC_DYN_DISS(Str1, Int_Wind,Status)
-- Cancel display of String
IF Status <> 0 THEN
-- Check the status
WRITE(’ CND_DYN_DISS failed, Status=’,status,CR)
ENDIF
END DYN_DISP
B.11
MANIPULATING VALUES OF DYNAMICALLY DISPLAYED
VARIABLES
The CHG_DATA.KL program is called by DYN_DISP, where the actual variables are displayed
dynamically. This program does some processing and changes the value of those variables.
Manipulate Dynamically Displayed Variables - Overview
----------------------------------------------------------------------------
----
CHG_DATA.KL
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----
Section 0: Detail about CHG_DATA.KL
----------------------------------------------------------------------------
---- Elements of KAREL Language Covered:
In Section:
----
Actions:
----
Clauses:
----
FROM
Sec 2
B-68
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
----
Conditions:
----
Data types:
----
INTEGER
Sec 2
----
REAL
Sec 2
----
----
Directives:
----
Built-in Functions & Procedures:
----
Statements:
----
DELAY
Sec 4
----
FOR
ENDFOR
Sec 4
----
REPEAT...UNTIL
Sec 4
----
----
Reserve Words:
----
BEGIN
Sec 4
----
END
Sec 4
----
PROGRAM
Sec 1
----
VAR
Sec 2
----------------------------------------------------------------------------
----
Section 1: Program and Environment Declaration
----------------------------------------------------------------------------
PROGRAM CHG_DATA
%nolockgroup
%comment = ’Dynamic Disp2’
Manipulate Dynamically Displayed Variables - Declaration Section
-----------------------------------------------------------------------------
----
Section 2: Variable Declaration
-----------------------------------------------------------------------------
VAR
-- IF the following variables did NOT have IN CMOS, the following errors
-- would be posted when loading this program:
--
VARS-012 Create var -INT1 failed VARS-038 Cannot change CMOS/DRAM type
--
VARS-012 Create var -REAL1 failed VARS-038 Cannot change CMOS/DRAM type
-- This indicates that there is a discrepancy between DYN_DISP and CHG_DATA.
-- One program has specified to create the variables in DRAM the
-- other specified CMOS.
Int1 IN CMOS FROM dyn_disp
:INTEGER
-- dynamically displayed variable
Real1 IN CMOS FROM dyn_disp
:REAL
-- dynamically displayed variable
Bool1 IN CMOS FROM dyn_disp
:BOOLEAN
-- dynamically displayed variable
Enum1 IN CMOS FROM dyn_disp
:INTEGER
-- dynamically displayed variable
Str1 IN CMOS FROM dyn_disp
:STRING[10] -- dynamically displayed variable
indx
:INTEGER
dynd_abrt FROM dyn_disp
:BOOLEAN
-- Set in dyn_disp when dyn_disp
-- is aborting
-----------------------------------------------------------------------------
B-69
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
----
Section 3: Routine Declaration
-----------------------------------------------------------------------------
Manipulate Dynamically Displayed Variables - Main Program
-----------------------------------------------------------------------------
----
Section 4: Main program
-----------------------------------------------------------------------------
BEGIN
-- CHG_DATA
-- This demonstrates that the variables are changed from this task, CHG_DATA.
-- The dynamic display initiated in task DYN_DISP, will continue
-- to correctly display the updated values of these variables.
-- Do real application processing.
-- Simulated here in a FOR loop.
REPEAT
FOR indx
= -9999 to 9999 DO
int1
= (indx DIV 2) * 7
real1 = (indx DIV 3)* 3.13
bool1 = ((indx AND 4) = 0)
enum1 = (ABS(indx) DIV 5) MOD 5
Str1 = SUB_STR(’123456789A’, 1, (ABS(indx) DIV 6) MOD 7 + 1)
delay 200
-- Delay for 1/5 of a second as if processing is going on.
ENDFOR
UNTIL (DYND_ABRT)
-- This task is aborted from DYN_DISP. However, if
-- DYN_DISP aborts abnormally (ie from a KCL> ABORT), it
-- will set DYND_ABRT, which will allow CHG_DATA to
-- complete execution.
END CHG_DATA
B.12
DISPLAYING A LIST FROM A DICTIONARY FILE
This program controls the display of a list which is read in from the dictionary file DCLISTEG.UTX.
For more information on DCLISTEG.UTX refer to Section B.12.1 . DCLST_EX.KL controls the
placement of the cursor along with the action taken for each command.
Note The use of DISCTRL_FORM is the preferred method of displaying information.
DISCTRL_FORM will automatically take care of all the key inputs and is much easier to use. For
more information, refer to Chapter 10 DICTIONARIES AND FORMS .
Display List from Dictionary File - Overview
----------------------------------------------------------------------------
----
DCLST_EX.KL
----------------------------------------------------------------------------
B-70
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
----
Section 0: Detail about DCLST_EX.KL
----------------------------------------------------------------------------
----
Elements of KAREL Language Covered:
In
Section:
----
Actions:
----
Clauses:
----
FROM
Sec 3-E
----
Conditions:
----
Data types:
----
ARRAY OF STRING
Sec
2
----
BOOLEAN
Sec
2
----
DISP_DAT_T
Sec
2
----
FILE
Sec
2
----
INTEGER
Sec
2
----
STRING
Sec
2
----
Directives:
----
ALPHABETIZE
Sec
1
----
COMMENT
Sec
1
----
INCLUDE
Sec
1
----
NOLOCKGROUP
Sec
1
----
Built-in Functions &
Procedures:
----
ADD_DICT
Sec
3-B
----
ACT_SCREEN
Sec
4-I
----
ATT_WINDOW_S
Sec
4-C
----
CHECK_DICT
Sec
3-B
----
CLR_IO_STAT
Sec
3-A,C
----
CNV_STR_INT
Sec
4-E
----
DEF_SCREEN
Sec
4-B
----
DET_WINDOW
Sec
4-I
----
DISCTRL_LIST
Sec
4-G,H
----
FORCE_SPMENU
Sec
4-A,B,C
----
IO_STATUS
Sec
3-A,
----
ORD
Sec
4-H
----
READ_DICT
Sec
4-E,F
Display List from Dictionary File - Overview Continued
----
REMOVE_DICT
Sec 4-I
----
SET_FILE_ATR
Sec 4-G
----
STR_LEN
Sec 4-F
----
UNINIT
Sec 3-C
----
WRITE_DICT
Sec 4-D,H,I
----
Statements:
----
ABORT
Sec 3-B
----
CLOSE FILE
Sec 4-I
----
FOR...ENDFOR
Sec 4-F
----
IF...THEN...ENDIF
Sec 3-A,B,C,D; 4-F,H,I
B-71
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
----
OPEN FILE
Sec
3-A; 4-H
----
READ
Sec
4-A,B,H
----
REPEAT...UNTIL
Sec
4-H
----
ROUTINE
Sec
3-A,B,C,D,E
----
SELECT...ENDSELECT
Sec
4-H
----
WRITE
Sec
3-A,B,C,D;4-A,I
----
Reserve Words:
----
BEGIN
Sec
3-A,B,C,D;4
----
CR
Sec
4-A,B,C
----
END
Sec
3-A,B,C,D; 4-I
----
PROGRAM
Sec
1
----
VAR
Sec
2
----
Predefined File Names:
----
TPDISPLAY
Sec
4-D,G,H,I
----
TPFUNC
Sec
4-D,H
----
TPPROMPT
Sec
4-D,H,I
----
TPSTATUS
Sec
4-D,I
----
Devices Used:
----
RD2U
Sec
3-B
----
Predefined Windows:
----
ERR
Sec
4-C
----
T_ST
Sec
4-C
----
T_FU
Sec
4-C
----
T_PR
Sec
4-C
----
T_FR
Sec
4-C
Display List from Dictionary File - Declaration Section
-----------------------------------------------------------------------------
----
Section 1: Program and Environment Declaration
-----------------------------------------------------------------------------
PROGRAM DCLST_EX
%COMMENT=’DISCTRL_LIST ’
%ALPHABETIZE
%NOLOCKGROUP
%INCLUDE DCLIST -- the include file from the dictionary DCLISTEG.UTX
-----------------------------------------------------------------------------
----
Section 2:
Variable Declarations
-----------------------------------------------------------------------------
VAR
exit_Cmnd
: INTEGER
act_pending
: INTEGER
-- decide if any action is pending
display_data
: DISP_DAT_T
-- information needed for DICTRL_LIST
done
: BOOLEAN
-- decides when to complete execution
Kb_file
: FILE
-- file opened to the TPKB
i
: INTEGER
-- just a counter
B-72
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
key
: INTEGER
-- which key was pressed
last_line
: INTEGER
-- number of last line of information
list_data
: ARRAY[20] OF STRING[40] -- exact string information
num_options
: INTEGER
-- number of items in list
old_screen
: STRING[4]
-- previously attached screen
status
: INTEGER
-- status returned from built-in call
str
: STRING[1]
-- string read in from teach pendant
Err_file
: FILE
-- err log file
Opened
: BOOLEAN
-- err log file open or not
Display List from Dictionary File - Declare Routines
-----------------------------------------------------------------------------
----
Section 3: Routine Declaration
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
----
Section 3-A: Op_Err_File Declaration
----
Open the error log file.
-----------------------------------------------------------------------------
Routine Op_Err_File
Begin
Opened = false
Write TPPROMPT(CR,’Creating Auto Error File
’)
OPEN FILE Err_File (’RW’,’RD2U:\D_LIST.ERR’)
-- open for output
IF (IO_STATUS(Err_File) <> 0 ) THEN
CLR_IO_STAT(Err_File)
Write TPPROMPT(’*** USE USER WINDOW FOR ERROR OUTPUT ***’,CR)
ELSE
Opened = TRUE
ENDIF
End Op_Err_File
-----------------------------------------------------------------------------
----
Section 3-B: Chk_Add_Dct Declaration
----
Check whether a dictionary is loaded.
----
If not loaded then load in the dictionary.
-----------------------------------------------------------------------------
Routine Chk_Add_Dct
Begin -- Chk_Add_Dct
-- Make sure ’DLST’ dictionary is added.
CHECK_DICT(’DLST’,TPTSSP_TITLE,STATUS)
IF STATUS <> 0 THEN
Write TPPROMPT(CR,’Loading Required Dictionary
’)
ADD_DICT(’RD2U:\DCLISTEG’,’DLST’,DP_DEFAULT,DP_DRAM,STATUS)
IF status <> 0 THEN
WRITE TPPROMPT(’ADD_DICT failed, STATUS=’,STATUS,CR)
ABORT
-- Without the dictionary this program can not continue.
B-73
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
ENDIF
ELSE
WRITE TPPROMPT (’Dictionary already loaded in system.
’)
ENDIF
End Chk_Add_Dct
Display List from Dictionary File - Declare Error Routines
-----------------------------------------------------------------------------
----
Section 3-C: Log_Errors Declaration
----
Log detected errors to a file to be reviewed later.
-----------------------------------------------------------------------------
ROUTINE Log_Errors(Out: FILE; Err_Str:STRING;Err_No:INTEGER)
BEGIN
IF NOT Opened THEN
-- If error log file not opened then write errors to
-- screen
WRITE (Err_Str,Err_No,CR)
ELSE
IF NOT UNINIT(Out) THEN
CLR_IO_STAT(Out)
WRITE Out(Err_Str,Err_No,CR,CR)
ELSE
WRITE (Err_Str,Err_No, CR)
ENDIF
ENDIF
END Log_Errors
-----------------------------------------------------------------------------
----
Section 3-D: Chk_Stat Declaration
----
Check the global variable, status.
----
If not zero then log input parameter, err_str,
----
to error file.
-----------------------------------------------------------------------------
ROUTINE Chk_Stat ( err_str: STRING)
BEGIN -- Chk_Stat
IF( status <> 0) then
Log_Errors(Err_File, err_str,Status)
ENDIF
END Chk_Stat
-----------------------------------------------------------------------------
----
Section 3-E: TP_CLS Declaration
-----------------------------------------------------------------------------
ROUTINE TP_CLS FROM ROUT_EX
Display List from Dictionary File - Setup and Define Screen
B-74
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
-----------------------------------------------------------------------------
----
Section 4: Main Program
-----------------------------------------------------------------------------
BEGIN -- DCLST_EX
-----------------------------------------------------------------------------
----
Section 4-A: Perform Setup operations
-----------------------------------------------------------------------------
TP_CLS
-- Call routine to clear and force the TP USER menu to be visible
Write (’
***** Starting DISCTRL_LIST Example *****’, CR, CR)
Chk_Add_Dct
-- Call routine to check and add dictionary
Op_Err_File
-- Call routine open error log file
-----------------------------------------------------------------------------
----
Section 4-B: Define and Active a screen
-----------------------------------------------------------------------------
DEF_SCREEN(’LIST’, ’TP’, status)
-- Create/Define a screen called LIST
Chk_Stat (’DEF_SCREEN LIST’)
-- Verify DEF_SCREEN was successful
ACT_SCREEN(’LIST’, old_screen, status) -- activate the LIST screen that
-- that was just defined.
Chk_Stat (’ACT_SCREEN LIST’)
-- Verify ACT_SCREEN was successful
-----------------------------------------------------------------------------
----
Section 4-C: Attach windows to the screen
-----------------------------------------------------------------------------
-- Attach the required windows to the LIST screen.
-- SEE:
-- Chapter 7.9.1 "USER Menu on the Teach Pendant,
-- for more details on predefined window names.
ATT_WINDOW_S(’ERR’, ’LIST’, 1, 1, status)
-- attach the error window
Chk_Stat(’Attaching ERR’)
ATT_WINDOW_S(’T_ST’, ’LIST’, 2, 1, status) -- attach the status window
Chk_Stat(’T_ST not attached’)
ATT_WINDOW_S(’T_FU’, ’LIST’, 5, 1, status) -- attach the full window
Chk_Stat(’T_FU not attached’)
ATT_WINDOW_S(’T_PR’, ’LIST’, 15, 1, status)-- attach the prompt window
Chk_Stat(’T_PR not attached’)
ATT_WINDOW_S(’T_FK’, ’LIST’, 16, 1, status)-- attach the function window
Chk_Stat(’T_FK not attached’)
Display List from Dictionary File - Write Elements to the Screen
-----------------------------------------------------------------------------
----
Section 4-D: Write dictionary elements to windows
-----------------------------------------------------------------------------
-- Write dictionary element,TPTSSP_TITLE, from DLST dictionary.
-- Which will clear the status window, and display intro message in
-- reverse video.
WRITE_DICT(TPSTATUS, ’DLST’, TPTSSP_TITLE, status)
B-75
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
Chk_Stat( ’TPTSSP_TITLE not written’)
-- Write dictionary element,TPTSSP_FK1, from DLST dictionary.
-- Which will display "[TYPE]" to the function line window.
WRITE_DICT(TPFUNC, ’DLST’, TPTSSP_FK1, status)
Chk_Stat( ’TPTSSP_FK1 not written’)
-- Write dictionary element, TPTSSP_CLRSC, from DLST dictionary.
-- Which will clear the teach pendant display window.
WRITE_DICT(TPDISPLAY, ’DLST’, TPTSSP_CLRSC, status)
Chk_Stat( ’TPTSSP_CLRSC not written’)
-- Write dictionary element, TPTSSP_INSTR, from DLST dictionary.
-- Which will display instructions to the prompt line window.
WRITE_DICT(TPPROMPT, ’DLST’, TPTSSP_INSTR, status)
Chk_Stat( ’TPTSSP_INSTR not written’)
-----------------------------------------------------------------------------
----
Section 4-E:
Determine the number of menu options
-----------------------------------------------------------------------------
-- Read the dictionary element, TPTSSP_NUM, from DLST dictionary,
-- Into the first element of list_data.
-- list_data[1] will be an ASCII representation of the number of
-- menu options. last_line will be returned with the number of
-- lines/elements used in list_data.
READ_DICT(’DLST’, TPTSSP_NUM, list_data, 1, last_line, status)
Chk_Stat( ’TPTSSP_NUM not read’)
-- convert the string into the INTEGER, num_options
CNV_STR_INT(list_data[1], num_options)
Display List from Dictionary File - Initialize Display Data
-----------------------------------------------------------------------------
----
Section 4-F:
Initialize the data structure, display_data
----
Which is used to display the list of menu options.
-----------------------------------------------------------------------------
-- Initialize the display data structure
-- In this example we only deal with window 1.
display_data.win_start[1] = 1
-- Starting row for window 1.
display_data.win_end[1]
= 10
-- Ending row for window 1.
display_data.curr_win = 0
-- The current window to display, where
--
zero (0) specifies first window.
display_data.cursor_row = 1
-- Current row the cursor is on.
display_data.lins_per_pg = 10
-- The number of lines scrolled when the
-- user pushes SHIFT Up or Down. Usually
-- it is the same as the window size.
display_data.curs_st_col[1] = 0 -- starting column for field 1
display_data.curs_en_col[1] = 0 -- ending column for field 1, will be
-- updated a little later
display_data.curr_field = 0
-- Current field, where
B-76
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
--
zero (0) specifies the first field
display_data.last_field = 0
-- Last field in the list (only using one
--
field in this example).
display_data.curr_it_num = 1
-- Current item number the cursor is on.
display_data.sob_it_num = 1
-- Starting item number.
display_data.eob_it_num = num_options
-- Ending item number, which is
-- the number of options read in.
display_data.last_it_num
= num_options-- Last item number, also the
--
number of options read in
-- Make sure the window end is not beyond total number of elements in list.
IF display_data.win_end[1] > display_data.last_it_num THEN
display_data.win_end[1] = display_data.last_it_num --reset to last item
ENDIF
-- Read dictionary element, TPTSSP_MENU, from dictionary DLST.
-- list_data will be populated with the menu list information
-- list_data[1] will contain the first line of information from
-- the TPTSSP_MENU and list_data[last_line] will contain the last
-- line of information read from the dictionary.
READ_DICT(’DLST’, TPTSSP_MENU, list_data, 1, last_line, status)
Chk_Stat(’Reading menu list failed’)
-- Determine longest list element & reset cursor end column for first field.
FOR i = 1 TO last_line DO
IF (STR_LEN(list_data[i]) > display_data.curs_en_col[1]) THEN
display_data.curs_en_col[1] = STR_LEN(list_data[i])
ENDIF
ENDFOR
Display List from Dictionary File - Control Cursor Movement
-----------------------------------------------------------------------------
----
Section 4-G:
Display the list.
-----------------------------------------------------------------------------
-- Initial Display the menu list.
DISCTRL_LIST(TPDISPLAY, display_data, list_data, DC_DISP, status)
Chk_Stat(’Error displaying list’)
-- Open a file to the TPDISPLAY window with PASSALL and FIELD attributes
-- and NOECHO
SET_FILE_ATR(kb_file, ATR_PASSALL)
-- Get row teach pendant input
SET_FILE_ATR(kb_file, ATR_FIELD)
-- so that a single key will
-- satisfy the reads.
SET_FILE_ATR(kb_file, ATR_NOECHO)
-- don’t echo the keys back to
-- the screen
OPEN FILE Kb_file (’RW’, ’KB:TPKB’) -- open a file to the Teach pendant
-- keyboard (keys)
status = IO_STATUS(Kb_file)
Chk_Stat(’Error opening TPKB’)
B-77
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
act_pending = 0
done = FALSE
-----------------------------------------------------------------------------
----
Section 4-H: Control cursor movement within the list
-----------------------------------------------------------------------------
REPEAT
-- Wait for a key input
READ Kb_file (str::1)
key = ORD(str,1)
key = key AND 255
-- Convert the key to correct value.
SELECT key OF
-- Decide how to handle key inputs
CASE (KY_UP_ARW) :
-- up arrow key pressed
IF act_pending <> 0 THEN
-- If a menu item was selected...
-- Clear confirmation prompt
WRITE_DICT(TPPROMPT, ’DLST’, TPTSSP_CLRSC, status)
-- Clear confirmation function keys
WRITE_DICT(TPFUNC, ’DLST’, TPTSSP_CLRSC, status)
ENDIF
DISCTRL_LIST(TPDISPLAY, display_data, list_data, DC_UP, status)
Chk_Stat (’Error displaying list’)
CASE (KY_DN_ARW) : -- down arrow key pressed
IF act_pending <> 0 THEN -- If a menu item was selected...
-- Clear confirmation prompt
WRITE_DICT(TPPROMPT, ’DLST’, TPTSSP_CLRSC, status)
-- Clear confirmation function keys
WRITE_DICT(TPFUNC, ’DLST’, TPTSSP_CLRSC, status)
ENDIF
DISCTRL_LIST(TPDISPLAY, display_data, list_data,
DC_DN, status)
Chk_Stat (’Error displaying list’)
Display List from Dictionary File - Control Cursor Movement Continued
CASE (KY_ENTER) :
-- Perform later
CASE (KY_F4) : -- "YES" function key pressed
IF act_pending <> 0 THEN -- If a menu item was selected...
-- Clear confirmation prompt
WRITE_DICT(TPPROMPT, ’DLST’, TPTSSP_CLRSC, status)
-- Clear confirmation function keys
WRITE_DICT(TPFUNC, ’DLST’, TPTSSP_CLRSC, status)
IF act_pending = num_options THEN
-- Exit the routine
done = TRUE
ENDIF
-- Clear action pending
act_pending = 0
B-78
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
ENDIF
CASE (KY_F5) : -- "NO" function key pressed
-- Clear confirmation prompt
WRITE_DICT(TPPROMPT, ’DLST’, TPTSSP_INSTR, status)
-- Clear confirmation function keys
WRITE_DICT(TPFUNC, ’DLST’, TPTSSP_CLRSC, status)
-- Clear action pending
act_pending = 0
ELSE :
-- User entered an actual item number. Calculate which
-- row the cursor should be on and redisplay the list.
IF ((key > 48) AND (key <= (48 + num_options))) THEN
-- Translate number to a row
key = key - 48
display_data.cursor_row = key
DISCTRL_LIST(TPDISPLAY,display_data,list_data,DC_DISP,status)
Chk_Stat (’Error displaying list’)
key = KY_ENTER
ENDIF
ENDSELECT
IF key = KY_ENTER THEN -- User has specified an action
-- Write confirmation prompt for selected item
WRITE_DICT (TPPROMPT, ’DLST’,
(TPTSSP_CNF1 - 1 + display_data.cursor_row), status)
-- Display confirmation function keys
WRITE_DICT(TPFUNC, ’DLST’, TPTSSP_FK2, status)
-- Set action pending to selected item
act_pending = display_data.cursor_row -- this is the item selected
ENDIF
UNTIL done
-- repeat until the user selects the exit option
Display List from Dictionary File - Cleanup and Exit Program
-----------------------------------------------------------------------------
----
Section 4-I: Cleanup before exiting program
-----------------------------------------------------------------------------
-- Clear the TP USER menu windows
WRITE_DICT(TPDISPLAY, ’DLST’, TPTSSP_CLRSC, status)
WRITE_DICT(TPSTATUS, ’DLST’, TPTSSP_CLRSC, status)
-- Close the file connected to the TP keyboard.
CLOSE FILE Kb_file
-- Close the error log file if it is open.
IF opened THEN
close file Err_File
ENDIF
Write TPPROMPT (cr,’Example Finished ’)
REMOVE_DICT ( ’LIST’, dp_default, status) -- remove the dictionary
B-79
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
write (’remove dict’, status,cr)
Chk_Stat (’Removing dictionary’)
ACT_SCREEN(old_screen, old_screen, status) -- activate the previous screen
Chk_stat (’Activating old screen’)
DET_WINDOW(’ERR’, ’LIST’, status)
-- Detach all the windows that were
Chk_stat (’Detaching ERR window’)
DET_WINDOW(’T_ST’, ’LIST’, status) -- previously attached.
Chk_stat (’Detaching T_ST window’)
DET_WINDOW(’T_FU’, ’LIST’, status)
Chk_stat (’Detaching T_FU window’)
DET_WINDOW(’T_PR’, ’LIST’, status)
Chk_stat (’Detaching T_PR window’)
DET_WINDOW(’T_FK’, ’LIST’, status)
Chk_stat (’Detaching T_FK window’)
END DCLST_EX
B.12.1
Dictionary Files
This ASCII dictionary file is used to create a teach pendant screen which is used with DCLST_EX.KL.
For more information on DCLST_EX.KL refer to Section B.7 .
Dictionary File
.kl dclist
$-,TPTSSP_TITLE &home &reverse "Karel DISCTRL_LIST Example
"
&standard
$-,TPTSSP_CLRSC &home &clear_2_eow
$-,TPTSSP_FK1 &home" [TYPE]
"
$-,TPTSSP_FK2 &home"
YES
NO
"
$-,TPTSSP_INSTR &home "Press ’ENTER’ or number key to select."
&clear_2_eol
* Add menu options here, "Exit" must be last option
* TPTSSP_NUM specifies the number of menu options
$-,TPTSSP_NUM "14"
$-,TPTSSP_MENU
" 1
Test Cycle 1" &new_line
" 2
Test Cycle 2" &new_line
" 3
Test Cycle 3" &new_line
" 4
Test Cycle 4" &new_line
" 5
Test Cycle 5" &new_line
" 6
Test Cycle 6" &new_line
" 7
Test Cycle 7" &new_line
" 8
Test Cycle 8" &new_line
B-80
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
" 9
Test Cycle 9" &new_line
" 10
Test Cycle 10" &new_line
" 11
Test Cycle 11" &new_line
" 12
Test Cycle 12" &new_line
" 13
Test Cycle 13" &new_line
" 14
EXIT"
* Confirmations must be in order
$-,TPTSSP_CNF1 &home"Perform test cycle 1? [NO]" &clear_2_eol
$-,TPTSSP_CNF2 &home"Perform test cycle 2? [NO]" &clear_2_eol
$-,TPTSSP_CNF3 &home"Perform test cycle 3? [NO]" &clear_2_eol
$-,TPTSSP_CNF4 &home"Perform test cycle 4? [NO]" &clear_2_eol
$-,TPTSSP_CNF5 &home"Perform test cycle 5? [NO]" &clear_2_eol
$-,TPTSSP_CNF6 &home"Perform test cycle 6? [NO]" &clear_2_eol
$-,TPTSSP_CNF7 &home"Perform test cycle 7? [NO]" &clear_2_eol
$-,TPTSSP_CNF8 &home"Perform test cycle 8? [NO]" &clear_2_eol
$-,TPTSSP_CNF9 &home"Perform test cycle 9? [NO]" &clear_2_eol
$-,TPTSSP_CNF10 &home"Perform test cycle 10? [NO]" &clear_2_eol
$-,TPTSSP_CNF11 &home"Perform test cycle 11? [NO]" &clear_2_eol
$-,TPTSSP_CNF12 &home"Perform test cycle 12? [NO]" &clear_2_eol
$-,TPTSSP_CNF13 &home"Perform test cycle 13? [NO]" &clear_2_eol
$-,TPTSSP_CNF14 &home"Exit? [NO]" &clear_2_eol
B.13
USING THE DISCTRL_ALPHA BUILT-IN
This program shows three different ways to use the DISCTRL_ALPH built-in. The DISCTRL_ALPH
built-in displays and controls alphanumeric string entry in a specified window. Refer to Appendix A ,
"KAREL Language Alphabetic Description" for more information.
Method 1 allows a program name to be entered using the default value for the dictionary name. See
Section 4-A in Using the DISCTRL_ALPHA Built-in - Enter Data from Teach Pendant .
Method 2 allows a comment to be entered using the default value for the dictionary name. See Section
4-B in Using the DISCTRL_ALPHA Built-in - Enter Data from Teach Pendant .
Method 3 uses a user specified dictionary name and element to enter a program name. See Section
4-C in Using the DISCTRL_ALPHA Built-in - Enter Data from CRT/KB .
This program also posts all errors to the controller.
Using the DISCTRL_ALPHA Built-in - Overview
-----------------------------------------------------------------------------
----
DCALP_EX.KL
-----------------------------------------------------------------------------
---- Elements of KAREL Language Covered:
In Section:
----
Actions:
B-81
B. KAREL EXAMPLE PROGRAMS
MARRC75KR07091E Rev D
----
Clauses:
----
Conditions:
----
Data types:
----
INTEGER
Sec 2
----
STRING
Sec 2
----
Directives:
----
COMMENT
Sec 1
----
INCLUDE
Sec 1
----
NOLOCKGROUP
Sec 1
----
Built-in Functions & Procedures:
----
ADD_DICT
Sec
4-C
----
CHR
Sec
4-A,B,C
----
DISCTRL_ALPH
Sec
4-A,B,C
----
FORCE_SPMENU
Sec
4-A,B,C
----
POST_ERR
Sec
4-A,B,C
----
SET_CURSOR
Sec
4-A,B,C
----
SET_LANG
Sec
4-C
----
Statements:
----
READ
Sec
4-A,B
----
WRITE
Sec
4-A,B,C
----
IF...THEN...ENDIF
Sec
4-A,B,C
----
Reserve Words:
----
BEGIN
Sec
4
----
CONST
Sec
2
----
CR
Sec
4-A,B,C
----
END
Sec
4-C
----
PROGRAM
Sec
1
----
VAR
Sec
2
----
Predefined File Names:
----
OUTPUT
Sec
4-C
----
TPDISPLAY
Sec
4-A,B
----
Predefined Windows:
----
T_FU
Sec
4-A,B
----
C_FU
Sec
4-C
Using the DISCTRL_ALPHA Built-in - Declaration Section
-----------------------------------------------------------------------------
----
Section 1: Program and Environment Declaration
-----------------------------------------------------------------------------
PROGRAM DCALP_EX
%COMMENT
= ’Display Alpha’
%NOLOCKGROUP
%INCLUDE KLEVKEYS
-- Necessary for the KY_ENTER
%INCLUDE DCALPH
-- Necessary for the ALPH_PROG Element, see section 4-C
-----------------------------------------------------------------------------
B-82
MARRC75KR07091E Rev D
B. KAREL EXAMPLE PROGRAMS
----
Section 2: Constant and Variable Declarations
-----------------------------------------------------------------------------
CONST
cc_home
= 137
cc_clear_win = 128
cc_warn
= 0
-- Value passed to POST_ERR to display warning only.
cc_pause
= 1
-- value passed to POST_ERR to pause program.
VAR
status
: INTEGER
device_stat
: INTEGER
term_char
: INTEGER
window_name
: STRING[4]
prog_name
: STRING[12]
comment
: STRING[40]
-----------------------------------------------------------------------------
----
Section 3: Routine Declaration
-----------------------------------------------------------------------------
Using the DISCTRL_ALPHA Built-in - Enter Data from Teach Pendant
-----------------------------------------------------------------------------
----
Section 4: Main Program
-----------------------------------------------------------------------------
BEGIN
-- DCALP_EX
-----------------------------------------------------------------------------
---- Section 4-A: Enter a program name from the teach pendant USER menu
-----------------------------------------------------------------------------
WRITE (CHR(cc_home), CHR(cc_clear_win))
-- Clear TP USER menu
FORCE_SPMENU(tp_panel, SPI_TPUSER, 1)
-- Force TP USER menu to be
-- visible
SET_CURSOR(TPDISPLAY, 12, 1, status)
-- reposition cursor
WRITE (’prog_name: ’)
prog_name = ’’
-- initialize program name
DISCTRL_ALPH(’t_fu’, 12, 12, prog_name, ’PROG’, 0, term_char, status)
IF status <> 0 THEN
POST_ERR(status, ’’, 0, cc_warn)
ENDIF
IF term_char = ky_enter THEN
-- User pressed the ENTER key
WRITE (CR, ’prog_name was changed:’, prog_name, CR)
ELSE
WRITE (CR, ’prog_name was not changed’)
ENDIF
WRITE (CR, ’Press enter to continue’)
READ (CR)
-----------------------------------------------------------------------------
---- Section 4-B: Enter a comment from the teach pendant
B-83
|
||
|
|
|