Overview 06/2005
Danaher
Motion
8 Rev
E
M-SS-005-03l
The MC
requests a connection from a remote host, according to a specific IP
address and port.
CONNECT
blocks task execution until the connection is
established or until the command fails. To unblock a task waiting in
CONNECT
, close the corresponding socket using
CLOSE
. In addition, killing
a task (
KILLTASK
) blocked by
CONNECT
closes the socket to release the
task.
CONNECT
may fail due to the following reasons:
1.
Invalid socket descriptor
2.
Remote host has no application attached to specified port.
3.
Destination address is not reachable
The following example illustrates a typical procedure of establishing a
connection to a remote host, and sending and receiving data:
OPENSOCKET OPTIONS=0 AS #1
CONNECT (#1,”212.25.84.100”,6002)
PRINT #1,”HELLO”
?INPUT$(LOC(1),#1)
CLOSE #1
1.8.2.3.
MC
A
S
TCP S
ERVER
When acting as a server. the MC endlessly waits for a connection from the
remote host. Use
ACCEPT
when the MC acts as server.
ACCEPT
binds a
socket to a specified port and waits for a connection. Simultaneous
ACCEPT
s on the same port are not allowed.
ACCEPT
blocks the execution
of the calling task until a connection is established. To unblock the task
waiting in
ACCEPT
, close the corresponding socket with
CLOSE
. In addition,
killing a task (
KILLTASK
) blocked in
ACCEPT
closes the socket and
releases the task. The following example illustrates a typical procedure of
waiting for a connection from a remote host, and sending and receiving data:
OPENSOCKET OPTIONS=0 AS #1
ACCEPT (#1,20000)
PRINT #1,”HELLO”
?INPUT$(LOC(1),#1)
CLOSE #1
1.8.3.
Send /Receive Data
Serial and TCP communication use the same commands to send and
receive data. After establishing communication over TCP or after configuring
the serial port communication parameters, send and receive data regardless
the communication type. Data flow differences are communication speed
and the size of the input and output buffers. TCP/IP communication uses
larger communication buffers.
1.8.3.1. R
ECEIVE
D
ATA
The input-buffer of the serial ports is a fixed512 bytes size. User
communication allows receiving strings using
INPUT$
. To check if data is
ready at the input buffer, use
LOC
. The following example checks the
number of bytes available at the input buffers and reads all the available
data:
-->?LOC(1)
11
-->STRING_VAR = INPUT$(11, #1)
-->?STRING_VAR
Hello World