Article View: comp.os.msdos.programmer
Article #299Terminal emulation using _bios_serialcom()
From: Lucio Menzel
Date: Fri, 07 Aug 1992 03:28
Date: Fri, 07 Aug 1992 03:28
91 lines
2924 bytes
2924 bytes
Dear colleagues:
I am trying to write a simple terminal emulation program in C using
Microsoft C 5.1 for MSDOS, tried to use _bios_serialcom() but have
problems with the interpretation of the status returned.
At the end of this message is some C code I wrote (it doesn't work).
Any help with this will be much appreciated. Please reply by e-mail.
Thanks...
Lucio Menzel -- lumenzel@eastern.uucp
-----------------------8<----------------cut----here----------
#include <stdio.h>
#include <conio.h>
#define ESC (char)27
char bCommGetChar(char cPort, char *pc)
{
// check port to see if there is a byte to read,
// if so read it, asign to *pc and return 1.
// If there's no byte to read return 0
unsigned uStatus;
uStatus = _bios_serialcom(_COM_STATUS, cPort - 1, 0);
if (uStatus & ...)
{
uStatus = _bios_serialcom(_COM_RECEIVE, cPort - 1, 0);
if (uStatus & ...)
{
*pc = (char)(uStatus & 0x00ff);
return (char)1;
}
}
return 0;
}
char bCommPutChar(char cPort, char c)
{
// wait until the port is ready and then send the byte
unsigned uStatus;
while (1)
{
uStatus = _bios_serialcom(_COM_STATUS, cPort - 1, 0);
if (uStatus & ...)
break;
}
uStatus = _bios_serialcom(_COM_SEND, cPort - 1, c);
return uStatus & ...;
}
int main(void)
{
char c, cPort = (char)1; // COM1
unsigned uStatus =
_bios_serialcom(
_COM_INIT,
cPort - 1,
_COM_EVENPARITY|_COM_CHR7|_COM_STOP1|_COM_1200
);
if (uStatus & ...)
{
fprintf(stderr, "\7Cant set serial port\n");
return 1;
}
puts("ESC to end");
while (1)
{
if (bCommGetChar(cPort, &c))
putchar(c);
if (kbhit())
{
c = (char)getchar();
if (c == ESC)
break;
if (!bCommPutChar(cPort, c))
printf("error sending %c\n", c);
}
}
return 0;
}
/*EOF*/
Technical Details
Message-ID:
<y604oB2w164w@eastern.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!canrem!telly!moore!eastern!lumenzelShow Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!canrem!telly!moore!eastern!lumenzel From: lumenzel@eastern.COM (Lucio Menzel) Subject: Terminal emulation using _bios_serialcom() Organization: Eastern's Public Access BBS, Toronto CAN Date: Fri, 7 Aug 1992 03:28:21 GMT Message-ID: <y604oB2w164w@eastern.COM> Sender: bbs@eastern.COM (Public Access BBS) Lines: 91