Cover V10, I05

may2001.tar


Listing 2 serial.c

 * Functions to control the terminal and write Intermec or
 * Zebra command objects to the serial device.
 * Author: Ed Schaefer
 */
#include    <stdio.h>
#include    <sys/types.h>
#include    <sys/termio.h>
#include    <sys/ioctl.h>
#include    <fcntl.h>
#include    "intermec.h" 
#include    "zebra.h" 
#include    "cemarks.h" 

/*
 * Print Serial label
 * 1 for Intermec and 2 for Zebra
 */
int bc_serial(char *lprpath, int baudrate, int printer_choice)
{
   struct termio  otermio;    /* terminal structure */
   int    lpr_fd;  /* file handle */

   if ((lpr_fd = open(lprpath, O_RDWR|O_SYNC)) == -1) 
      {
      printf("error opening port %s\n", lprpath);
      exit(1);
      }
   ioctl(lpr_fd, TCGETA, &otermio);    /* save old settings */
   set_terminal(lpr_fd, baudrate);

   sleep(2);
   if(printer_choice == 1)
      {  /* Intermec Serial */
      printf("Intermec Serial Printer test\n");
      printf("Loading Intermec Graphics CE \n");
      write_load_commands(intermec_ce, lpr_fd); 

      printf("Loading Intermec Format \n");
      write_load_commands(load_intermec_label, lpr_fd); 

      printf("Printing First Intermec Label \n");
      write_load_commands(print_intermec_label1, lpr_fd); 

      printf("Printing Second Intermec Label \n");
      write_load_commands(print_intermec_label2, lpr_fd); 
      }

   if(printer_choice == 2)  
      { /* Zebra Serial */
      printf("Zebra Serial Printer test\n");
      printf("Loading Zebra Graphics CE\n");
      write_load_commands(zebra_ce, lpr_fd);

      printf("Loading Zebra Format \n");
      write_load_commands(load_zebra_label, lpr_fd);

      printf("Printing First Zebra Label \n");
      write_load_commands(print_zebra_label1, lpr_fd);

      printf("Printing Second Zebra Label \n");
      write_load_commands(print_zebra_label2, lpr_fd);
      }

   ioctl(lpr_fd, TCSETA, &otermio);    /* restore terminal settings */
   close(lpr_fd);
}

/*
 * set the terminal to only work with one character 
 */
int set_terminal(int slpr_fd, int baudrate)
{
   struct  termio  ntermio;    /* new terminal charactoristics */

   ioctl(slpr_fd, TCGETA, &ntermio);  /* initialize with old settings */
   ntermio.c_iflag = IGNBRK|INPCK|ISTRIP|IXON|IXOFF;
   if(baudrate == 19200)
      ntermio.c_cflag = B19200|CS7|CREAD|PARENB;
   else
      ntermio.c_cflag = B9600|CS7|CREAD|PARENB;

   ntermio.c_lflag = 0;
   ntermio.c_oflag = 0;
   ntermio.c_line = 0;
   ntermio.c_cc[VMIN] = 1;
   ntermio.c_cc[VTIME] = 0;
   ioctl(slpr_fd, TCSETAF, &ntermio);    /* activate new settings */
} /* end serial.c */

/*