Solved

Serial communications

Posted on 2001-06-05
10
341 Views
Last Modified: 2012-05-04
I want to communicate with a com port using c in ms-dos (send and recieve data).
how do I do that?

I know there are  functions called outportb and inportb, how do I use them and is there any other way to do that?

I'm not using a modem, but a different device, but a modem exampe would also be good.

10x..
0
Comment
Question by:makris
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 3

Expert Comment

by:3rsrichard
ID: 6155950
Each port has 8 registers associated with it.  It's been a long time,
but I think COM1 is at 0x38F and COM2 is at 0x28F.
These registers mirror I/O registers in the UART, and are
used to set baud rate, bits, parity, etc.  Once the UART is set
up you can send a byte by writing to the correct register, and
read by watching the flags then reading a byte.  You either have
to make your program fast enough to handle incoming messages
byte by byte or do an interrupt routine.
There is also a set of DOS interrupts which control the UART, you
might have better luck with those.  You'd have to look them up in
your DOS manual.
Most people who did seious communication under DOS used
a purchased library.

0
 

Author Comment

by:makris
ID: 6156028
do you know such a library?
I know borland has dos.h which has outportb and inportb.

If I understand what you wrote, all I have to do is write the data to the right memory address(0x3f8 for instance), and then read it from the same location?
how do I know if any there is any data waiting to be "read"?
if I'm using direct access to the registers, I don't have to "open" and "close" the port...right?

If I want to make my program fast enough I can also use assembler, so that's not a problem...

0
 
LVL 4

Expert Comment

by:newmang
ID: 6158092
makris

Send me an email to newmangj@banksa.com.au and I will send you the source code for C based serial communications that uses inportb and outportb that I wrote about 10 years ago.

It's a bit too big to post here so send me an email & I will replay and attach the code.

Cheers - Gavin
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:makris
ID: 6158840
amihai_m@hotmail.com

10x...:)
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6158862
Make the question worth 300 points and I'll send you serial communication source code for Turbo C 2.01.
0
 
LVL 3

Expert Comment

by:3rsrichard
ID: 6159383
>>do you know such a library?
Sure, Greenleaf for one, but they may not sell it any more.  Have you looked around
at tucows.com  ?

>>If I understand what you wrote, all I have to do is write the data to the right memory address(0x3f8
>> for instance), and then read it from the same location?
Basically.

>>  how do I know if any there is any data waiting to be "read"?
Have you ever programmed a UART?  One of the registers is a "status" register
which tells you if there is data in the RX buffer, if it has errors, etc.  I suggest you go to
a TI, Motorola, Intel or other website and look up the specs for a UART, I thinx the one
mostly used in PC's is a 16640 or something like that.  Look on your PC specs.

 if I'm using direct access to the registers, I don't have to "open" and "close" the port...right?
Yes and no.  You do have to set the baud rate, # of bits, parity, etc if they are different
from the computers defaults.  If you use an interrupt service program to receive data then
you would have to remove the vector when you are through.

>>    If I want to make my program fast enough I can also use assembler, so that's not a problem...
0
 
LVL 3

Expert Comment

by:3rsrichard
ID: 6159781
Here is a link to a site which has code you might be able to modify for your
use.  A least it will show you the sort of routines you'll need.
http://www.jkmicro.com/newsite/downloads/downloads.html
0
 
LVL 4

Accepted Solution

by:
newmang earned 100 total points
ID: 6161979
makris

I received your email and replied with attached source code today - hope it helps...

Cheers - Gavin
0
 

Author Comment

by:makris
ID: 6162900
newmang

I'll try using it..

10x..
0
 
LVL 1

Expert Comment

by:MatthewL
ID: 6184340
a good resource for you - http://www.lvr.com/serport.htm

Matt
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Picking random number 8 177
Why this code doesn't work? 8 101
Why adding test code changes the build ? 11 132
How do I set up two external hard drives with Acronis True Image? 12 88
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers 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.

803 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