PRB: _bios_serialcom() May Not Work at 9600 and 4800

Last reviewed: July 17, 1997
Article ID: Q60333
5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50
MS-DOS                      | WINDOWS
kbprg kbprb

The information in this article applies to:

  • The C Run-time (CRT), included with:

        - Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax
        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

In Microsoft C, the function _bios_serialcom() may not work correctly at 4800 or 9600 baud.

CAUSE

This problem is due to the function calling BIOS interrupt 14h.

RESOLUTION

Because _bios_serialcom() uses interrupt 14h to do the work, this is a limitation of the BIOS and not the function. If you want to establish reliable serial communications at a higher baud rate, an interrupt service routine (ISR) should be written to handle the I/O. More information on this can be found in Article 6, pages 167-246 of the "MS-DOS Encyclopedia."

NOTE: The "MS-DOS Encyclopedia" is currently out of print.

MORE INFORMATION

Sample Code

/* Transmitting Machine */
/* Compile options needed: none
*/

#include <stdio.h>
#include <conio.h>
#include <bios.h>

void main(void)
{
   unsigned config;

   config = (_COM_CHR8|_COM_STOP1|_COM_NOPARITY|_COM_9600);
   _bios_serialcom(_COM_INIT,0,config);

   while(1)
      _bios_serialcom(_COM_SEND,0,(unsigned)getch());
}

/* Receiving Machine */
#include <stdio.h>
#include <conio.h>
#include <bios.h>

void main(void)
{
   unsigned config;
   unsigned data;
   config = (_COM_CHR8|_COM_STOP1|_COM_NOPARITY|_COM_9600);
   _bios_serialcom(_COM_INIT,0,config);

   while(1)
      {
      data = 0x0000;
      _bios_serialcom(_COM_RECEIVE,0,data);
      if (data != 0x0000)
         putch((int)data);
      }
}

If the sample programs are run on two separate machines connected by a null modem (serial cable), 9600 baud communication is not possible. At 4800 baud, the data is seriously corrupted on the receiving end. The results are the same when the roles of the machines in question are reversed. However, the function performs well at 300 to 2400 baud.


Additional reference words: 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00
KBCategory: kbprg kbprb
KBSubcategory: CRTIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.