[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Need to write a DOS program that sends string to COM port!

Posted on 1998-09-19
Medium Priority
Last Modified: 2008-10-01
I need a sample DOS program written in C to send 3 byte string to COM port1 or 2.

Does anyone have a sample code about this issue?

I need the following functions to

open a port
send 3 byte string to a port and wait for return respond
close the port that has been opened.

Question by:hoosang
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 11

Accepted Solution

alexo earned 300 total points
ID: 1252899

If you use MSVC 1.x the bios_serialcom() function is the one you need.  Other compilers may call it differently.  Check <bios.h> fro details.

From the docs:

#include <bios.h>
unsigned _bios_serialcom(unsigned service, unsigned serial_port, unsigned data);
service - Communications service
serial_port - Serial port to use
data - Port configuration bits

The _bios_serialcom routine uses INT 0x14 to provide serial communications services. The serial_port parameter is set to 0 for COM1, to 1 for COM2, and so on.

The _bios_serialcom routine may not be able to establish reliable communications at baud rates in excess of 1,200 baud (_COM_1200) due to the overhead associated with servicing computer interrupts. Faster data communication rates are possible with more direct programming of serial-port controllers. See C Programmer's Guide to Serial Communications for more details on serial-communications programming in C.

The service parameter can be set to one of the following manifest constants:

_COM_INIT - Sets the port to the parameters specified in the data parameter

_COM_SEND - Transmits the data characters over the selected serial port

_COM_RECEIVE - Accepts an input character from the selected serial port

_COM_STATUS - Returns the current status of the selected serial port

The data parameter is ignored if service is set to _COM_RECEIVE or _COM_STATUS. The data parameter for _COM_INIT is created by combining (with the OR operator) one or more of the following constants:

_COM_CHR7 - 7 data bits
_COM_CHR8 - 8 data bits
_COM_STOP1 - 1 stop bit
_COM_STOP2 - 2 stop bits
_COM_NOPARITY - No parity
_COM_EVENPARITY - Even parity
_COM_ODDPARITY - Odd parity
_COM_110 - 110 baud
_COM_150 - 150 baud
_COM_300 - 300 baud
_COM_600 - 600 baud
_COM_1200 - 1200 baud
_COM_2400 - 2400 baud
_COM_4800 - 4800 baud
_COM_9600 - 9600 baud

The default value of data is 1 stop bit, no parity, and 110 baud.

The function returns a 16-bit integer whose high-order byte contains status bits. The meaning of the low-order byte varies, depending on the service value. The high-order bits have the following meanings:

15 - Timed out
14 - Transmission-shift register empty
13 - Transmission-hold register empty
12 - Break detected
11 - Framing error
10 - Parity error
9  - Overrun error
8  - Data ready

When service is _COM_SEND, bit 15 will be set if data could not be sent.

When service is _COM_RECEIVE, the byte read will be returned in the low-order bits if the call is successful. If an error occurs, any of the bits 9, 10, 11, or 15 will be set.

When service is _COM_INIT or _COM_STATUS, the low-order bits are defined as follows:

7 - Receive-line signal detected
6 - Ring indicator
5 - Data set ready
4 - Clear to send
3 - Change in receive-line signal detected
2 - Trailing-edge ring indicator
1 - Change in data-set-ready status
0 - Change in clear-to-send status

Note that this function works only with IBM personal computers and true compatibles.


Expert Comment

ID: 1252900
          You can use inport and outport functions defined in dos.h header file.
LVL 11

Expert Comment

ID: 1252901
>> You can use inport and outport functions defined in dos.h header file.
inport() and outport() perform I/O from the *processor* ports, not the serial ports.

Expert Comment

ID: 1252902
Hi alexo,
                      I   think we can use inport and outport for serial ports also by specifying their address or port ID . isn't it.
LVL 11

Expert Comment

ID: 1252903
Not really.  Although there are processor ports corresponding to the serial ports, there is a protocol involved.  You cannot just dump/read the data using in/out instructions and expect it to work.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question