0 ratings0% found this document useful (0 votes) 388 views20 pagesUser Socket Messaging
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Chapter 9
SOCKET MESSAGING
Contents
Chapter 9 SOCKETMESSAGING ..csscsssnsentennenanttananenenene 949. SOCKET MESSAGING MAROUINS9010171E REV H
The User Socket Messaging Option gives you the benefit of using TCP/IP socket messaging
from KAREL.
Socket Messaging enables data exchange between networked robots and a remote PC with
LINUX, or a UNIX workstation. A typical application of Socket Messaging might be a robot
running a KAREL program that sends process information to a monitoring program on the remote
PC. The combination of PC-Interface option on the robot and PC-Developers Kit on the PC is
recommended for data exchange between the robot and a Windows-based PC.
Socket Messaging uses the TCP/IP protocol to transfer raw data, or data that is in its original,
‘unformatted form across the network. Commands and methods that Socket Messaging uses to
transfer data are part of the TCP/IP protocol. Since Socket Messaging supports client and server
tags, applications requiring timeouts, heartbeats, or data formatting commands can provide these
additional semantics at both the client and server (application) sides of the socket messaging
connection.
Refer to the KAREL Reference Manual for more information,
92Chapter 12
SOCKET MESSAGING
Contents
Chapter 12
124
122
12.2.4
1222
12.2.3
12.3
123.4
1232
123.3
12.4
124.4
12.4.2
12.4.3
124.4
1245
125
SOCKET MESSAGING... . 124
OVERVIEW
SYSTEM REQUIREMENTS 12-2
Overview
Software Rea
Hardware Requirements swvnnennenesnsnmnnsnnnnnnnemnntnennnnns
CONFIGURING THE SOCKET MESSAGING OPTION
Overview
Setting up a Server Tag «.
Setting up a Client Tag ennnnnnennmnnesnnmnnnnnnnnntiemnntineennnnse
SOCKET MESSAGING AND KAREL
Overview
MSG_CONNECT( siring, integer)
a ee
MSG_PING( string, integer ) ve
Exchanging Data during a Socket Messaging Connection
NETWORK PERFORMANCE seven
OVERVIEW snnnerennrenmmnneneennmnnntninnnnnnnnnnenninnnnntt
Guidelines for a Good implementation
PROGRAMMING EXAMPLES
AKAREL Client Application -..nnnnnnnnommnnnnnnnnnnnnnnnn
A KAREL Server Application
ANSI-C Loopback Client Exampie
12412. SOCKET MESSAGING MARRC75KR07091E Rev L
12.1 OVERVIEW
The User Socket Messaging Option gives you the benefit of using TCP/IP socket messaging from
KAREL.
Socket Messaging enables data exchange between networked robots and a remote PC with LINUX, or
a UNIX workstation, A typical application of Socket Messaging might be a robot running a KAREL
program that sends process information to a monitoring program on the remote PC. The combination
of PC-Interface option on the robot and PC-Developers Kit on the PC is recommended for data
exchange between the robot and a Windows-based PC.
Socket Messaging uses the TCP/IP protocol to transfer raw data, or data that is in its original,
unformatted form across the network. Commands and methods that Socket Messaging uses to transfer
data are part of the TCP/P protocol. Since Socket Messaging supports client and server tags,
applications requiring timeouts, heartbeats, or data formatting commands can provide these additional
semantics at both the client and server (application) sides of the socket messaging connection.
12.2, SYSTEM REQUIREMENTS
12.2.1 Overview
This section contains information about the compatibility of socket messaging with some typical
network software, transmission protocols, and interface hardware
12.2.2 Software Requirements
Socket Messaging is compatible with all other Internet Options including DNS, FTP, Web Server,
and Telnet,
Note Client and Server tags are shared between Socket Messaging and other supported protocols
such as FTP, For example, a tag can be set for either FTP operation. or for SM (Socket Messaging)
operation.
12.2.3 Hardware Requirements
Socket Messaging is compatible with all network hardware configurations that use the TCPP
network protocol, Some of these network hardware configurations include Ethemet, serial PPP
connections and PPP modem connections.
12-2MARRC75KRO7091E Rev L 12. SOCKET MESSAGING
12.3. CONFIGURING THE SOCKET MESSAGING OPTION
12.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 messag
+ On the client,
— The IP address or name of your server
— The port on the server that you want to use for socket messaging.
to set up a Socket
Use Procedure 12-1 to set up a Socket Messaging Server Tag. Use Procedure 12.
Messaging Client Tag,
Note The server port at which the server listens on should mateh the port the client tries to connect on.
12.3.2 Setting up a Server Tag
‘You need configure the server tags you want to use for socket messaging. Use Procedure 12-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 TCPAP,
need to undefine the tags before they can be used for socket messaging. After making sure thet
‘want to use is not critical to another component of your network, you must undefine the tag.
Procedure 12-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
4. Cold start the controller.
On the teach pendant, press and hold the SHIFT and RESET keys. Or, on the operator
panel, press and hold RESET.
bb. While still pressing SHIFT and RESET on the teach pendant (or RESET on the operator
panel), turn on the power disconnect circuit breaker.
a
©. Release all of the keys.
12-312. SOCKET MESSAGING MARRC75KR07091E Rev L
2, On the teach pendant, Press MENU,
3. Select SETUP,
4, Press Fl, [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.
UNDEFIN
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 MENU.
b._ Select NEXT.
Select SYSTEM, and press Fl, [TYPE].
d. Select Variables.
124MARRC75KRO7091E Rev L 12. SOCKET MESSAGING
@. Move the cursor to SHOSTS_CFG, and Press ENTER.
£ 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.
hh. 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.
12-512. SOCKET MESSAGING MARRC75KR07091E Rev L
12.3.3. Setting up a Client Tag
‘You need configure the client tags you want to use for socket messaging. Use Procedure 12-2 to set up
your server tags. You can also use Procedure 12-2 to undefine tags.
Note Ifthe 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 12-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
4. Cold start the controller
a. On the teach pendant, press and hold the SHIFT and RESET keys. Or, om the operator
panel, press and hold RESET.
. While still pressing SHIFT and RESET on the teach pendant (or RESET on the operator
panel), tum on the power disconnect cirenit breaker
©. Release all of the keys,
2. On the teach pendant, Press MENU,
3. Select SETUP.
4, Press FI, [TYPE]
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.
12-6MARRC75KRO7091E Rev L 12. SOCKET MESSAGING
Current Stat UNDEFINED
s Sta
Server 1P/# [RRER RAAT EERE
‘anonymous
9. Move the cursor to the Protocol Name item, and press F4, [CHOICE].
10. Select SM.
41. 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.
yu must add the remote host and its IP address into the host
Note If you are not using DNS, y
entry table.
14, Press F2, [ACTION], and select DEFINE,
15, Set the system variable:
a. Press MENU.
b. Select NEXT.
¢. Select SYSTEM, and press Fl, [TYPE].
d_ Select Variables.
Move the cursor to SHOSTC_CFG, and press ENTER,
£ Move the cursor to the structure corresponding to the tag selected in Step 8. For
example, if you ate setting up tag C3, move the cursor structure element [3], as shown
in the following screen.
12-712. SOCKET MESSAGING MARRC75KR07091E Rev L
REMOTE
SUSERNAY
SPARD_TIMOUT 0
SERVER _PO!
hh. 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.
12-8MARRC75KRO7091E Rev L 12. SOCKET MESSAGING
12.4. SOCKET MESSAGING AND KAREL
12.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 ot @
server program or application. The Environment fibt statement is required to use any of the listed
built-ins (%ENVIRONMENT fibt).
12.4.2. MSG_CONNECT( string, integer )
MSG_CONNECT 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_CONNECT,
12.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_CONNECT
can be used to establish another connection to the remote server
12-912. SOCKET MESSAGING MARRC75KR07091E Rev L
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 om the client side.
12.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 itis 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 startin 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.
12.4.5 Exchanging Data during a Socket Messaging Connection
Afier 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 detail.
12.5 NETWORK PERFORMANCE
12.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 rn on the controller, the network cabling
configuration, and number of hops that the message will have to make to reach its destination device.
12-10MARRC75KRO7091E Rev L 12. SOCKET MESSAGING
Note Hops is a term that indicates the number of routers between the source host and destination
host. In general, tue 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.
12.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 sep:
This applies to both read and write
rately, instead gather the data and transfer as a larger packet
‘+ You must understand that the rate of data does not flood the remote side.
+ You must understand that there are other nodes on the Ethemet network so performance cannot
be guaranteed
+ You must understand that other applications on robot also use TCP/IP and performance can.
be affected,
12.6 PROGRAMMING EXAMPLES
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 ANST C language,
Note The KAREL examples assume the appropriate tags (C2 for client and $3 for Server) have been
setup for socket messaging using Procedure 12-1 and Procedure 12-2
12.6.2 A KAREL Client Application
AKAREL Client Application provides code for a basic KAREL client application that can be used to
establish a socket messaging connection to a remote host, wiiich could be the KAREL server socket
‘messaging application shown in KAREL Server Application
AKAREL Client Application
12-1112. SOCKET MESSAGING MARRC75KR07091E Rev L
a vagiate:
coxparation
wam for TCE Mesea:
use TCP messaging
12-12MARRC75KRO7091E Rev L 12. SOCKET MESSAGING
12-1312. SOCKET MESSAGING MARRC75KR07091E Rev L
12.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
12.14MARRC75KRO7091E Rev L 12. SOCKET MESSAGING
12-1512. SOCKET MESSAGING MARRC75KR07091E Rev L
12.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
12-16MARRC75KRO7091E Rev L 12. SOCKET MESSAGING
12-4712. SOCKET MESSAGING MARRC75KR07091E Rev L
m7
12-18