![North Atlantic 8810A Programmer'S Reference Manual Download Page 37](http://html.mh-extra.com/html/north-atlantic/8810a/8810a_programmers-reference-manual_1707615037.webp)
Soft Panel Program
5 API-8810A Ethernet Protocol
The 8810A Ethernet interface supports only the API-8810A Language. Sending commands via
the Ethernet interface requires the creation and connection via a TCP/IP socket.
The following code snippet,
CreateClientSocket()
from the API8810ADll (Ethernet.cpp)
makes calls to the Winsock API to create and connect a TCP/IP socket to send commands to the
8810A. Note the code utilizes the
PingHost()
call to make sure that the IP address specified for
the 8810A is reachable before attempting to create the socket. This avoids waiting for the socket
timeout in the
connect()
call if the device is not reachable. The code snippet,
CloseClientSocket()
closes the socket connection.
int
CreateClientSocket(
char
*pszIPAddr,
int
nPort, SOCKET* s)
{
WSADATA wsaData;
SOCKET sock;
SOCKADDR_IN ServerAddr;
int
result;
/* Before trying to make a connection to the server, ping it to make sure it's reachable */
result = PingHost(pszIPAddr);
if
(result != 0)
return
ETHER_CANNOT_ESTABLISH_CONNECTION;
// Initialize Winsock version 2.2
WSAStartup(MAKEWORD(2,2), &wsaData);
// Create a new socket to make a TCP client connection
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
setsockopt( sock, SOL_SOCKET, SO_RCVTIMEO, (
char
*)&RECEIVE_TIMEOUT,
sizeof
(
int
) );
setsockopt( sock, SOL_SOCKET, SO_SNDTIMEO, (
char
*)&SEND_TIMEOUT,
sizeof
(
int
) );
// set to no_delay to insure quick ack
result = setsockopt( sock, IPPROTO_TCP, TCP_NODELAY, (
char
*)&NO_DELAY,
sizeof
(
int
) );
// Setup a SOCKADDR_IN structure that will be used to connect
// to the listening server on the Port.
ServerAddr.sin_family = AF_INET;
ServerAddr.sin_port = htons(nPort);
ServerAddr.sin_addr.s_addr = inet_addr(pszIPAddr);
// Make a connection to the server with socket sock
connect(sock, (
const
struct
sockaddr *)&ServerAddr,
sizeof
(ServerAddr));
*s = sock;
Socket = sock;
// put it into global socket
return
ETHER_SUCCESS;
}
int
CloseClientSocket(SOCKET s)
{
closesocket(s);
WSACleanup();
return
ETHER_SUCCESS;
}
After a socket connection is made to the 8810A, device log-in is required. 8810A Ethernet login
is accomplished by sending
“NAII\r\n”
command via the Ethernet connection to the 8810A.
North Atlantic Industries, Inc.
631.567.1100/631.567.1823 (fax) Revision 2.0.0.2
Reference Guide
110 Wilbur Place, Bohemia, NY 11716
www.naii.com
/ e-mail:[email protected]
Page 37 of 50
8810A Programmer’s