How to use the serial port to make two computers talk.

Hi,
I was looking for help on making two computers talk (live chat) via a connection through the serial port in C?? How can that also be modified to allow transfer of files between the two computers? Does anyone know where I can start? Any help would be appreciated.  Thanks!
ign0miniousAsked:
Who is Participating?
 
jimmy007Connect With a Mentor Commented:
Under Windows2000 or XP, you can use the C 32bit window API.

Look for functions :

* CreateFile(..)
* WriteFile(..)
* ReadFile(..)
* DeleteFile(..)

The CreateFile function can create a handle to a communications resource, such as the serial port COM1. For communications resources, the dwCreationDisposition parameter must be OPEN_EXISTING, and the hTemplate parameter must be NULL. Read, write, or read/write access can be specified, and the handle can be opened for overlapped I/O. For more information about communications
0
 
mtmikeCommented:
Well, C is platform independent language and doesn't have any standard functions you can use to communicate with hardware. Most OSs use devices to accomplish this.

You should be able to open the serial device and simply read/write it. You can usually set parameters such as baudrate using an ioctl()-like interface.

Start by setting up the connection and when that is working (ie you can send something from one computer to the other), define a communication protocol that allows for live chat, file transfer, etc.
0
 
ign0miniousAuthor Commented:
Hmm.. Would it then be wise for me to use C to perform this task. Perhaps assembly would be preferable? What would you recommend? (mtmike?)
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
mtmikeCommented:
There's no need to use assembly. Most OSs have C functions to access the serial port and this is the preferred method.

The links sunnycoder has given show you how to do this on a unix system. On windows:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceseril/html/cmconProgrammingSerialConnections.asp

0
 
ign0miniousAuthor Commented:
Mtmike,

That link is for windows CE - will it be the same for other versions of windows (win2k/xp)?

Also, does anyone have any sample code of how I should even begin - I'm clueless.

Thanks!
0
 
sunnycoderCommented:
reiterating what I posted
Serial Programming Guide for POSIX Operating Systems --- will work for all POSIX compliant systems and that includes windows  -- this is one of the most detailed guides.. even though it has a bias towards unix, you should find it very helpful
http://dns.easysw.com/~mike/serial/serial.html

this is a linux link, but is a very good resoiurce and you will find it helpful
http://www.faqs.org/docs/Linux-HOWTO/Serial-Programming-HOWTO.html
0
 
ign0miniousAuthor Commented:
Thanks for the clarification Sunnycoder,

Have you ever done something along these lines before? Do you have any sample code you can provide?
0
 
sunnycoderCommented:
no I have not done serial programming myself
The links I posted have step by step guide along with sample code
0
 
mtmikeCommented:
You can either use the POSIX or the native windows API.
http://www.lookrs232.com/com_port_programming/
0
 
sunnycoderCommented:
came across something while cleaning up
http://www.lvr.com/serport.htm
it has loads of stuff .... code, links etc
0
All Courses

From novice to tech pro — start learning today.