Article View: comp.os.msdos.programmer
Article #1699Re: Help! serial comm problems
From: Stephen B Coy
Date: Fri, 27 Jul 1990 19:51
Date: Fri, 27 Jul 1990 19:51
89 lines
2677 bytes
2677 bytes
In article <487@roo.UUCP>, kurtenba@parc.xerox.com (Gord Kurtenbach) writes:
>
> I'm not a DOS programmer and I`m trying to write a program to read and
> write over the serial port. The basic structure is:
>
> while (1) {
>
> <if there is something to send out then stuff it down the serial port >
>
> <if something has been sent to the serial port then read it>
> }
>
> If some kind soul out there has a stitch of code (C would be great)
> that does what I want I would be most thankful for their help.
>
> Thanks.
>
> Gord Kurtenbach
This is for Microsoft C although I think the only thing you'll need
to change for Turbo C or others is the _bios_serialcom() function
calls. Since its not a standard function everyone has created their
own standards. Hope this helps.
Stephen Coy
uw-beaver!ssc-vax!coy
/*
Test serial port interaction. Keyboard hits are sent across
the serial line, characters received are displayed on the
screen. Hit ESC to exit.
*/
#include <stdio.h>
#include <stdlib.h>
#include <bios.h>
#define COM1 (0)
#define COM2 (1)
#define COM COM1
#define PARITY _COM_NOPARITY
#define BITS _COM_CHR8
#define STOP _COM_STOP1
#define BAUD _COM_9600
main(int ac, char **av)
{
int c, status, error;
/* init serial port, 8bits, 1s stop bit, no parity, 9600 baud */
_bios_serialcom(_COM_INIT, COM, BITS | STOP | PARITY | BAUD);
for(;;) {
/* Is DATA_READY set? If so, grab the character. */
status = 0x0100 & _bios_serialcom(_COM_STATUS, COM, 0);
if(status) {
c = 0x00ff & _bios_serialcom(_COM_RECEIVE, COM, 0);
printf("%c", c);
}
/* Do we have data to send? */
if(kbhit()) {
c = getch();
/* bail if esc as hit */
if(c == 27) {
printf("\n\nbye...\n");
exit(0);
}
/* wait until transmit hold reg empty */
status = 0x2000 &_bios_serialcom(_COM_STATUS, COM, 0);
while(status != 0x2000) {
status = 0x2000 &_bios_serialcom(_COM_STATUS, COM, 0);
}
status = _bios_serialcom(_COM_SEND, COM, c);
if(status & 0x8000) {
fprintf(stderr, "\nError send %c\n", c);
}
} /* end of if kbrd hit loop */
} /* end of forever loop */
} /* end of main */
Technical Details
Message-ID:
<3466@ssc-vax.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cornell!uw-beaver!fluke!ssc-vax!coyReferences:
<487@roo.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cornell!uw-beaver!fluke!ssc-vax!coy From: coy@ssc-vax.UUCP (Stephen B Coy) Newsgroups: comp.os.msdos.programmer Subject: Re: Help! serial comm problems Message-ID: <3466@ssc-vax.UUCP> Date: 27 Jul 90 19:51:18 GMT References: <487@roo.UUCP> Organization: Boeing Aerospace & Electronics, Seattle WA Lines: 89 Keywords: serial communication port RS232