delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/08/12/10:30:37

From: "nonya" <duck AT tdux DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Trying to get code to compile and getting errors please help.
Date: Tue, 12 Aug 2003 10:21:57 -0400
Organization: VeriSign Global Registry Services
Lines: 490
Message-ID: <bhat0n$fcv$1@news.nsiregistry.net>
References: <bh8nfp$sd7$1 AT news DOT nsiregistry DOT net>
NNTP-Posting-Host: nat.networksolutions.com
X-Trace: news.nsiregistry.net 1060697943 15775 216.168.237.71 (12 Aug 2003 14:19:03 GMT)
X-Complaints-To: news AT nsiregistry DOT net
NNTP-Posting-Date: 12 Aug 2003 14:19:03 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Complete source attached.  This is supposed to be for Microsoft visual c++
version 1.5 or later.  The source is supposed to be compiled to run under
DOS.

Recently I acquired a Symbol pdt 3100 bar code scanner.  (Someone left the
company that was supposed to be working on interfacing the scanner and now
it is dumped on me scenario)  The scanner is supposed to have all the bells
and whistles but from first impressions it sucks!!!!!!  I turned on the
scanning unit and it errored on boot up.  After downloading all the manuals
for this unit and spending several hours reading and skimming this is what I
discovered.  (1)You can download demo software for the unit but it is not
very useful.  (2) If you want the unit to do anything you have to write the
application in C then upload it to the unit.  (3) You can buy their
application builder software for the extra low price of $1999.00.

I downloaded some sample code which does almost exactly what I need it to
do.  I have already done minor modifications to the source code and just
need to get it compiled.  I do not know much about programming but am up for
the challenge.  The last real programming I have done was assembly for the
Commodore 128 and made an attempt to learn C++ about 10 years ago.  I am
fairly good at Unix shell programming and know a little perl.  If I can get
this code to compile I can use it to build on and achieve the desired goals.
Any help on this would be GREATLY appreciated!!!!!



/* SAMPLE.C */

#include <dos.h>
#include <fcntl.h>
#include <graph.h>
#include <io.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys\types.h>
#include <sys\timeb.h>
#include <sys\stat.h>

#pragma pack(1)

#include <3000\bios.h>
#include <3000\dos.h>
#include <3000\urm.h>

#define CON_KEY_ONLY          0
#define CON_KEY_OR_SCAN       1
#define CON_SCAN_ONLY         2
#define ERROR                 -1
#define ERROR_DETECTED        1
#define ERROR_NO              0
#define KEY_CLEAR             0x001B
#define KEY_BACKSPACE         0x0008
#define NO                    0
#define VIDEO_NORMAL          0x07
#define VIDEO_INVERSE         0x70
#define YES                   1

struct detail_rec {
  char number[64];
  short quantity;
  };

/* GLOBAL VARIABLES */
int con_handle;
char store_number[6];

/* FUNCTION DECLARATIONS */
void CollectData(void);
void EraseData(void);
short Initialize(void);
short MainMenu(short);
void TransmitData(void);
void GetData(unsigned char, short, short, short, char *);

/* MAIN ROUTINE (BEGINNING OF THE C PROGRAM) */
main(int argc, char *argv)
{
short errorlevel;
short selection;

if ( (errorlevel = Initialize()) == ERROR_NO ) {
  for ( selection = 1; selection; ) {
    switch ( selection = MainMenu(selection) ) {
      case 1:
 CollectData();
 break;
      case 2:
 CollectData2();
 break;
      case 3:
 TransmitData();
 break;
      case 4:
 EraseData();
 break;
      case 5:
 exit(0);


}
    }
  }
exit(errorlevel);
}

