Solved

writing o a com port

Posted on 1998-12-07
5
241 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

728 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

10 Experts available now in Live!

Get 1:1 Help Now