Mitsubishi Electronics fx3u Garage Door Opener User Manual


 
App - 10
MELSEC-F
APPENDIX
App - 10
int main()
{
WORD wVersionRequested=MAKEWORD(1,1); // Winsock Ver 1.1 request
WSADATA wsaData;
int length; // Communication data length
unsigned char s_buf[BUF_SIZE]; // Send buffer
unsigned char r_buf[BUF_SIZE]; // Receive buffer
int rbuf_idx; // Receive data storage head index
int recv_size; // Number of receive data
struct sck_inf sc;
struct sockaddr_in hostdata; // External device side data
struct sockaddr_in FX3UENET_L; // Ethernet block side data
void Sockerror(int); // Error handling function
unsigned long ulCmdArg ; // Non-blocking mode setting flag
sc.my_addr.s_addr=htonl(INADDR_ANY); // External device side IP address
sc.my_port=htons(0); // External device side port number
sc.FX_IP_addr.s_addr=inet_addr("172.16.56.99"); // Ethernet block side IP address
// (AC103863h)
sc.FX_port=htons(10000); // Ethernet block side port number
Closeflag=FLAG_OFF; // Connection completion flag off
nErrorStatus=WSAStartup(wVersionRequested,&wsaData); // Winsock Initial processing
if (nErrorStatus!=SOCK_OK) {
Sockerror(ERROR_INITIAL); // Error handling
return (SOCK_NG);
}
printf ("Winsock Version is %ld.%ld\n",HIBYTE(wsaData.wVersion),LOBYTE(wsaData.wVersion));
printf ("FX3U-ENET-L Test Start\n");
socketno=socket(AF_INET,SOCK_STREAM,0); // Create socket for TCP/IP
if (socketno==INVALID_SOCKET){
Sockerror (ERROR_SOCKET); // Error handling
return(SOCK_NG);
}
hostdata.sin_family=AF_INET;
hostdata.sin_port=sc.my_port;
hostdata.sin_addr.s_addr=sc.my_addr.s_addr;
if(bind(socketno,(LPSOCKADDR)&hostdata,sizeof(hostdata))!=SOCK_OK){
// Bind
Sockerror(ERROR_BIND); // Error handling
return(SOCK_NG);
}
FX3UENET_L.sin_family=AF_INET;
FX3UENET_L.sin_port=sc.FX_port;
FX3UENET_L.sin_addr.s_addr=sc.FX_IP_addr.s_addr;
if(connect(socketno,(LPSOCKADDR)&FX3UENET_L,sizeof(FX3UENET_L))!=SOCK_OK){
// Connection (Active open)
Sockerror(ERROR_CONNECT); // Error handling
return(SOCK_NG);
}