Appendix A: D320 PLC Communication Protocol
211
Communication Program Example
The following program is an example program written in C code to demonstrate the D320 PLC open
communications protocol. This program consists of a header, the main program, and various
subroutines. The buffers and a few variables needed to store the communication data are set as global
variables, so that the main function and the various functions may have access. Notes are provided
alongside the main program to help explain the exact purpose and function of the individual parts of
the program.
Note:
This program is provided for illustrative purposes only. It is left to the responsibility of the
user/programmer to ensure that any programs written based on, and using the information
contained in this program, satisfy the requirements of their particular application.
Program
Notes
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
#define PC_ID 0xE2
#define Time_limit 28
#define retrial_limit 2
#define TRUE 1
#define FALSE 0
#define lower_byte(x) (unsigned int) ((x)& 0x00FF)
#define upper_byte(x) (unsigned int) (((x)& 0xFF00)>>8)
typedef int BOOL;
unsigned int PORTADD,DIVISOR,sending_delay, receiving_delay;
unsigned int sending_frame[262],receiving_frame[262];
unsigned int Crc;
unsigned int card,i,ix,iy,smode;
unsigned int port_number;
unsigned int PlcID,OldID;
BOOL Success;
unsigned int data,JobID,retrialC;
unsigned int Old,New,receiving_Index_max,sending_Index_max,index,watchdog;
unsigned int M[128],K[128]; /* Example Register */
void RR_occurring(void);
void Trsport(unsigned int);
unsigned int Recport(void);
BOOL sending_occurring(void);
BOOL receiving_occurring(void);
void Crc16(unsigned int);
void Job(void);
unsigned int communication(void);
void Mword_reading(void);
void Kword_writing(void);
This program was written in Borland
C++. It uses the peripheral device
(PC) to read the M000 to M127
words, and stores them in the K000 to
K127, and then compares the two
registry values and indicates the
results on the screen using the OK or
the FAIL notation. The user may read
or manipulate the various
communication function codes and
the information sent to control the
PLC in various ways.
This program consists of a header, the
main program and various functions.
The buffers and variables needed to
store the communication data are set
as global variables, so that the main
and various other functions may
reference them.
By using the COM1 and COM2 ports
of the computer, serial
communication is possible. By using
the GPU-300 card, parallel
communication is also enabled
(NOTE: The GPU-300 card is not
currently offered by Cutler-Hammer).
The Qs, QAs, RRs, Rs are handled in
the job functions. If there are
communication errors or a frame
breakdown, retry 3 times, then issue a
communication error.
The procedure of the communication,
according to the JobID is:
1. Q sending
2. QA receiving
3. RR sending
4. R receiving
When an error occurs in a frame, a
retransmission should be made.
Major operations of the program
1. Adjusts the initial communication
port and the board rate for
communication. Then initializes the
Summary of Contents for D320 PLC
Page 1: ...D320 PLC User s Manual...
Page 18: ...6 D320 PLC User s Manual...
Page 28: ...16 D320 PLC User s Manual...
Page 34: ...22 D320 PLC User s Manual...
Page 78: ...66 D320 PLC User s Manual...
Page 176: ...164 D320 PLC User s Manual...
Page 210: ...198 D320 PLC User s Manual...
Page 258: ...246 D320 PLC User s Manual...