![North Atlantic 8810A Programmer'S Reference Manual Download Page 38](http://html.mh-extra.com/html/north-atlantic/8810a/8810a_programmers-reference-manual_1707615038.webp)
Soft Panel Program
The following code snippets,
Ethernet_WriteMsg()
,
SendEthernetMsg()
and
ReadEthernetMsg()
from the API8810ADll (Ethernet.cpp) makes calls to the Winsock API to
send and receive messages to and from the 8810A.
#define
MSG_MAX_SIZE 1500
/* Maximum number of bytes to send */
#define
RECV_MSG_MAX_SIZE 1500
/* Maximum number of bytes that can be read */
bool
Ethernet_WriteMsg(SOCKET s,
char
* szMsg,
bool
bExpectReply,
char
* pszReply)
{
bool
bSuccess =
false
;
char
aReceiveBuffer[RECV_MSG_MAX_SIZE];
int
nBytesRead = 0;
if
(SendEthernetMsg(s, &szMsg[0], strlen(szMsg)) == ETHER_SEND_ERROR)
return
bSuccess;
if
(bExpectReply)
{
if
(ReadEthernetMsg(s, RECV_MSG_MAX_SIZE, aReceiveBuffer, &nBytesRead) == ETHER_RECV_ERROR)
return
bSuccess;
strncpy(pszReply, (
char
*)aReceiveBuffer, nBytesRead);
}
bSuccess =
true
;
return
bSuccess;
}
int
SendEthernetMsg(SOCKET s,
char
*pszMessage,
int
nMessageLen)
{
int
ret;
char
sendbuff[MSG_MAX_SIZE];
int
nLeft;
int
nIndex;
int
status = 0;
// Copy the data to be sent to the buffer
for
(nIndex = 0; nIndex < nMessageLen; +)
sendbuff[nIndex] = pszMessage[nIndex];
nLeft = nMessageLen;
nIndex = 0;
while
(nLeft > 0)
{
ret = send(s, &sendbuff[nIndex], nLeft, 0);
// It seems we sent some data
if
(ret != SOCKET_ERROR)
{
nLeft -= ret;
= ret;
}
// got SOCKET_ERROR
else
{
status = ETHER_SEND_ERROR;
break
;
}
}
if
(nLeft > 0)
status = ETHER_SEND_ERROR;
/* ERROR */
else
status = ETHER_SUCCESS;
/* SUCCESS */
return
status;
}
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 38 of 50
8810A Programmer’s