F
Frits JK
Hallo, I have a function in a DLL which is te interface between a xBase
program and a PLC.
most things work fine exept when I send or receive command-string contains a
character 0.
knows any body a solution for this problem.
Frits Janse Kok
//--------------- begin of
code ---------------------------------------------------------------------
extern "C" int PASCAL EXPORT ReadMidi( char const *szIPAddr , char
*Opdracht , char * Antwoord , int *lengte )
{
#define IPPORT_MIDIXP 6768
#define nBuf 255
static SOCKET sock ;
static struct sockaddr_in sa ;
WSADATA WSAData ;
int status;
//-------------- versienummer instellen -------------
if ( WSAStartup( 0x202, &WSAData) != 0 )
{
WSACleanup();
return -1 ;
}
//----------- Call "socket" ( internetprocol, Sock protocol, UDP-IP )
sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP) ;
if (sock < 0)
{
WSACleanup () ;
return -2 ;
}
// ------------- Call "connect" with IP address and time-server port
sa.sin_family = AF_INET ;
sa.sin_port = htons (IPPORT_MIDIXP) ;
sa.sin_addr.S_un.S_addr = inet_addr (szIPAddr) ;
if (connect(sock, (struct sockaddr *) &sa, sizeof(sa)) == SOCKET_ERROR )
{ closesocket (sock) ;
WSACleanup () ;
return -3 ;
}
if ( send(sock, (char*)Opdracht , *lengte , 0) == SOCKET_ERROR )
{ closesocket (sock) ;
WSACleanup();
return -4;
}
status = recv( sock , Antwoord, nBuf , 0 ) ;
closesocket(sock);
WSACleanup();
if (status < 0 ) return -5;
if (status == 0 ) return -6;
*lengte = status;
return 0 ;
}
//--------------------------------------------------------------------------
------------------
program and a PLC.
most things work fine exept when I send or receive command-string contains a
character 0.
knows any body a solution for this problem.
Frits Janse Kok
//--------------- begin of
code ---------------------------------------------------------------------
extern "C" int PASCAL EXPORT ReadMidi( char const *szIPAddr , char
*Opdracht , char * Antwoord , int *lengte )
{
#define IPPORT_MIDIXP 6768
#define nBuf 255
static SOCKET sock ;
static struct sockaddr_in sa ;
WSADATA WSAData ;
int status;
//-------------- versienummer instellen -------------
if ( WSAStartup( 0x202, &WSAData) != 0 )
{
WSACleanup();
return -1 ;
}
//----------- Call "socket" ( internetprocol, Sock protocol, UDP-IP )
sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP) ;
if (sock < 0)
{
WSACleanup () ;
return -2 ;
}
// ------------- Call "connect" with IP address and time-server port
sa.sin_family = AF_INET ;
sa.sin_port = htons (IPPORT_MIDIXP) ;
sa.sin_addr.S_un.S_addr = inet_addr (szIPAddr) ;
if (connect(sock, (struct sockaddr *) &sa, sizeof(sa)) == SOCKET_ERROR )
{ closesocket (sock) ;
WSACleanup () ;
return -3 ;
}
if ( send(sock, (char*)Opdracht , *lengte , 0) == SOCKET_ERROR )
{ closesocket (sock) ;
WSACleanup();
return -4;
}
status = recv( sock , Antwoord, nBuf , 0 ) ;
closesocket(sock);
WSACleanup();
if (status < 0 ) return -5;
if (status == 0 ) return -6;
*lengte = status;
return 0 ;
}
//--------------------------------------------------------------------------
------------------