Yokogawa DR240 User Manual

Page 112

Advertising
background image

8-14

IM DR231-11E

57

WSACleanup();

58

}

59

}

60
61

int recv_msg(SOCKET so, char *msg, char *buf, int max) {

62
63

int

sum = 0;

64

int

len;

65

int

pos;

66
67

for(;;) {

68
69

len = recv(so, &buf[sum], max - sum, 0);

70
71

if(len == SOCKET_ERROR || len == 0)

72

return(len);

73
74

sum += len;

75
76

buf[sum] = ‘\0’;

77
78

if(buf[sum-1] != ‘\n’)

79

continue;

80
81

for(pos = sum-1; pos > 0; pos—) {

82
83

if(buf[pos-1] == ‘\n’)

84

break;

85

}

86
87

if(!strcmp(msg, “TS0”) || !strcmp(msg, “\x1bT”)) {

88
89

if((pos < sum-1) && (buf[pos] == ‘E’))

90

break;

91

}

92

else if(!strncmp(msg, “FM”, 2)) {

93
94

if((pos+1 < sum-1) && (buf[pos+1] == ‘E’))

95

break;

96

}

97

else break;

98

}

99

return(sum);

100 }

Line 8

Sets the DR's IP address.

Line 9

Specifies the port number to connect.

Line 16 to 21

Command

Line 29

Starts Windows socket (Winsock Ver. 1.1).

Line 31

Creates a socket.

Line 33 to 36

Sets connection destination. inet_addr() and htons() are functions used to convert to
network format.

Line 38

Establishes connection.

Line 40 to 54

Sends a command and receives a response.

Line 55

Closes the socket.

Line 57

Terminates the use of the Windows socket.

Line 61

A function to receive ASCII data.

Line 69

Receives data from the destination. If the connection is down, recv() returns 0.

Line 78 to 79

Reads the response data by line.

Line 81 to 84

Determines the beginning of the last received line. The first character of the last line is
buff[pos].

Line 87 to 97

If the response data are final (all responses have been received with respect to each
command), return to main.

8.4 Ethernet Program

Advertising
This manual is related to the following products: