Appendix C: Program Examples
135
FX
3U
-ENET-ADP User's Manual
B
Ve
rsion
Inform
ation
C
Program
Examples
D
Di
fferences w
ith
FX
3U
-E
N
E
T
E
D
ocum
ent,
oth
ers
Appendix C-1 Program example for communication using MC protocol -1
/ ******************************************************************** /
/ **
** /
/ **
Sample program
** /
/ **
** /
/ **
This program is a sample program to conduct a
** /
/ **
connection test between the Ethernet adapter and ** /
/ **
target device.
** /
/ **
This program accesses the data register (D) of
** /
/ **
the PLC
main unit
installed together with the
** /
/ **
Ethernet adapter.
** /
/ **
** /
/ **
Copyright(C) 2011 Mitsubishi Electric Corporation
** /
/ **
All Rights Reserved
** /
/ **
** /
/ ******************************************************************** /
#include <stdio.h>
#include <winsock.h>
#define FLAG_OFF 0
// Completion flag OFF
#define FLAG_ON 1
// Completion flag ON
#define SOCK_OK 0
// Normal completion
#define SOCK_NG -1
// Abnormal completion
#define BUF_SIZE 4096
// Receive buffer size
#define ERROR_INITIAL 0
// Initial error
#define ERROR_SOCKET 1
// Socket creation error
#define ERROR_BIND 2
// Bind error
#define ERROR_CONNECT 3
// Connection error
#define ERROR_SEND 4
// Send error
#define ERROR_RECEIVE 5
// Receive error
#define ERROR_SHUTDOWN 6
// Shutdown error
#define ERROR_CLOSE 7
// Line close error
//Definitions for checking the receiving sizes
//#define RECV_ANS_1 4
// Receiving size of response message in reply to device write (1E frame)
//#define RECV_ANS_2 24
// Receiving size of response message in reply to device read (1E frame)
typedef struct sck_inf{
struct in_addr my_addr;
unsigned short my_port;
struct in_addr FX_IP_addr;
unsigned short FX_port;
};
int nErrorStatus;
// Error information storage variable
int Dmykeyin;
// Dummy key input
int Closeflag;
// Connection completion flag
SOCKET socketno;
int main()
{
WORD wVersionRequested=MAKEWORD(1,1);
// Winsock Ver 1.1 request
WSADATA wsaData;
int length;
// Communication data length
unsigned char s_buf[BUF_SIZE];
// Send buffer
unsigned char r_buf[BUF_SIZE];
// Receive buffer
int rbuf_idx;
// Receive data storage head index
int recv_size;
// Number of receive data
struct sck_inf sc;
struct sockaddr_in hostdata;
// External device side data
struct sockaddr_in FX3UENETADP;
// Ethernet adapter side data
void Sockerror(int);
// Error handling function
unsigned long ulCmdArg ;
// Non-blocking mode setting flag
Содержание FX3U-ENET-ADP
Страница 1: ...FX3U ENET ADP USER S MANUAL ...
Страница 2: ......
Страница 6: ... 4 Safety Precautions Read these precautions before use MEMO ...
Страница 160: ...154 FX3U ENET ADP User s Manual Revised History Revised History Date Revision Description 2 2012 A First Edition ...
Страница 161: ......