Rockwell Automation 1771-DMC_DMC1_DMC4_DXPS Control Coprocessor User Manual User Manual

Page 121

Advertising
background image

Chapter 7

Using the Serial Ports

7-13

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

* The sg_parity is a bitfield of 8 bits.

* Bits 0 and 1, indicate parity. 00 = no parity

* 01 = odd parity

* 11 = even parity

* Bits 2 and 3, indicate bits/character. 00 = 8 bits/char

* 01 = 7 bits/char

* 10 = 6 bits/char

* 11 = 5 bits/char

* Bits 4 and 5, indicate stop bits. 00 = 1 stop bit

* 01 = 1 1/2 stop bits

* 10 = 2 stop bits

* Bits 6 and 7 are reserved.

* The sg_baud is the baud rate variable (one byte field).

* 0 = 50 baud 6 = 600 baud C = 4800 baud

* 1 = 75 baud 7 = 1200 baud D = 7200 baud

* 2 = 110 baud 8 = 1800 baud E = 9600 baud

* 3 = 134.5 baud 9 = 2000 baud F = 19200 baud

* 4 = 150 baud A = 2400 baud 10 = 38400 baud

* 5 = 300 baud B = 3600 baud FF = external

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

/*** Set the options ***/

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

{

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

return(-1);

}

/*** Make sure transmitter is off ***/

if ((status = _ss_enrts(path)) == -1)

{

fprintf(stderr, “**** ERROR on disabling transmitter! ***\n”);

return(-1);

}

/*** Make sure buffer is empty ***/

if ((size = _gs_rdy(path)) != -1) /* Is it empty? */

{

while (size--)

if ((status = read(path, &buff, 1)) == -1) /* Clear it out */

{

fprintf(stderr, “**** ERROR reading input buffer! ***\n”);

return(-1);

}

}

return(0); /* Everything ok */

} /* End of function */

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

* r e a d _ 4 8 5 . c

* PURPOSE: Read characters from a serial port configured for RS-485.

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

* USAGE: This function reads characters from a port configured for RS-485.

* Because RS-485 reads are no different than a normal read()

* function, this read_485 function merely makes a normal read()

* call. This function is only included to pair with the write_485()

* function. The write_485() function is quite different than a

* normal write() function.

* Function returns the number of bytes actually read. A -1 is

* returned if an error occurs. The error code is placed in the

* variable ’errno’.

Advertising