Yaskawa MP920 Communications Module User Manual
Page 283

C.1 Sample Programs for Master Station
C-7
C
C.1.2 UDP (When Using Extended MEMOBUS Protocol (SFC = 09))
#include
#include
#include
int sd;
/* Socket Discripter */
struct sockaddr_in my;
struct sockaddr_in dst;
struct sockaddr_in from;
#define MY_IP 0xC0A8010A // Local IP address: 192.168.001.010
#define MY_PORT 10010 // Local port number
#define DST_IP 0xC0A80106 // Remote IP address: 192.168.001.006
#define DST_PORT 10020 // Remote port number
unsigned char sbuf[2048];
unsigned char rbuf[2048];
// 218TCP.C
extern
void mk_cmd_data(void);
extern
int chk_rsp_data(int);
void main_udp(void)
{
WSADATAwsadata;
int rc, slen, rlen, fromlen;
// Declaration to use Winsock.dll (Always required at first.)
rc = WSAStartup( 0x0101, &wsadata );
if ( rc != 0 )
{
exit(0);
}
// Clears the sockaddr structure (IP address, port number, etc.) to zero.
memset( (char *)&my, 0, sizeof(struct sockaddr));
memset( (char *)&dst, 0, sizeof(struct sockaddr));
// Declaration of local IP address and port number
my.sin_family = AF_INET;
my.sin_addr.s_addr = htonl( MY_IP );
my.sin_port = htons( MY_PORT );
// Declaration of remote IP address and port number
dst.sin_family = AF_INET;
dst.sin_addr.s_addr = htonl( DST_IP );
Ethernet
CN1
PORT
MP920 (Slave)
Personal computer (Master)
IP address: 192. 168. 1. 6
Port number: 10020
IP address: 192. 168. 1. 10
Port number: 10010
<
Configuration and Setting Example >