/* INITIALIZATION ROUTINE */
/* - SETS UP THE COMMUNICATION PROTOCOL AND PORT PARAMETERS */
short Initialize(void)
{
SEPCHART com_inp_separators;
SEPCHART com_out_separators;
unsigned int device_info;
short errorlevel;
int handle;
IoctlT ioctl;

errorlevel = ERROR_NO;
if ( DosOpen("CON", READWRITE, &con_handle) != 0 )
  errorlevel = ERROR_DETECTED;
else {
  DosIoCtrlSetInfo(con_handle, DosIoCtrlGetInfo(con_handle) | RAWMODE);
  ioctl.funcode = ConsIoctlGetScanParms;
  DosIoCtrlRdData(con_handle, &ioctl, ConsIoctlScanParamLen);
  ioctl.data.scanparms.inactivetime = 30;
  ioctl.data.scanparms.initscantime = 10;
  ioctl.data.scanparms.subsscantime = 5;
  ioctl.data.scanparms.postdecodeact = 1;
  ioctl.data.scanparms.decodefailact = 1;
  ioctl.data.scanparms.labeltermchar = '\r';
  ioctl.data.scanparms.beepondecode = YES;
  ioctl.data.scanparms.beeptime = 100;
  ioctl.funcode = ConsIoctlSetScanParms;
  DosIoCtrlWrData(con_handle, &ioctl, ConsIoctlScanParamLen);
  }
if ( !errorlevel )
  if ( DosOpen("COM1", READWRITE, &handle) != 0 )
    errorlevel = ERROR_DETECTED;
  else {
    device_info = DosIoCtrlGetInfo(handle);
    DosIoCtrlSetInfo(handle, device_info | RAWMODE);
    ioctl.funcode = ComIoctlSelectProtCmd;
    DosIoCtrlRdData(handle, (char *)&ioctl, ComIoctlSelectProtLen);
    ioctl.funcode = ComIoctlSelectProtCmd;
    ioctl.data.selectprotocol.protocol = MSISTD;
    DosIoCtrlWrData(handle, (char *)&ioctl, ComIoctlSelectProtLen);
    ioctl.funcode = ComIoctlComParamCmd;
    DosIoCtrlRdData(handle, (char *)&ioctl, ComIoctlComParamLen);
    ioctl.data.comparameters.databits = DATABITS8;   // was 7.
    ioctl.data.comparameters.parity = PARITYEVEN;
    ioctl.data.comparameters.flowctl = SOFTWAREFLOWCTL;
    ioctl.data.comparameters.baudrate = BAUD9600;
    ioctl.data.comparameters.stopbits = STOPBITS1;
    ioctl.data.comparameters.duplex = DUPLEXFULL;
    ioctl.data.comparameters.modemdelay = 0;
    ioctl.data.comparameters.dsrwait = 0;        // was 30,  change for
serial printer
    ioctl.data.comparameters.cdwait = 0;         // was 30,  change for
serial printer
    ioctl.data.comparameters.linecondflags = CTSCOND;
    ioctl.data.comparameters.rxcharwait = 30;
    ioctl.funcode = ComIoctlComParamCmd;
    DosIoCtrlWrData(handle, (char *)&ioctl, ComIoctlComParamLen);
    DosClose(handle);
    }
if ( !errorlevel ) {
  BiosClrScr(VIDEO_NORMAL);
  BiosPutStrMove(0, 5, 10, "SAMPLE 1.0", VIDEO_NORMAL);
  BiosPutStrMove(2, 0, 6, "STORE:", VIDEO_NORMAL);
  GetData(CON_KEY_OR_SCAN, 2, 7, 5, store_number);
  }
return(errorlevel);
}

/* MAIN MENU ROUTINE */
/* - DISPLAY THE MENU ENTRIES, PROMPT FOR A SELECTION */
short MainMenu(short selection)
{
static char *menu_entry[] = {
  "1 = Asset initial",
  "2 = Asset daily",
  "3 = Send Data",
  "4 = Erase Data",
  "5 = Exit",
 };

char choice[2];
unsigned char line;
short loop;
short valid;

  BiosClrScr(VIDEO_NORMAL);
  BiosPutStrMove(0, 5, 9, "MAIN MENU", VIDEO_NORMAL);
for (line = 2, loop = 0; loop < 5; loop++, line++ )
  BiosPutStrMove(line, 1, strlen(menu_entry[loop]), menu_entry[loop],
VIDEO_NORMAL);
  BiosPutStrMove(7, 2, 14, "Please select:", VIDEO_NORMAL);
for ( valid = NO; !valid; ) {
  GetData(CON_KEY_ONLY, 7, 17, 1, choice);
  selection = atoi(choice);
  if ( selection >= 1 && selection <= 5 )
    valid = YES;
  else
    BiosBeep(300);
  }
return(selection);
}

