Solved

writing o a com port

Posted on 1998-12-07
5
244 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

773 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