[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2003-11-02
11
Medium Priority
?
1,960 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever run into that annoying problem where the computer won't boot?  Wouldn't it be great if you had a tool that would make that disk boot again?  I have found one tool that works more often than not ...
Steps to fix “Unable to mount database. (hr=0x80004005, ec=1108)”.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

872 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