/* DATA COLLECTION ROUTINE */
/* - COLLECTS Serial/Asset/Location RECORDS UNTIL BLANK ITEM NUMBER IS
ENTERED */
void CollectData(void)
{
char data_entry[66];
short error_detected;
int handle;
struct detail_rec item;
short quit;

if ( (handle = open("D:DATAFILE.DAT", O_WRONLY | O_CREAT | O_BINARY, S_IREAD
| S_IWRITE)) != ERROR )
{
  BiosClrScr(VIDEO_NORMAL);
  BiosPutStrMove(0, 4, 12, "COLLECT DATA", VIDEO_NORMAL);
  for ( error_detected = quit = NO; !error_detected && !quit; )
 {
    BiosPutStrMove(1, 0, 9, "Serial #:", VIDEO_NORMAL);
    BiosPutStrMove(3, 0, 9, "Asset ID:", VIDEO_NORMAL);
    BiosPutStrMove(5, 0, 10, "Location:", VIDEO_NORMAL);
   GetData(CON_KEY_OR_SCAN, 2, 0, 18, data_entry);
    if ( strlen(data_entry) == 0 )
      quit = YES;
    else {
      strncpy(item.number, data_entry, 18);
      GetData(CON_KEY_OR_SCAN, 4, 0, 18, data_entry);
      strncpy(item.number, data_entry, 18);
      GetData(CON_KEY_OR_SCAN, 6, 11, 10, data_entry);
   item.quantity = atoi(data_entry);
      if ( write(handle, (unsigned char *)&item, sizeof(item)) !=
sizeof(item) ) {
 error_detected = YES;
 BiosBeep(300);
       }
   }
  }
  close(handle);
  }
}

/* DATA COLLECTION ROUTINE */
/* - COLLECTS ITEM/QUANTITY RECORDS UNTIL BLANK ITEM NUMBER IS ENTERED */
void CollectData2(void)
{
char data_entry[66];
short error_detected;
int handle;
struct detail_rec item;
short quit;

if ( (handle = open("D:DATAFILE.DAT", O_WRONLY | O_CREAT | O_BINARY, S_IREAD
| S_IWRITE)) != ERROR )
{
  BiosClrScr(VIDEO_NORMAL);
  BiosPutStrMove(0, 4, 12, "COLLECT DATA", VIDEO_NORMAL);
  for ( error_detected = quit = NO; !error_detected && !quit; )
 {
  BiosPutStrMove(1, 0, 9, "Asset ID:", VIDEO_NORMAL);
    BiosPutStrMove(4, 0, 10, "Location:", VIDEO_NORMAL);
   GetData(CON_KEY_OR_SCAN, 2, 0, 18, data_entry);
    if ( strlen(data_entry) == 0 )
      quit = YES;
    else {
      strncpy(item.number, data_entry, 18);
      GetData(CON_KEY_OR_SCAN, 5, 11, 10, data_entry);
   item.quantity = atoi(data_entry);
      if ( write(handle, (unsigned char *)&item, sizeof(item)) !=
sizeof(item) ) {
 error_detected = YES;
 BiosBeep(300);
       }
   }
  }
  close(handle);
  }
}

