EasyManua.ls Logo

YASKAWA MP3000 Series - Page 368

YASKAWA MP3000 Series
435 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
2.13 Communications with a Windows PC (Visual C++ Application)
Using Automatic Reception with the MP3000 as a Slave
2-350
// Initialize serial number setting
iSerial = 0x00;
// Clear the sockaddr structure (IP address, port number, etc.) with zeros.
memset( (char )&my, 0, sizeof(struct sockaddr));
memset( (char )&dst, 0, sizeof(struct sockaddr));
// Declare the PC’s IP address and port number
my.sin_family = AF_INET;
my.sin_addr.s_addr = myip;
my.sin_port = htons( myport );
// Declare the MP3000’s IP address and port number
dst.sin_family = AF_INET;
dst.sin_addr.s_addr = dstip;
dst.sin_port = htons( dstport );
// Create the TCP or UDP socket
if( trans_prt == TCP_PRT )
{ //TCP
sd = socket( AF_INET, SOCK_STREAM, 0 );
}
else
{ //UDP
sd = socket( AF_INET, SOCK_DGRAM, 0 );
}
if ( sd <= 0 )
{
rc = -1;
return( rc );
}
// Bind the local port number and socket
rc = bind( sd, ( struct sockaddr )&my, sizeof(struct sockaddr_in));
if ( rc == -1 )
{
closesocket( sd );
rc = -2;
return( rc );
}
// Establish connection
if( trans_prt == TCP_PRT )
{ //TCP
rc = connect( sd, ( struct sockaddr )&dst, sizeof(struct sockaddr_in));
if( rc == -1 )
{ //TCP
closesocket( sd );

Table of Contents

Other manuals for YASKAWA MP3000 Series

Related product manuals