Mitsumi electronic NZ2GF-ETB Network Card User Manual


 
81
CHAPTER 7 COMMUNICATION OF THE ETHERNET ADAPTER MODULE
7
7.1 SLMP Communication and Cyclic Transmission
7.1.5 Connection to the Ethernet
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);
}
EthernetAD.sin_family = AF_INET;
EthernetAD.sin_port = sc.aj_port;
EthernetAD.sin_addr.s_addr = sc.aj_addr.s_addr;
if(connect(socketno, (LPSOCKADDR)&EthernetAD, sizeof(EthernetAD)) != SOCK_OK) {
// Connect (Active open)
Sockerror(ERROR_CONNECT); // Error handling
return (SOCK_NG);
}
Closeflag = FLAG_ON; // Connection end flag on
// Make non-blocking mode active.
ulCmdArg = 1;
ioctlsocket(socketno, FIONBIO, &ulCmdArg); // Set to non-blocking mode
k = 1;
while (k) {
printf("For the Read command, enter 1.\n");
printf("For the Write command, enter 2.\n");
printf("For ending, enter a value other than 1 and 2.\n");
printf(">");
scanf_s("%d", &j);
switch (j) {
case 1:
//Creates a frame requesting for reading RY0000 to RY001F devices (3E frame)
s_buf[0] = 0x50; // Setting subheader
s_buf[1] = 0x00;
s_buf[2] = 0x00; // Setting network number
s_buf[3] = 0xff; // Setting station number
s_buf[4] = 0xff; // Setting request destination module I/O number
s_buf[5] = 0x03;
s_buf[6] = 0x00; // Setting request destination module station number
s_buf[7] = 0x0c; // Setting request data length (12 bytes)
s_buf[8] = 0x00;
s_buf[9] = 0x10; // Setting CPU monitoring timer
s_buf[10] = 0x00;
s_buf[11] = 0x01; // Setting command (batch read of word data)
s_buf[12] = 0x04;
s_buf[13] = 0x00; // Setting subcommand
s_buf[14] = 0x00;
s_buf[15] = 0x00; // Setting device number 000000
s_buf[16] = 0x00;
s_buf[17] = 0x00;
s_buf[18] = 0x9d; // Setting device code (Y)
s_buf[19] = 0x02; // Setting device points (2 words)
s_buf[20] = 0x00;