Solved

writing o a com port

Posted on 1998-12-07
5
248 Views
Last Modified: 2011-09-20
Can I use the WriteToFile Method to write to a com port. Similarly how can I read the data from the com port?
Thanx in advance
0
Comment
Question by:Abbas071098
  • 3
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
nil_dib earned 50 total points
ID: 1179460
This answer is only for microsoft environments. If you don't work under/with MS reject
my answer.
You have to use the WriteFile function!
First of all you have to open the serail port with the CreateFile function.
Then call SetupComm, SetCommState, SetCommMask, SetCommTimeouts ....
After that call WriteFile and ReadFile to write and read from the port.
A good sample how to open/initialize/read/write serial ports is mttty.                                    
For more information look at http://www.microsoft.com/win32dev/base/serial.htm
or at http://www.codeguru.com/ (search for "serialport") where you can find a class which handles the serail port comunication.

0
 

Author Comment

by:Abbas071098
ID: 1179461
Thanx nil_dib. I accept your answer and am awarding you the deserving points. but is it possible to get the handle if the serial port is exclusively owned by some driver say if the mouse is connected to the serial port? I haven't tried it but I think this would cause some problems
0
 
LVL 4

Expert Comment

by:nil_dib
ID: 1179462
I think you are right. Once I tried to open/read from a com port which was used by
another application ... and that didn't work( CreateFile returned port allready
open or something..). But you can try to get the port handle not from CreateFile
(which creates the handle) but from another function which should catch the handle
to the open port.
0
 

Author Comment

by:Abbas071098
ID: 1179463
Do u know nil_dib what can be the other function to get a handle to the port?...
0
 
LVL 4

Expert Comment

by:nil_dib
ID: 1179464
mmhhh,
I believe the method whow to get the handle, depends on the type
of driver owned the port (exe,dll,system,vxd ...) and on the
way the port was opened
( read http://www.microsoft.com/win32dev/base/serial.htm
chapter: Overlapped I/O).
But: this is only a suggestion ... I'm not sure whether it
is possible to write/read to a port which is owned by another
appliction or driver.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which IDE to use to begin C++ training? 5 65
C++ Language error 28 246
Header Errors LNK2019, LNK1120 - Unresolved Externals 4 193
Precision Problem in C++ 7 44
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

829 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