Example code for rsć485 communication – Rockwell Automation 1771-DMC_DMC1_DMC4_DXPS Control Coprocessor User Manual User Manual

Page 120

Advertising
background image

Chapter 7

Using the Serial Ports

7-12

Example Code for RSĆ485 Communication

/*****************************************************************************

* i n i t _ 4 8 5 . c

* PURPOSE: Initialize the coprocessor’s serial port for generic serial

* communication using RS-485.

* REVISION LOG: 4/12/94 Original release of program

* 6/30/94 Turned off psc character

* USAGE: This function initializes the serial port properly for doing

* generic RS-485 communication to a coprocessor serial port. The

* function is passed the path of the port. This function then

* turns off all the default terminal settings that may adversely

* effect communications later on. A 0 is returned upon success and

* a -1 if there was a problem. Check the global variable errno

* for the error code reported.

* SYNOPSIS int init_485(path)

* int path; - Path number from opened port

* EXAMPLE:

* path = open(“/t1”, (S_IREAD | S_IWRITE));

* status = init_485(path);

* if (status == -1)

* exit();

****************************************************************************/

/* system include files */

#include <stdio.h>

#include <sgstat.h>

int init_485(path)

int path;

{

char buff; /* Character buffer */

int status; /* Status variable */

int size; /* Size of leftover stuff in input buffer */

struct sgbuf opts; /* Buffer for path descriptor information */

/*** Get the current options ***/

if ((status = _gs_opt(path, &opts)) == -1)

{

fprintf(stderr, “**** ERROR on getting port options! ***\n”);

return(-1);

}

/*** Set the options. This section is not needed with firmaware rel. A/E and later***/

opts.sg_pause = 0; /* Screen pause to off*/

opts.sg_psch = 0; /* No pause character */

opts.sg_bspch = 0; /* No backspace character */

opts.sg_dlnch = 0; /* No delete line character */

opts.sg_rlnch = 0; /* No reprint line character */

opts.sg_dulnch = 0; /* No duplicate last line character */

opts.sg_tabcr = 0; /* No tab character */

opts.sg_echo = 0; /* Echo off */

opts.sg_eorch = 0; /* Ignore end of record */

opts.sg_eofch = 0; /* Ignore end of file */

opts.sg_kbach = 0; /* Keyboard abort off - default = CTRL-E */

opts.sg_kbich = 0; /* Keyboard quit off - default = CTRL-C */

opts.sg_xon = 0xff; /* XON turned off, 0xff is special code for*/

opts.sg_xoff = 0xff; /* copro RS485, it will not interpret 0xff */

opts.sg_parity = 0x00; /* No Parity, 8 Bits, 1 Stop Bit, See below */

opts.sg_baud = 0x0e; /* Baud rate at 9600, See below

Advertising