• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

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..
0
makris
Asked:
makris
  • 3
  • 3
  • 2
  • +2
1 Solution
 
3rsrichardCommented:
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
 
makrisAuthor Commented:
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
 
newmangCommented:
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
SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

 
makrisAuthor Commented:
amihai_m@hotmail.com

10x...:)
0
 
MadYugoslavCommented:
Make the question worth 300 points and I'll send you serial communication source code for Turbo C 2.01.
0
 
3rsrichardCommented:
>>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
 
3rsrichardCommented:
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
 
newmangCommented:
makris

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

Cheers - Gavin
0
 
makrisAuthor Commented:
newmang

I'll try using it..

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

Matt
0

Featured Post

KuppingerCole Reviews AlgoSec in Executive Report

Leading analyst firm, KuppingerCole reviews AlgoSec's Security Policy Management Solution, and the security challenges faced by companies today in their Executive View report.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now