Solved

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

Posted on 2003-11-02
11
1,949 Views
Last Modified: 2013-11-15
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!
0
Comment
Question by:ign0minious
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 5

Expert Comment

by:mtmike
ID: 9672404
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
 

Author Comment

by:ign0minious
ID: 9675375
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
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9676722
0
 
LVL 5

Expert Comment

by:mtmike
ID: 9677674
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
 

Author Comment

by:ign0minious
ID: 9722394
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 45

Expert Comment

by:sunnycoder
ID: 9722506
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
 

Author Comment

by:ign0minious
ID: 9722579
Thanks for the clarification Sunnycoder,

Have you ever done something along these lines before? Do you have any sample code you can provide?
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9728289
no I have not done serial programming myself
The links I posted have step by step guide along with sample code
0
 
LVL 5

Expert Comment

by:mtmike
ID: 9730124
You can either use the POSIX or the native windows API.
http://www.lookrs232.com/com_port_programming/
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9730620
came across something while cleaning up
http://www.lvr.com/serport.htm
it has loads of stuff .... code, links etc
0
 
LVL 1

Accepted Solution

by:
jimmy007 earned 500 total points
ID: 9839350
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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Today companies are subjected to more-and-more data, and it won't stop any time soon.  But there are obvious opportunities for reducing data, particularly data duplicated among companies.
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
Viewers will learn how to use the Hootsuite Dashboard.

705 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

19 Experts available now in Live!

Get 1:1 Help Now