EasyManua.ls Logo

YASKAWA MP920 - Sample Programs for Slave Station; TCP (When Using Extended MEMOBUS Protocol

YASKAWA MP920
336 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
C.2 Sample Programs for Slave Station
C-9
C
C.2 Sample Programs for Slave Station
C.2.1 TCP (When Using Extended MEMOBUS Protocol)
#include <stdio.h>
#include <winsock.h>
#include <winioctl.h>
int sd;
// Socket to wait for connection
int new_sd;
// Socket for communication after connected
struct sockaddr_in my;
// Work to store local IP address and port number
struct sockaddr_in dst;
// Work to store the remote IP address and port number
char sbuf[2048];
    // Send buffer
char rbuf[2048];
   
// Receive buffer
#define MY_IP 0xC0A8010A
   // Local IP address: 192.168.1.10
#define MY_PORT 8000
   
// Local port number: 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.
Ethernet
CN1
PORT
MP920 (Master)
Personal computer (Slave)
IP address: Depends on the Slave (remote) setting.
Port number: Depends on the Slave (remote) setting.
IP address: 192. 168. 1. 10.
Port number: 8000
Configuration and Setting Example

Table of Contents

Related product manuals