/* DATA TRANSMISSION ROUTINE */
/* - PROMPTS TO VERIFY TRANSMISSION, THEN SENDS THE DATA */
void TransmitData(void)
{
static unsigned char index_table[] = {
  COMDEV, COMDEV, COMDEV | TOMDM, COMDEV | TOSPKR,
  LPTDEV, LPTDEV, LPTDEV | TOCOM1, LPTDEV | TOCOM2
  };
static XlatPtrT tran_table = {
  "COM:\0COM:2\0COM:4\0COM:5\0LPT:\0LPT:1\0LPT:2\0LPT:4\0",
  "AUTO\0COM1\0COM2\0COM2\0LPT1\0LPT1\0LPT1\0LPT1\0",
  index_table
  };

static unsigned char rec_flag;
static int rec_length;
static int rec_number;
static unsigned char rec_type;
static SEPCHART com_sep_inp;
static SEPCHART com_sep_out;
static UrmPtrT urm_com_blk =
  { &com_sep_out, &com_sep_inp, &rec_number, &rec_length, &rec_type,
&rec_flag };

static FCBT fcb_inp = { 0 };
static FCBT fcb_out = { 0 };

unsigned char *buffer_inp;
unsigned char *buffer_out;
char choice[2];
short error_detected;
struct detail_rec item;
int handle;
char message[21];
MODEMCTLT modem_ctl;
int out_bytes;
short selection;
short valid;

BiosClrScr(VIDEO_NORMAL);
BiosPutStrMove(0, 3, 13, "TRANSMIT DATA", VIDEO_NORMAL);
BiosPutStrMove(2, 1, 17, "1 = START SENDING", VIDEO_NORMAL);
BiosPutStrMove(3, 1, 18, "2 = RETURN TO MENU", VIDEO_NORMAL);
BiosPutStrMove(5, 2, 14, "Please select:", VIDEO_NORMAL);
for ( valid = NO; !valid; ) {
  GetData(CON_KEY_ONLY, 5, 17, 1, choice);
  selection = atoi(choice);
  if ( selection >= 1 && selection <= 2 )
    valid = YES;
  else
    BiosBeep(300);
  }
if ( selection == 1 ) {
  BiosClrScr(VIDEO_NORMAL);
  BiosPutStrMove(0, 3, 13, "TRANSMIT DATA", VIDEO_NORMAL);
  error_detected = NO;
  buffer_inp = (unsigned char *)malloc(128);
  buffer_out = (unsigned char *)malloc(128);
  if ( buffer_inp == NULL || buffer_out == NULL )
    error_detected = YES;
  else {
    if ( (handle = open("D:DATAFILE.DAT", O_RDONLY | O_BINARY)) == ERROR )
      error_detected = YES;
    else {
      BiosPutStrMove(2, 0, 13, "CONNECTING...", VIDEO_NORMAL);
      memset(&com_sep_inp, 0, sizeof(com_sep_inp));
      com_sep_inp.TrailerPost = '\n';
      com_sep_inp.NonTrailerPost = '\n';
      memset(&com_sep_out, 0, sizeof(com_sep_out));
      rec_flag = ENDOFREC;
      memset(&modem_ctl, 0, sizeof(modem_ctl));
      modem_ctl.modemtype = ModemV22;
      modem_ctl.dial = NODIAL;
      modem_ctl.dtwait = 2;
      if ( UrmOpen(&fcb_inp, &tran_table, "COM:2", 5, buffer_inp, 128,
OpenForInput, &modem_ctl, &com_sep_inp) != 0 )
 error_detected = YES;
      else {
 if ( UrmOpen(&fcb_out, &tran_table, "COM:2", 5, buffer_out, 128,
OpenForPrint, &modem_ctl, &com_sep_out) != 0 )
   error_detected = YES;
 else {
   BiosPutStrMove(2, 7, 8, "END      ", VIDEO_NORMAL);
   BiosPutStrMove(3, 0, 15, "TRANSMITTING...", VIDEO_NORMAL);
   sprintf(buffer_out, "%5s\r\n", store_number);
   out_bytes = strlen(buffer_out);
   error_detected = UrmWriteField(&fcb_out, buffer_out, out_bytes, NULL,
&urm_com_blk);
   while ( !error_detected && read(handle, (unsigned char *)&item,
sizeof(item)) == sizeof(item) ) {
   sprintf(buffer_out, "%64s,%04d\r\n", item.number, item.quantity);
   out_bytes = strlen(buffer_out);
     if ( UrmWriteField(&fcb_out, buffer_out, out_bytes, NULL, &urm_com_blk)
!= 0 )
       error_detected = YES;
     }
   if ( !error_detected )
     if ( UrmWriteField(&fcb_out, "END\r\n", 5, NULL, &urm_com_blk) != 0 )
       error_detected = YES;
   BiosPutStrMove(3, 9, 6, "END   ", VIDEO_NORMAL);
   UrmClose(&fcb_out, &urm_com_blk);
   }
 UrmClose(&fcb_inp, &urm_com_blk);
 }
      close(handle);
      }
    }
  free(buffer_out);
  free(buffer_inp);
  if ( !error_detected )
    BiosPutStrMove(4, 0, 18, "GOOD - PRESS ENTER", VIDEO_NORMAL);
  else
    BiosPutStrMove(4, 0, 17, "BAD - PRESS ENTER", VIDEO_NORMAL);
  GetData(CON_KEY_OR_SCAN, 4, 18, 1, choice);
  }
}

