beautypg.com

Df1 programming example (cont’d) – Rockwell Automation 5370 CVIM Communications Manual User Manual

Page 124

background image

Chapter 5

Using the RS–232 Ports

5–54

/* CVIM RS–232 Communication example program using DF1 protocol */

/* Copyright Allen–Bradley 12-5-89 jrm, aes */

This sample program was compiled using Microsoft C Version 5.1 */

#include

#include

#include

#define STX 0x02 /* Start of Text character */

#define ETX 0x03 /* End of Text character */

#define ENQ 0x05 /* Enquire */

#define DLE 0x10 /* Data Link Escape (Control char) */

#define ACK 0x06 /* Positive acknowledgement */

#define NAK 0x15 /* Negative acknowledgement */

#define COMMFLAGS 0x8E00 /* defines bits to check for comm error */

#define MAX BUFFER

128

/* define storage for configuration data */

unsigned char config [135] [MAX BUFFER] configlen [135]

template [256] [MAX BUFFER] templen [256[

unsigned char last_response = 0;

void main()

{

int x, op_num, portnum, err, replen, reslen, numblocks;

unsigned char reply[200], results[MAX BUFFER];

/* Get Serial port number from user */

printf (”Enter port number (1 for COM1 or 2 for COM2):”);

scanf (”%d”, &portnum));

/* make portnum either 0 or 1 */

portnum = (portnum – 1) & 0x01;

/* Open comm channel to at 9600 baud */

_bios_serialcom (_COM_INIT, portnum–1, _COM_CHR8 | _COM_STOP1 |

_COM_NOPARITY | _COM_9600);

DF1 Programming Example
(cont’d)