FANUC Robotics SYSTEM R-30iA and R-30iB Controller. KAREL Reference Manual - page 9

 

  Index      Manuals     FANUC Robotics SYSTEM R-30iA and R-30iB Controller. KAREL Reference Manual (MARRC75KR07091E Rev D)

 

Search            copyright infringement  

 

   

 

   

 

Content      ..     7      8      9      10     ..

 

 

 

FANUC Robotics SYSTEM R-30iA and R-30iB Controller. KAREL Reference Manual - page 9

 

 

MARRC75KR07091E Rev D
11. SOCKET MESSAGING
11.3
CONFIGURING THE SOCKET MESSAGING OPTION
11.3.1
Overview
In order to use Socket Messaging, you need to configure the following network hardware and
software parameters:
On the server,
— The port you want to use for socket messaging
On the client,
— The IP address or name of your server
— The port on the server that you want to use for socket messaging.
Use Procedure 11-1 to set up a Socket Messaging Server Tag. Use Procedure 11-2 to set up a Socket
Messaging Client Tag.
Note The server port at which the server listens on should match the port the client tries to connect on.
11.3.2
Setting up a Server Tag
You need configure the server tags you want to use for socket messaging. Use Procedure 11-1 to
set up your server tags.
Note If the server tags you want to use are being used by a network protocol other than TCP/IP, you
need to undefine the tags before they can be used for socket messaging. After making sure the tag you
want to use is not critical to another component of your network, you must undefine the tag.
Procedure 11-1
Setting up a Server Tag
Conditions
The tag you want to set up is not configured to be used by another device on your network.
Steps
1. Cold start the controller.
a. On the teach pendant, press and hold the SHIFT and RESET keys. Or, on the operator
panel, press and hold RESET.
b. While still pressing SHIFT and RESET on the teach pendant (or RESET on the operator
panel), turn on the power disconnect circuit breaker.
c. Release all of the keys.
11-3
11. SOCKET MESSAGING
MARRC75KR07091E Rev D
2. On the teach pendant, press MENUS.
3. Select SETUP.
4. Press F1, [TYPE].
5. Select Host Comm.
6. Press F4, [SHOW].
7. Choose Servers.
8. Move the cursor to the tag you want set up for Socket Messaging, and press F3, DETAIL.
You will see screen similar to the following.
SETUP Tags
Tag S3:
Comment:
****************
Protocol Name:
********
Current State:
UNDEFINED
Startup State:
Server IP/Hostname:*****************
Remote Path/Share: *****************
Port:
*****
Inactivity Timeout:
15 min
Username:
anonymous
Password
**********
9. Move the cursor to Protocol name, and press F4, [CHOICE].
10. Select SM.
11. Move the cursor to Startup State, and press F4, [CHOICE].
12. Select START.
13. Press F2, [ACTION].
14. Select DEFINE.
15. Press F2, [ACTION].
16. Select START.
17. Set the system variable:
a. Press MENUS.
b. Select NEXT.
c. Select SYSTEM, and press F1, [TYPE].
d. Select Variables.
11-4
MARRC75KR07091E Rev D
11. SOCKET MESSAGING
e. Move the cursor to $HOSTS_CFG, and Press ENTER.
f. Move the cursor to the structure corresponding to the tag selected in Step 8 . For example,
if you are setting up tag S3, move the cursor structure element [3], as shown in the
following screen.
SYSTEM Variables
$HOSTS_CFG
1
[1]
HOST_CFG_T
2
[2]
HOST_CFG_T
3
[3]
HOST_CFG_T
4
[4]
HOST_CFG_T
5
[5]
HOST_CFG_T
6
[6]
HOST_CFG_T
7
[7]
HOST_CFG_T
8
[8]
HOST_CFG_T
g. Press ENTER. You will see a screen similar to the following.
SYSTEM Variables
$HOSTS_CFG[3]
1
$COMMENT
*uninit*
2
$PROTOCOL
’SM’
3
$PORT
*uninit*
4
$OPER
3
5
$STATE
3
6
$MODE
*uninit*
7
$REMOTE
*uninit*
8
$REPERRS
FALSE
9
$TIMEOUT
15
10
$PATH
*uninit*
11
$STRT_PATH
*uninit*
12
$STRT_REMOTE
*uninit*
13
$USERNAME
*uninit*
14
$PWRD_TIMOUT
0
15
$SERVER_PORT
0
h. Move the cursor to $SERVER_PORT. Type in the name of the TCP/IP port you want to
use for socket messaging. The server tag is now ready to use from a KAREL program.
11-5
11. SOCKET MESSAGING
MARRC75KR07091E Rev D
11.3.3
Setting up a Client Tag
You need configure the client tags you want to use for socket messaging. Use Procedure 11-2 to set up
your server tags. You can also use Procedure 11-2 to undefine tags.
Note If the client tags you want to use are being used by a network protocol other than TCP/IP, you
need to undefine the tags before they can be used for socket messaging.
Procedure 11-2
Setting up a ClientTag
Conditions
The tag you want to set up is not configured to be used by another device on your network.
Steps
1. Cold start the controller.
a. On the teach pendant, press and hold the SHIFT and RESET keys. Or, on the operator
panel, press and hold RESET.
b. While still pressing SHIFT and RESET on the teach pendant (or RESET on the operator
panel), turn on the power disconnect circuit breaker.
c. Release all of the keys.
2. On the teach pendant, press MENUS.
3. Select SETUP.
4. Press F1, [TYPE].
5. Select Host Comm.
6. Press F4, [SHOW].
7. Choose Clients.
8. Move the cursor to the tag you want set up for Socket Messaging, and press F3, DETAIL.
You will see screen similar to the following.
11-6
MARRC75KR07091E Rev D
11. SOCKET MESSAGING
SETUP Tags
Tag C3:
Comment:
****************
Protocol Name:
********
Current State:
UNDEFINED
Startup State:
Server IP/Hostname:****************
Remote Path/Share: ****************
Port:
*****
Inactivity Timeout:
15 min
Username:
anonymous
Password
**********
9.
Move the cursor to the Protocol Name item, and press F4, [CHOICE].
10. Select SM.
11.
Move the cursor to the Startup State item, press F4, [CHOICE], and choose DEFINE.
12.
Move the cursor to the Server IP/Hostname item, and press ENTER.
13. Type in hostname or IP address the of the remote host server you want to use for socket
messaging.
Note If you are not using DNS, you must add the remote host and its IP address into the host
entry table.
14. Press F2, [ACTION], and select DEFINE.
15. Set the system variable:
a. Press MENUS.
b. Select NEXT.
c. Select SYSTEM, and press F1, [TYPE].
d. Select Variables.
e. Move the cursor to $HOSTC_CFG, and press ENTER.
f. Move the cursor to the structure corresponding to the tag selected in Step 8 . For
example, if you are setting up tag C3, move the cursor structure element [3], as shown
in the following screen.
11-7
11. SOCKET MESSAGING
MARRC75KR07091E Rev D
SYSTEM Variables
$HOSTC_CFG
1
[1]
HOST_CFG_T
2
[2]
HOST_CFG_T
3
[3]
HOST_CFG_T
4
[4]
HOST_CFG_T
5
[5]
HOST_CFG_T
6
[6]
HOST_CFG_T
7
[7]
HOST_CFG_T
8
[8]
HOST_CFG_T
g. Press ENTER. You will see a screen similar to the following.
SYSTEM Variables
$HOSTC_CFG[3]
1
$COMMENT
*uninit*
2
$PROTOCOL
’SM’
3
$PORT
*uninit*
4
$OPER
3
5
$STATE
3
6
$MODE
*uninit*
7
$REMOTE
*uninit*
8
$REPERRS
FALSE
9
$TIMEOUT
15
10
$PATH
*uninit*
11
$STRT_PATH
*uninit*
12
$STRT_REMOTE
*uninit*
13
$USERNAME
*uninit*
14
$PWRD_TIMOUT
0
15
$SERVER_PORT
0
h. Move the cursor to $SERVER_PORT. Type in the name of the TCP/IP server port you want
to use for socket messaging. The client tag is now ready to use from a KAREL program.
11-8
MARRC75KR07091E Rev D
11. SOCKET MESSAGING
11.4
SOCKET MESSAGING AND KAREL
11.4.1
Overview
Socket messaging is an integrated component of KAREL. When you use socket messaging functions
and utilities from a KAREL program, the syntax is similar to other file read and write operations,
except that you need to establish a network connection when you use socket messaging functions
and utilities.
The following KAREL socket messaging functions and utilities enable the server to establish a
connection with a remote host on your network. There are several KAREL program samples in this
section that provide examples of how these functions and utilities can be used with KAREL file
read and write functions and utilities to write a complete Socket Messaging KAREL client or a
server program or application. The Environment flbt statement is required to use any of the listed
builtins (%ENVIRONMENT flbt).
11.4.2
MSG_CONN( string, integer )
MSG_CONN needs to be called before any tag can be used for socket messaging.
The first parameter of this command contains the tag name ("S1:" for example) and the second
parameter is an integer that will contain the status of the operation. If you are using this command to
connect to a server tag, this command will return a status value only after a remote client device has
established a connection with this server tag.
If you are using this command to connect to a client tag, this command will return a status value only
if the remote server is attempting to accept the connection. If the connection was successful, the
command will return a value indicating a successful connection was made. If the connection was not
successful, the command will return a value indicating that a connection error has occurred.
During a socket messaging session, you must use MSG_DISCO to close the socket connection with a
client or server tag before any subsequent attempts to connect to the same client or server tag can be
made using MSG_CONN.
11.4.3
MSG_DISCO( string, integer )
MSG_DISCO is used to close socket messaging connections. If a connection is lost, perhaps because
a READ or WRITE error occurred when the remote server terminated a socket messaging connection,
you will need to use MSG_DISCO to close the connection to the remote server. In this case,
MSG_DISCO must be used to close the connection at the client side before MSG_CONN can be used
to establish another connection to the remote server.
11-9
11. SOCKET MESSAGING
MARRC75KR07091E Rev D
The first parameter of this command contains the tag name (e.g. "S1:") and the second parameter is an
integer value that indicates the status of closing the connection on the client side.
11.4.4
MSG_PING( string, integer )
MSG_PING is a utility command used to check network connections with a remote host, so that you
can determine if it is currently connected to the network. The MSG_PING command sends ping
packets to the remote host and waits for a reply. (Ping packets are chunks of data that are transferred
between hosts on a network. ) If there is no reply from the remote host, this usually means that you
will not be able to use other network protocols like FTP, TELNET, or Socket Messaging to connect to
that host. If you have attempted without success to use Socket Messaging to connect to a remote host,
the MSG-PING utility is a good place to start in trying to diagnose the problem.
The first parameter of this command contains the name of the remote host to ping. If you are not
using DNS on your network, the host name and IP address of the remote host will have to exist in
the Host Entry table.
11.4.5
Exchanging Data during a Socket Messaging Connection
After you have successfully established a socket messaging connection, you can use KAREL
commands to exchange data between connected devices. KAREL has several commands that can be
used for data exchange operations:
OPEN FILE
WRITE
READ
BYTES_AHEAD
Refer to the KAREL Reference Manual for details.
11.5
NETWORK PERFORMANCE
11.5.1
Overview
Performance of socket messaging on your network will vary depending upon the number of devices
connected to the network, the number of applications being run on the controller, the network cabling
configuration, and number of hops that the message will have to make to reach its destination device.
11-10
MARRC75KR07091E Rev D
11. SOCKET MESSAGING
Note Hops is a term that indicates the number of routers between the source host and destination
host. In general, the fewer the number of hops the data makes from router to router, the faster the
data is transmitted between the source and destination hosts. Data transfer is fastest between hosts
on the same network.
11.5.2
Guidelines for a Good Implementation
Use the following guidelines when implementing a solution for any application using socket
messaging.
You must not transfer small data separately, instead gather the data and transfer as a larger
packet. This applies to both read and write.
You must understand that the rate of data does not flood the remote side.
You must understand that there are other nodes on the Ethernet network so performance cannot
be guaranteed.
You must understand that other applications on robot also use TCP/IP and performance can be
affected.
11.6
PROGRAMMING EXAMPLES
11.6.1
This section contains programming examples for a KAREL socket messaging client, and a KAREL
socket messaging server. There is also a UNIX-based ANSI C example for a loopback client
application, which assumes that you have access to a UNIX-compatible ANSI C compiler, and a basic
knowledge of programming in the ANSI C language.
Note The KAREL examples assume the appropriate tags (C2 for client and S3 for Server) have been
setup for socket messaging using Procedure 11-1 and Procedure 11-2 .
11.6.2
A KAREL Client Application
A KAREL Client Application provides code for a basic KAREL client application that can be used to
establish a socket messaging connection to a remote host, which could be the KAREL server socket
messaging application shown in KAREL Server Application .
A KAREL Client Application
--
This material is the joint property of Fanuc Robotics Corporation and
11-11
11. SOCKET MESSAGING
MARRC75KR07091E Rev D
--
FANUC LTD Japan, and must be returned to either Fanuc Robotics
--
Corporation or FANUC LTD Japan immediately upon request. This material
--
and
the information illustrated or contained herein may not be
--
reproduced, copied, used, or transmitted in whole or in part in any way
--
without the prior written consent of both Fanuc Robotics and FANUC
--
--
All Rights Reserved
--
Copyright (C)
2000
--
Fanuc Robotics Corporation
--
FANUC LTD Japan
--
--
Karel is a registered trademark of
--
Fanuc Robotics Corporation
--
+
--
Program: loopcl.kl - Program for TCP Messaging
--
--
Description:
--
--
This program serves as an example on how to use TCP messaging
--
and write a client Karel program.
--
--
Authors: Fanuc Robotics Corporation
--
3900 West Hamlin
--
Rochester Hills, MI 48309
--
--
Modification history:
--
-------------------------------------------------------------------------------
PROGRAM loopcl
%STACKSIZE = 4000
%NOLOCKGROUP
%NOPAUSE=ERROR+COMMAND+TPENABLE
%ENVIRONMENT uif
%ENVIRONMENT sysdef
%ENVIRONMENT memo
%ENVIRONMENT kclop
%ENVIRONMENT bynam
%ENVIRONMENT fdev
%ENVIRONMENT flbt
%INCLUDE klevccdf
%INCLUDE klevkeys
%INCLUDE klevkmsk
-------------------------------------------------------------------------------
VAR
file_var : FILE
tmp_int
: INTEGER
tmp_str
: STRING[128]
11-12
MARRC75KR07091E Rev D
11. SOCKET MESSAGING
status
: INTEGER
entry
: INTEGER
loop1
: BOOLEAN
--------------------------------------------------------
BEGIN
SET_FILE_ATR(file_var, ATR_IA)
SET_VAR(entry, ’*SYSTEM*’,’$HOSTC_CFG[2].$SERVER_PORT’,59002,status)
-- Connect the tag
WRITE(’Connecting..’,cr)
MSG_CONNECT(’C2:’,status)
WRITE(’ Connect Status = ’,status,cr)
loop1 = TRUE
IF
status = 0 THEN
WHILE loop1 = TRUE DO
WRITE(’Opening File..’,cr)
OPEN FILE file_var(’rw’,’C2:’)
status = IO_STATUS(file_var)
IF status = 0 THEN
FOR tmp_int = 1 TO 100 DO
tmp_str = ’0123456789012345’
WRITE file_var(tmp_str::10)
WRITE(’Wrote 126 Bytes’,cr)
IF status <> 0 THEN
WRITE(’Loop Test Fails’,cr)
loop1 = FALSE
tmp_int = 100
ELSE
WRITE(’Read 126 Bytes’,cr)
READ file_var(tmp_str::10)
status = IO_STATUS(file_var)
WRITE(’Read Status ’,status,cr)
ENDIF
ENDFOR
WRITE(’Closed File’,cr)
CLOSE FILE file_var
ELSE
WRITE(’Error Opening File’,cr)
loop1 = FALSE
ENDIF
ENDWHILE
WRITE(’Disconnecting..’,cr)
MSG_DISCO(’C2:’,status)
WRITE(’Done.’,cr)
11-13
11. SOCKET MESSAGING
MARRC75KR07091E Rev D
ENDIF
END loopcl
11.6.3
A KAREL Server Application
KAREL Server Application provide code for a basic KAREL server application that can be used to
host a socket messaging connection made by a remote client, which could be the KAREL client socket
messaging application shown in A KAREL Client Application .
KAREL Server Application
--
This material is the joint property of Fanuc Robotics Corporation and
--
FANUC LTD Japan, and must be returned to either Fanuc Robotics
--
Corporation or FANUC LTD Japan immediately upon request. This material
--
and the information illustrated or contained herein may not be
--
reproduced, copied, used, or transmitted in whole or in part in any way
--
without the prior written consent of both Fanuc Robotics and FANUC.
--
--
All Rights Reserved
--
Copyright (C) 2000
--
Fanuc Robotics Corporation
--
FANUC LTD Japan
--
Karel is a registered trademark of
--
Fanuc Robotics Corporation
--
+
--
Program: tcpserv3.kl - Program for TCP Messaging
--
--
Description:
--
--
This program serves as an example on how to use TCP messaging and write
--
a server Karel program.
--
--
Authors: Fanuc Robotics Corporation
--
3900 West Hamlin
--
Rochester Hills, MI 48309
--
--
Modification history:
--
-------------------------------------------------------------------------------
PROGRAM tcpserv3
%STACKSIZE = 4000
%NOLOCKGROUP
%NOPAUSE=ERROR+COMMAND+TPENABLE
%ENVIRONMENT uif
11-14
MARRC75KR07091E Rev D
11. SOCKET MESSAGING
%ENVIRONMENT sysdef
%ENVIRONMENT memo
%ENVIRONMENT kclop
%ENVIRONMENT bynam
%ENVIRONMENT fdev
%ENVIRONMENT flbt
%INCLUDE klevccdf
%INCLUDE klevkeys
%INCLUDE klevkmsk
-------------------------------------------------------------------------------
VAR
file_var : FILE
tmp_int
: INTEGER
tmp_int1 : INTEGER
tmp_str
: STRING[128]
tmp_str1 : STRING[128]
status
: INTEGER
entry
: INTEGER
-------------------------------------------------------------------------------
BEGIN
SET_FILE_ATR(file_var, ATR_IA)
-- set the server port before doing a connect
SET_VAR(entry, ’*SYSTEM*’,’$HOSTS_CFG[3].$SERVER_PORT’,59002,status)
WRITE(’Connecting..’,cr)
MSG_CONNECT(’S3:’,status)
WRITE(’ Connect Status = ’,status,cr)
IF status = 0 THEN
-- Open S3:
WRITE (’Opening’,cr)
FOR tmp_int1 = 1 TO 20 DO
OPEN FILE file_var (’rw’,’S3:’)
status = IO_STATUS(file_var)
WRITE (status,cr)
IF status = 0 THEN
-- write an integer
FOR tmp_int = 1 TO 1000 DO
WRITE(’Reading’,cr)
-- Read 10 bytes
BYTES_AHEAD(file_var, entry, status)
WRITE(entry, status, cr)
READ file_var (tmp_str::10)
status = IO_STATUS(file_var)
WRITE (status, cr)
11-15
11. SOCKET MESSAGING
MARRC75KR07091E Rev D
-- Write 10 bytes
WRITE (tmp_str::10, cr)
status = IO_STATUS(file_var)
WRITE (status, cr)
ENDFOR
CLOSE FILE file_var
ENDIF
ENDFOR
WRITE(’Disconnecting..’,cr)
MSG_DISCO(’S3:’,status)
WRITE(’Done.’,cr)
ENDIF
END tcpserv3
11.6.4
ANSI C Loopback Client Example
ANSI C UNIX-Based Loopback Client Example provides an example of a UNIX-based loopback
client that can be used to establish a connection with a remote host.
ANSI C UNIX-Based Loopback Client Example
/* BSD Standard Socket Programming Example - UNIX */
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define SERV_TCP_PORT 59002
#define SERV_HOST_ADDR "199.5.148.56"
#define MAXLINE 512
int written(int fd, char *ptr, int nbytes);
int readline(int fd, char *ptr, int maxlen);
void str_cli(int sockfd);
char *pname;
int main(int argc, char *argv[])
{
int sockfd;
struct sockaddr_in serv_addr;
pname = argv[0];
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(SERV_HOST_ADDR);
11-16
MARRC75KR07091E Rev D
11. SOCKET MESSAGING
serv_addr.sin_port = htons(SERV_TCP_PORT);
if((sockfd = socket(AF_INET, SOCK_STREAM,0)) < 0){
printf("Client: Can’t Open Stream Socket\n");
}
printf("Client: Connecting...\n");
if(connect(sockfd,(struct sockaddr *) &serv_addr, sizeof(serv_addr))<0){
printf("Client: Can’t Connect to the server\n");
}
else{
str_cli(sockfd);
}
exit(0);
}
void str_cli (int sockfd)
{
int n, i;
char sendline[MAXLINE], recvline[MAXLINE + 1];
while(1)
{
memset (sendline, 2, 128);
if(written(sockfd, sendline, 126)!=126){
printf("strcli:written error on sock\n");
}
i = readline(sockfd, recvline, 126);
}
}
int readline(int fd, char *ptr, int maxlen)
{
int n, rc;
char c;
for(n = 0; n < maxlen; n++){
if((rc = read(fd, &c, 1)) == 1){
*ptr++ = c;
if(c==’\n’){
break;
}
else if(rc== 0) {
if(n== 0) {
return (0);
}
11-17
11. SOCKET MESSAGING
MARRC75KR07091E Rev D
else{
break;
}
}
}
else{
return (-1);
}
}
*ptr = 0;
return (n);
}
int written(int fd, char
*ptr, int nbytes)
{
int nleft, nwritten;
nleft = nbytes;
while(nleft > 0) {
nwritten = write(fd,
ptr, nleft);
if(nwritten <= 0) {
return(nwritten);
}
nleft -= nwritten;
ptr += nwritten;
}
return(nbytes - nleft);
}
11-18
Chapter 12
SYSTEM VARIABLES
Contents
Chapter 12
SYSTEM VARIABLES
12-1
12.1
ACCESS RIGHTS
12-2
12.2
STORAGE
12-3
12-1
12. SYSTEM VARIABLES
MARRC75KR07091E Rev D
System variables are variables that are declared as part of the KAREL system software. They have
permanently defined variable names that begin with a dollar sign ($). Many system variables are
structure variables , in which case each field also begins with a dollar sign ($). Many are robot
specific, meaning their values depend on the type of robot that is attached to the system.
System variables have the following characteristics:
They have predefined data types that can be any one of the valid KAREL data types.
The initial values of the system variables are either internal default values or variables stored in
the default system variable file, SYSDEF.SV.
When loading and saving system variables from the FILE screen or KCL, the system variable
file name defaults to SYSVARS.SV.
Access rights govern whether or not you can examine or change system variables.
Modified system variables can be saved to reflect the current status of the system.
See Also: Chapter 2 LANGUAGE ELEMENTS for more information on the data types available
in KAREL
12.1
ACCESS RIGHTS
The following rules apply to system variables:
If a system variable allows a KAREL program to read its value, you can use that value in the
same context as you use program variable values or constant values in KAREL programs.
For example, these system variables can be used on the right hand side of an assignment statement
or as a test condition in a control statement.
If a system variable allows a KAREL program to write its value, you can use that system variable
in any context where you assign values to variables in KAREL programs.
The symbols for the program access rights are listed in Table 12-1 . These symbols are given for each
of the system variables in the FANUC Robotics SYSTEM Software Reference Manual .
Table 12-1. Access Rights for System Variables
Access
Meaning
NO
No access
RO
Read only
RW
Read and write
FP
Field protection; if it is a structure variable, one of the first three access rights will apply.
12-2
MARRC75KR07091E Rev D
12. SYSTEM VARIABLES
See Also: FANUC Robotics Software Reference Manual for system variables
12.2
STORAGE
System variables are assigned an initial value upon power up based on
Internal default values
Values stored in the default system variable file, SYSDEF.SV
12-3
Chapter 13
KAREL COMMAND LANGUAGE (KCL)
Contents
Chapter 13
KAREL COMMAND LANGUAGE (KCL)
13-1
13.1
COMMAND FORMAT
13-2
13.1.1
Default Program
13-2
13.1.2
Variables and Data Types
13-3
13.2
PROGRAM CONTROL COMMANDS
13-3
13.3
ENTERING COMMANDS
13-3
13.3.1
Abbreviations
13-4
13.3.2
Error Messages
13-4
13.3.3
Subdirectories
13-4
13.4
COMMAND PROCEDURES
13-4
13.4.1
Command Procedure Format
13-5
13.4.2
Creating Command Procedures
13-6
13.4.3
Error Processing
13-6
13.4.4
Executing Command Procedures
13-6
13-1
13. KAREL COMMAND LANGUAGE (KCL)
MARRC75KR07091E Rev D
The KAREL command language (KCL) environment contains a group of commands that can be used
to direct the KAREL system. KCL commands allow you to develop and execute programs, work with
files, get information about the system, and perform many other daily operations.
The KCL environment can be displayed on the CRT/KB by pressing MENUS (F10) and selecting
KCL from the menu.
In addition to entering commands directly at the KCL prompt, KCL commands can be executed
from command files.
13.1
COMMAND FORMAT
A command entry consists of the command keyword and any arguments or parameters that are
associated with that command. Some commands also require identifiers specifying the object of the
command.
KCL command keywords are action words such as LOAD, EDIT, and RUN. Command
arguments, or parameters, help to define on what object the keyword is supposed to act.
Many KCL commands have default arguments associated with them. For these commands, you
need to enter only the keyword and the system will supply the default arguments.
KCL supports the use of an asterisk (*) as a wildcard, which allows you to specify a group of
objects as a command argument for the following KCL commands:
— COPY
— DELETE FILE
— DIRECTORY
KCL identifiers follow the same rules as the identifiers in the KAREL programming language.
All of the data types supported by the KAREL programming language are supported in KCL.
Therefore, you can create and set variables in KCL.
See Also: Chapter 2 LANGUAGE ELEMENTS , and Chapter 9 FILE SYSTEM ,
13.1.1
Default Program
Setting a program name as a default for program name arguments and file name arguments allows you
to issue a KCL command without typing the name.
The KCL default program can be set by doing one of the following:
Using the SET DEFAULT KCL command
Selecting a program name at the SELECT menu on the CRT/KB
13-2
MARRC75KR07091E Rev D
13. KAREL COMMAND LANGUAGE (KCL)
13.1.2
Variables and Data Types
The KCL> CREATE VARIABLE command allows you to declare variables. The KCL> SET
VARIABLE command permits you to assign values to declared variables. Assigned values can
be INTEGER, REAL, BOOLEAN, and STRING data types. Values can be assigned to particular
ARRAY elements or specified PATH nodes. VECTOR variables are assigned as three REAL values,
and POSITION variables are assigned as six REAL values.
See Also: CREATE VARIABLE and SET VARIABLE KCL commands in Appendix C , “KCL
Command Alphabetical Description”
13.2
PROGRAM CONTROL COMMANDS
KCL commands can be used to run programs. In some cases, these programs may cause motion such
as when a teach pendant program is run or when a KAREL program that calls a teach pendant program
is run. The device from which the KCL command is issued must have motion control in order to do
this. Refer to the $RMT_MASTER description in the FANUC Robotics Software Reference Manual
for more information about assigning motion control to a remote device.
Program control commands:
Can immediately cause robot and/or auxiliary axis motion, or have the potential to cause motion
Can be executed only if a number of conditions are met
The following commands are program control commands:
CONTINUE
RUN
Warning
Be sure that the robot work envelope is clear of personnel before
issuing a program control command or starting a robot that
automatically executes a program at power up. Otherwise, you could
injure personnel or damage equipment.
13.3
ENTERING COMMANDS
You can enter KCL commands only from the CRT/KB.
To enter KCL commands:
13-3
13. KAREL COMMAND LANGUAGE (KCL)
MARRC75KR07091E Rev D
1. Press MENUS (F10) at the CRT/KB.
2. Select KCL.
3. Enter commands at the KCL prompt.
By entering the first keyword of a KCL command that requires more than one keyword, and by
pressing ENTER, a list of all additional KCL keywords will be displayed.
For example, entering DELETE at the KCL prompt will display the following list of possible
commands: “FILE, NODE, or VARIABLE.”
Note The up arrow key can be used to recall any of the last ten commands entered.
13.3.1
Abbreviations
Any KCL command can be abbreviated as long as the abbreviations are unique in KCL. For example,
TRAN is unique to TRANSLATE and ED , to EDIT.
13.3.2
Error Messages
If you enter a KCL command incorrectly, KCL displays the appropriate error message and returns
the KCL> prompt, allowing you to reenter the command. An up arrow (^) indicates the offending
character or the beginning of the offending word.
13.3.3
Subdirectories
Subdirectories are available on the memory card device. Subdirectories allow both memory cards and
Flash disk cards to be formatted on any MS-DOS file system. You can perform all KCL file related
commands on subdirectories. You can nest subdirectories up to many levels. However, FANUC
Robotics does not recommend nesting subdirectories greater than eight levels.
13.4
COMMAND PROCEDURES
Command procedures are a sequence of KCL commands that are stored in a command file (.CF file
type) and can be executed automatically in sequence.
Command procedures allow you to use a sequence of KCL commands without typing them
over and over.
Command procedures are executed using the RUNCF command.
13-4
MARRC75KR07091E Rev D
13. KAREL COMMAND LANGUAGE (KCL)
13.4.1
Command Procedure Format
All KCL commands except RUNCF can be used inside a command procedure. For commands that
require confirmation, you can enter either the command and confirmation on one line or KCL will
prompt for the confirmation on the input line. Confirmation in a Command Procedure displays
CLEAR ALL as the KCL command and YES as the confirmation.
Confirmation in a Command Procedure
Enter command and confirmation on one line:
CLEAR ALL YES
Nesting Command Procedures
Use the following guidelines when nesting command procedures:
Command procedures can be nested by using %INCLUDE filename inside a command procedure.
Nesting of command procedures is restricted to four levels.
If nesting of more than four command procedures is attempted, KCL will detect the error and take
the appropriate action based on the system variable $STOP_ON_ERR. Refer to Section 13.4.3
for more information on $STOP_ON_ERR.
See Also: Section 13.4.3 , “Error Processing”
Continuation Character
The KCL continuation character, ampersand (&), allows you to continue a command entry across
more than one line in a command procedure.
You can break up KCL commands between keywords or between special characters.
For example, use the ampersand (&) to continue a command across two lines:
CREATE VAR [TESTING_PROG.]PICK_UP_PNT &
:POSITION
Comments
Comment lines can be used to document command procedures. The following rules apply to using
comments in command procedures:
Precede comments with two consecutive hyphens ( -- ).
Comments can be placed on a line by themselves or at the end of a command line.
13-5
13. KAREL COMMAND LANGUAGE (KCL)
MARRC75KR07091E Rev D
13.4.2
Creating Command Procedures
A command procedure can be created by typing in the list of commands into a command file and
saving the file. This can be done using the full screen editor.
See Also: EDIT KCL commands, Appendix C , “KCL Command Alphabetical Description”
13.4.3
Error Processing
If the system detects a KCL error while a command procedure is being executed, the system handles
the error in one of two ways, depending on the value of the system variable $STOP_ON_ERR:
If $STOP_ON_ERR is TRUE when a KCL error is detected, the command procedure terminates
and the KCL> prompt returns.
If $STOP_ON_ERR is FALSE, the system ignores KCL errors and the command procedure
runs to completion.
13.4.4
Executing Command Procedures
Each command in a command procedure is displayed as it is executed unless the SET VERIFY OFF
command is used. Each command is preceded with the line number from the command file. However,
if the file is not on the RD: device, the entire command file is read into memory before execution and
line numbers will be omitted from the display.
Command procedures can be executed using the KCL RUNCF command.
13-6
Chapter 14
INPUT/OUTPUT SYSTEM
Contents
Chapter 14
INPUT/OUTPUT SYSTEM
14-1
14.1
USER-DEFINED SIGNALS
14-2
14.1.1
DIN and DOUT Signals
14-2
14.1.2
GIN and GOUT Signals
14-3
14.1.3
AIN and AOUT Signals
14-3
14.1.4
Hand Signals
14-5
14.2
SYSTEM-DEFINED SIGNALS
14-5
14.2.1
Robot Digital Input and Output Signals (RDI/RDO)
14-6
14.2.2
Operator Panel Input and Output Signals (OPIN/OPOUT)
14-6
14.2.3
Teach Pendant Input and Output Signals (TPIN/TPOUT)
14-17
14.3
Serial Input/Output
14-22
14.3.1
Serial Input/Output
14-22
14-1
14. INPUT/OUTPUT SYSTEM
MARRC75KR07091E Rev D
The Input/Output (I/O) system provides user access with KAREL to user-defined I/O signals,
system-defined I/O signals and communication ports. The user-defined I/O signals are controlled in a
KAREL program and allow you to communicate with peripheral devices and the robot end-of-arm
tooling. System-defined I/O signals are those that are designated by the KAREL system for specific
purposes. Standard and optional communications port configurations also exist.
The number of user-defined I/O signals is dependent on the controller hardware and on the types and
number of modules selected.
14.1
USER-DEFINED SIGNALS
User-defined signals are those input and output signals whose meaning is defined by a KAREL
program. You have access to user-defined signals through the following predefined port arrays:
DIN (digital input) and DOUT (digital output)
GIN (group input) and GOUT (group output)
AIN (analog input) and AOUT (analog output)
In addition to the port arrays, you have access to robot hand control signals through KAREL OPEN
and CLOSE HAND statements.
14.1.1
DIN and DOUT Signals
The DIN and DOUT signals provide access to data on a single input or output line in a KAREL
program.
The program treats the data as a BOOLEAN data type. The value is either ON (active) or OFF
(inactive). You can define the polarity of the signal as either active-high (ON when voltage is applied)
or active-low (ON when voltage is not applied).
Input signals are accessed in a KAREL program by the name DIN[n], where ‘‘n’’ is the signal number.
Evaluating DIN signals causes the system to perform read operations of the input port. Assigning a
value to a DIN signal is an invalid operation unless the DIN signal has been simulated. These can
never be set in a KAREL program, unless the DIN signal has been simulated.
Evaluating DOUT signals causes the system to return the currently output value from the specified
output signal. Assigning a value to a DOUT signal causes the system to set the output signal to
ON or OFF.
To turn on a DOUT:
DOUT[n] = TRUE or
14-2
MARRC75KR07091E Rev D
14. INPUT/OUTPUT SYSTEM
DOUT[n] = ON
To turn off a DOUT:
DOUT[n] = FALSE or
DOUT[n] = OFF
You assign digital signals to the ports on I/O devices using teach pendant I/O menus or the KAREL
built-in routine SET_PORT_ASG.
14.1.2
GIN and GOUT Signals
The GIN and GOUT signals provide access to DINs and DOUTs as a group of input or output signals
in a KAREL program. A group can have a size of 1 to 16 bits, with each bit corresponding to an input
or output signal. You define the group size and the DINs or DOUTs associated with a specific group.
The first (lowest numbered) port is the least significant bit of the group value.
The program treats the data as an INTEGER data type. The unused bits are interpreted as zeros.
Input signals are accessed in KAREL programs by the name GIN[n], where“n” is the group number.
Evaluating GIN signals causes the system to perform read operations of the input ports. Assigning a
value to a GIN signal is an invalid operation unless the GIN signal has been simulated. These can
never be set in a KAREL program, unless the GIN signal has been simulated.
Setting GOUT signals causes the system to return the currently output value from the specified output
port. Assigning a value to a GOUT signal causes the system to perform an output operation.
To control a group output, the integer value equivalent to the desired binary output is used. For
example the command GOUT[n] = 25 will have the following binary result “0000000000011001”
where 1 = output on and 0 = output off, least significant bit (LSB) being the first bit on the right.
You assign group signals using teach pendant I/O menus or the KAREL built-in routine
SET_PORT_ASG.
14.1.3
AIN and AOUT Signals
The AIN and AOUT signals provide access to analog electrical signals in a KAREL program. For
input signals, the analog data is digitized by the system and passed to the KAREL program as a
16 bit binary number, of which 14 bits, 12 bits, or 8 bits are significant depending on the analog
module. The program treats the data as an INTEGER data type. For output signals, an analog voltage
corresponding to a programmed INTEGER value is output.
14-3
14. INPUT/OUTPUT SYSTEM
MARRC75KR07091E Rev D
Input signals are accessed in KAREL programs by the name AIN[n], where“n” is the signal number.
Evaluating AIN signals causes the system to perform read operations of the input port. Setting an AIN
signal at the Teach Pendant is an invalid operation unless the AIN signal has been simulated. These
can never be set in a KAREL program, unless the AIN signal has been simulated.
The value displayed on the TP or read by a program from an analog input port are dependent on the
voltage supplied to the port and the number of bits of significant data supplied by the analog-to-digital
conversion. For positive input voltages, the values read will be in the range from 0 to 2**(N-1) -1,
where N is the number of bits of significant data. For 12 bit devices (most FANUC modules), this
is 2**11-1, or 2047.
For negative input voltages, the value will be in the range 2**N - 1 to 2**(N-1) as the voltage varies
from the smallest detectable negative voltage to the largest negative voltage handled by the device.
For 12 bit devices, this is from 4095 to 2048.
An example of the KAREL logic for converting this input to a real value representing the voltage,
where the device is a 12 bit device which handles a range from +10v to -10v would be as follows:
Figure 14-1. KAREL Logic for Converting Input to a Real Value Representing the Voltage
V: REAL
AINP: INTEGER
AINP = AIN[1]
IF (AINP <= 2047) THEN
V = AINP * 10.0 /2047.0
ELSE
V = (AINP - 4096) * 10.0 / 2047
ENDIF
In TPP, the following logic would be used:
R[1] = AI[1]
IF (R[1] > 2047) JMP LBL[1]
R[2] = R[1] * 10
R[2] = R[2] / 2047
JMP LBL[2]
LBL[1]:
R[2] = R[1] - 4096
R[2] = R[2] * 10
R[2] = R[2] / 2047
LBL[2]
R[2] has the desired voltage.
14-4
MARRC75KR07091E Rev D
14. INPUT/OUTPUT SYSTEM
Evaluating AOUT signals causes the system to return the currently output value from the specified
output signal. Assigning a value to an AOUT signal causes the system to perform an output operation.
An AOUT can be turned on in a KAREL program with AOUT[n] = (an integer value). The result
will be the output voltage on the AOUT signal line[n] of the integer value specified. For example,
AOUT[1] = 1000 will output a +5 V signal on Analog Output line 1 (using an output module with 12
significant bits).
You assign analog signals using teach pendant I/O menus or the KAREL built-in routine
SET_PORT_ASG.
14.1.4
Hand Signals
You have access to a special set of robot hand control signals used to control end-of-arm tooling
through the KAREL language HAND statements, rather than through port arrays. HAND signals
provide a KAREL program with access to two output signals that work in a coordinated manner to
control the tool. The signals are designated as the open line and the close line. The system can
support up to two HAND signals.
HAND[1] uses the same physical outputs as RDO[1] and RDO[2].
HAND[2] uses the same physical outputs as RDO[3] and RDO[4].
The following KAREL language statements are provided for controlling the signal, where “n” is the
signal number.
OPEN HAND n activates open line, and deactivates close line
CLOSE HAND n deactivates open line, and activates close line
RELAX HAND n deactivates both lines
14.2
SYSTEM-DEFINED SIGNALS
System-defined I/O signals are signals designated by the controller software for a specific purpose.
Except for certain UOP signals, system-defined I/O cannot be reassigned.
You have access to system-defined I/O signals through the following port arrays:
Robot digital input (RDI) and robot digital output (RDO)
Operator panel input (OPIN) and operator panel output (OPOUT)
Teach pendant input (TPIN) and teach pendant output (TPOUT)
14-5

 

 

 

 

 

 

 

Content      ..     7      8      9      10     ..