/* DATA ERASURE ROUTINE */
/* - PROMPTS TO VERIFY ERASURE, THEN DELETES THE DATA FILE */
void EraseData(void)
{
char choice[2];
short selection;
short valid;

BiosClrScr(VIDEO_NORMAL);
BiosPutStrMove(0, 5, 10, "ERASE DATA", VIDEO_NORMAL);
BiosPutStrMove(2, 1, 18, "1 = ERASE ALL DATA", VIDEO_NORMAL);
BiosPutStrMove(3, 1, 18, "2 = RETURN TO MENU", VIDEO_NORMAL);
BiosPutStrMove(5, 2, 14, "Please select:", VIDEO_NORMAL);
for ( valid = NO; !valid; ) {
  GetData(CON_KEY_ONLY, 5, 17, 1, choice);
  selection = atoi(choice);
  if ( selection >= 1 && selection <= 2 )
    valid = YES;
  else
    BiosBeep(300);
  }
if ( selection == 1 ) {
  BiosClrScr(VIDEO_NORMAL);
  BiosPutStrMove(0, 5, 10, "ERASE DATA", VIDEO_NORMAL);
  unlink("D:DATAFILE.DAT");
  BiosPutStrMove(2, 0, 20, "ERASED - PRESS ENTER", VIDEO_NORMAL);
  GetData(CON_KEY_OR_SCAN, 4, 18, 1, choice);
  }
}

/* GET DATA ROUTINE */
/* - A CRUDE BUT USEFUL ROUTINE TO MANAGE DATA ENTRY BY KEYBOARD OR SCANNER
*/
void GetData(unsigned char mode, short line, short column, short width, char
*data_buffer)
{
char blanks[65];
int bytes;
char character[2];
char *data;
IoctlT ioctl;
short key_pressed;

memset(blanks, ' ', 65);
blanks[width] = '\0';
memset(data = data_buffer, 0, width + 1);
ioctl.funcode = ConsIoctlSetInputMode;
ioctl.data.inputmode.inmode = mode;
ioctl.data.inputmode.labeltimeout = 30;
DosIoCtrlWrData(con_handle, &ioctl, ConsIoctlSetInputModeLen);
do {
  BiosPutStrMove((unsigned char)line, (unsigned char)column, strlen(blanks),
blanks, VIDEO_NORMAL);
  if ( strlen(data_buffer) )
    BiosPutStrMove((unsigned char)line, (unsigned char)column,
strlen(data_buffer), data_buffer, VIDEO_NORMAL);
  BiosSetCursorPos((unsigned char)line, (unsigned char)(column +
strlen(data_buffer)));
  DosRead(con_handle, character, 1, &bytes);
  if ( !(key_pressed = character[0]) ) {
    DosRead(con_handle, character, 1, &bytes);
    key_pressed = character[0];
    key_pressed = key_pressed << 8;
    }
  switch ( key_pressed ) {
    case KEY_CLEAR:
      memset(data = data_buffer, 0, width + 1);
      break;
    case KEY_BACKSPACE:
      if ( strlen(data_buffer) == 0 )
 BiosBeep(300);
      else
 *--data = '\0';
      break;
    default:
      if ( key_pressed != '\r' )
 if ( strlen(data_buffer) == width )
   BiosBeep(300);
 else
   *data++ = key_pressed;
      break;
    }
  } while ( key_pressed != '\r' );
}


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019