Sample Programs For Slave Station; Tcp (When Using Extended Memobus Protocol - YASKAWA MP920 User Manual

Machine controller
Table of Contents

Advertisement

C.2

Sample Programs for Slave Station

C.2.1

TCP (When Using Extended MEMOBUS Protocol)

< Configuration and Setting Example >
MP920 (Master)
IP address: Depends on the Slave (remote) setting.
Port number: Depends on the Slave (remote) setting.
#include <stdio.h>
#include <winsock.h>
#include <winioctl.h>
int
sd;
int
new_sd;
struct
sockaddr_in my;
struct
sockaddr_in dst;
char
sbuf[2048];
char
rbuf[2048];
#define MY_IP
0xC0A8010A   // Local IP address: 192.168.1.10
#define MY_PORT
8000
void main_tcp_Srv(void);
void mk_rsp_data(int*);
int chk_cmd_data(int);
void main_tcp_Srv(void)
{
WSADATAwsadata;
int rc, slen, rlen, send_len, client_addrlen;
// 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 );
// Creates TCP socket.
sd = socket( AF_INET, SOCK_STREAM, 0 );
if ( sd <= 0 ) // A value 0 or less will be returned if an error occurs in processing.
PORT
CN1
Ethernet
// Socket to wait for connection
// Socket for communication after connected
// Work to store local IP address and port number
// Work to store the remote IP address and port number
    // Send buffer
    // Receive buffer
    // Local port number: 8000
C-9
C.2 Sample Programs for Slave Station
Personal computer (Slave)
IP address: 192. 168. 1. 10.
Port number: 8000
C

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents