Solved

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

Posted on 2003-11-02
11
1,951 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

A list of useful business intelligence software.
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
The viewer will learn how to create multiple layers to apply various filters and how to delete areas from each layer’s filter.
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.

911 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

22 Experts available now in Live!

Get 1:1 Help Now