delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/18/04:00:27

From: "Spec-Temp, Inc." <spectemp AT bright DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Serial port access problem
Date: Tue, 17 Feb 1998 12:04:21 -0500
Organization: Spec-Temp, Inc.
Lines: 202
Message-ID: <34E9C315.33BC@bright.net>
Reply-To: spectemp AT bright DOT net
NNTP-Posting-Host: paul-cas1-cs-21.dial.bright.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

This is a multi-part message in MIME format.

--------------115C418F1860
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Can someone clue me in as to why this won't work? 

/*
*       bioscom test program
*
*       Use to read data from serial port
*/

#include <stdlib.h>
#include <stdio.h>
#include <bios.h>
#include <dos.h>
#include <conio.h>
#include <pc.h>

#define COM 0           /* serial port number (COM 1)*/
#define CONF 0xba       /* 2400 bps, even parity, 1 stop, 7 data bits */
#define RS232 0x14      /* RS 232 port interrupt number */
#define DATAR 0x100     /* data ready bit in status word */
#define TRUE 1
#define FALSE 0

union REGS inregs, outregs;  /* for ROM BIOS calls */

int main ()
{
    char ch, receive(); /*local declarations*/
    int j;
    init(CONF);		/*initialize port*/
    for(j=0; j<25; j++) /*send something to screen to show it's
running*/
        putch(0x2b);
    clrscr();		
    while(TRUE) {
        if(kbhit()) {	
            ch=getch();
            send(ch);
        }
        if(ready()) {	
            ch=receive();
            putch(ch);	
        }
    }
}

/* init() */
/* initialize serial port */
init(conf)
char conf;
{
    inregs.h.ah = 0;
    inregs.x.dx = COM;
    inregs.h.al = conf;
    int86(RS232, &inregs, &outregs);
}

/* send() */
/* send character to serial port */
send(c)
char c;
{
    inregs.h.ah = 1;
    inregs.x.dx = COM;
    inregs.h.al = c;
    int86(RS232, &inregs, &outregs);
}

/* ready() */
/* get serial port ready status */
ready()
{
   inregs.h.ah = 3;
   inregs.x.dx = COM;
   int86(RS232, &inregs, &outregs);
   return(outregs.x.ax & 0x100);
}

/* receive() */
/* get character from serial port */
char receive()
{
    inregs.h.ah = 2;
    inregs.x.dx = COM;
    int86(RS232, &inregs, &outregs);
    return(outregs.h.al & 0x7f);
}

I am trying to interface a digital gram balance to a PC via RS232. The
PC is a Quantex pentium 166 running Win95. The balance sends a 17 byte
data stream whenever the appropriate key is pressed. I know that the
communication works because I can transfer the information through
ProComm Plus directly reading the serial port. This tells me that the
hardware is ok and the communication settings are correct.

When I execute the above code, neither of the if conditions in main()
ever execute. Any ideas?

Thanks
Brian Miller
Spec-Temp, Inc.

--------------115C418F1860
Content-Type: text/plain; charset=us-ascii; name="Bioscom.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Bioscom.c"

/*
*       bioscom test program
*
*       Use to check port status
*/

#include <stdlib.h>
#include <stdio.h>
#include <bios.h>
#include <dos.h>
#include <conio.h>
#include <pc.h>

#define COM 1           /* serial port number */
#define CONF 0x83       /* 2400 bps, even parity, 1 stop, 7 bits */
#define RS232 0x14      /* RS 232 port interrupt number */
#define DATAR 0x100     /* data ready bit in status word */
#define TRUE 1
#define FALSE 0

union REGS inregs, outregs;  /* for ROM BIOS calls */
int row, col;          /* row and column of cursor position */
char initret, readyret, sendret;

int main ()
{
    char ch, receive();
    int j;
    init(CONF);
    for(j=0; j<25; j++)
        putch(0x2b);
    clrscr();
    printf("Hello world");
    while(TRUE) {
        if( kbhit() ) {
            ch=getch();
            send(ch);
        }
        if(ready()) {
            ch=receive();
            putch(ch);
        }
    }
}

/* init() */
/* initialize serial port */
init(conf)
char conf;
{
    inregs.h.ah = 0;
    inregs.x.dx = COM;
    inregs.h.al = 0xba;
    int86(RS232, &inregs, &outregs);
}

/* send() */
/* send character to serial port */
send(c)
char c;
{
    inregs.h.ah = 1;
    inregs.x.dx = COM;
    inregs.h.al = c;
    int86(RS232, &inregs, &outregs);
}

/* ready() */
/* get serial port ready status */
ready()
{
   inregs.h.ah = 3;
   inregs.x.dx = COM;
   int86(RS232, &inregs, &outregs);
   return(outregs.x.ax & 0x100);
}

/* receive() */
/* get character from serial port */
char receive()
{
    inregs.h.ah = 2;
    inregs.x.dx = COM;
    int86(RS232, &inregs, &outregs);
    return(outregs.h.al & 0x7f);
}


--------------115C418F1860--

- Raw text -


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