Rockwell Automation 1771-DMC_DMC1_DMC4_DXPS Control Coprocessor User Manual User Manual
Page 115

Chapter 7
Using the Serial Ports
7-7
******************************************************************************
* FUNCTIONS CALLED BY THIS PROGRAM:
******************************************************************************
* EXTERNAL/LIBRARY FUNCTIONS:
*
* _gs_opt() * get setup of serial port from OS-9
* _gs_rdy() * get number of characters waiting in input buffer
* _ss_enrts() * turn on the RTS line on the serial port
* _ss_opt() * change setup of serial port
* close() * close path to serial port
* exit() * abort program, exiting with status
* memcpy() * copy bar code data from input buffer to global data
* open() * open a path to the bar code reader input port
* printf() * print messages to terminal screen (stdout)
* read() * get characters from input port
* readln() * get
*
* FUNCTIONS (defined in this file):
* NONE
******************************************************************************
* PROGRAMS WHICH CALL THIS PROGRAM:
******************************************************************************
* This program is started by the user from the OS-9 shell “$” prompt
* command line. It loops until terminated by a user
*
******************************************************************************/
#include
#include
#include
#include
#include
#include
#define BARC_PORT “/t2”
/** Makes it easy to change. Even easier to change ***
*** (but harder to program) is to read port name ***
*** from command line using argc, argv. **/
#define BARC_BUF_SIZE 60
/** Not many single line readers can fit that ***
*** many characters within the scan window! **/
main ( )
{
int path; /* OS-9 path number for barcode port */
int sts; /* return status of any given call... */
int recd_chars; /* number of chars gotten from barc. */
struct sgbuf opts_buffer; /* place to store OS-9 path options */
char barc_buf[BARC_BUF_SIZE]; /* data buffer for barcode */
int mfg_loc; /* Manufacturing Location from barcode */
int c, i, n; /* Used to bit-bucket garbage from port */
while ( 1 )
{
/* Open a path to the serial input from the barcode reader */
path = open ( BARC_PORT, ( S_IREAD ) );
if ( path < 0 )
{
/* failure to open path to bar code reader port */
printf ( “BARCODE::Failed to open path to serial port!\n” );
exit ( errno );
}