Mitsumi electronic NZ2GF-ETB Network Card User Manual


 
80
// Definitions for checking the receiving data size
#define SEND_REQ_1 25 // The size of the request message to be sent for device writing (3E frame, binary)
#define RECV_ANS_1 11 // The size of the response message to be received for device writing (3E frame, binary)
#define SEND_REQ_2 21 // The size of the request message to be sent for device reading (3E frame, binary)
#define RECV_ANS_2 15 // The size of the response message to be received for device reading (3E frame, binary)
typedef struct sck_inf{
struct in_addr my_addr;
unsigned short my_port;
struct in_addr aj_addr;
unsigned short aj_port;
}sck_inf;
int nErrorStatus; // Error information stored in variable
int Dmykeyin; // Dummy key input
int Closeflag; // Connection end flag
int socketno;
int main()
{
WORD wVersionRequested = MAKEWORD(1, 1); // Winsock Ver.1.1 request
WSADATA wsaData;
int j; // For command identification 1
int k; // For command identification 2
int i; // Counter for data display
char disp[2]; // Workspace for data display
char s_buf[BUF_SIZE]; // Send buffer
char r_buf[BUF_SIZE]; // Receive buffer
int length; // Receive data length
int rbuf_idx; // Receive data storage head index
int recv_size; // Total number of receive data
struct sck_inf sc;
struct sockaddr_in hostdata; // External device side data
struct sockaddr_in EthernetAD; // Ethernet adapter module 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's IP address
sc.my_port = htons(0); // External device's port number
sc.aj_addr.s_addr = inet_addr("192.168.3.30"); // Ethernet adapter module's IP address(C0A8031Eh)
sc.aj_port = htons(0x2000); // Ethernet adapter module's port number
Closeflag = FLAG_OFF; // Connection end 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 %1d.%1d\n", HIBYTE(wsaData.wVersion), LOBYTE(wsaData.wVersion));
printf("EthernetAD_test Start\n\n\n");
socketno = socket(AF_INET, SOCK_STREAM, 0); // Creating TCP/IP socket
if(socketno == INVALID_SOCKET) {
Sockerror(ERROR_SOCKET); // Error handling
return (SOCK_NG);
}