Solved

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

Posted on 1998-09-19
5
856 Views
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.

0
Comment
Question by:hoosang
  • 3
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
alexo earned 100 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.

0
 

Expert Comment

by:manjucee
ID: 1252900
Hi,
          You can use inport and outport functions defined in dos.h header file.
0
 
LVL 11

Expert Comment

by:alexo
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.
0
 

Expert Comment

by:manjucee
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.
     
0
 
LVL 11

Expert Comment

by:alexo
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.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now