Solved

Serial communications

Posted on 2001-06-05
10
320 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:makris
Comment Utility
amihai_m@hotmail.com

10x...:)
0
 
LVL 2

Expert Comment

by:MadYugoslav
Comment Utility
Make the question worth 300 points and I'll send you serial communication source code for Turbo C 2.01.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:3rsrichard
Comment Utility
>>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
Comment Utility
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
Comment Utility
makris

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

Cheers - Gavin
0
 

Author Comment

by:makris
Comment Utility
newmang

I'll try using it..

10x..
0
 
LVL 1

Expert Comment

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

Matt
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

772 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

10 Experts available now in Live!

Get 1:1 Help Now