Solved

writing o a com port

Posted on 1998-12-07
5
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

696 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