Link to home
Start Free TrialLog in
Avatar of makris
makris

asked on

Serial communications

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..
Avatar of 3rsrichard
3rsrichard

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.

Avatar of makris

ASKER

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

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
Avatar of makris

ASKER

amihai_m@hotmail.com

10x...:)
Make the question worth 300 points and I'll send you serial communication source code for Turbo C 2.01.
>>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...
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
ASKER CERTIFIED SOLUTION
Avatar of newmang
newmang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of makris

ASKER

newmang

I'll try using it..

10x..
a good resource for you - http://www.lvr.com/serport.htm

Matt