App - 10 App - 10
MELSEC-F
APPENDIX
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;
// 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 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.sin_family=AF_INET;
FX3UENET.sin_port=sc.FX_port;
FX3UENET.sin_addr.s_addr=sc.FX_IP_addr.s_addr;
if(connect(socketno,(LPSOCKADDR)&FX3UENET,sizeof(FX3UENET))!=SOCK_OK){
// Connection (Active open)
Sockerror(ERROR_CONNECT);
// Error handling
return(SOCK_NG);
}
Содержание FX3U-ENET
Страница 1: ...USER S MANUAL FX3U ENET ...
Страница 2: ......
Страница 159: ...8 6 8 6 MELSEC F 8 COMMUNICATION USING MC PROTOCOL MEMO ...
Страница 295: ...App 25 App 25 MELSEC F APPENDIX MEMO ...
Страница 297: ......