Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Serial communications

Posted on 2001-06-05
10
Medium Priority
?
369 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
[X]
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
  • 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
Industry Leaders: 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!

 

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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops 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.

688 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