Solved

Accessing COM-Ports in NT

Posted on 1998-06-24
8
229 Views
Last Modified: 2010-04-04
How hard can it be? I REALLY need to access the com ports in Windows NT. Is there anyone out there who has a simpel solution for this? I have seen/tried a lot of components, but they are either buggy or expensive... HELP ME... Please...
0
Comment
Question by:johnrt
8 Comments
 
LVL 1

Expert Comment

by:Odie
ID: 1355558
It's quite easy.  Just use CreateFile and use "COM1" as a filename.  But you'd better check your Win32 Help-file first.
0
 

Author Comment

by:johnrt
ID: 1355559
Odie: that won't work in NT!!!!!!!!!!!! Try it yourself!!!
0
 
LVL 5

Expert Comment

by:inter
ID: 1355560
Hi,
johnrt, CreateFile do work on NT. If not you may have problems with your config. First of all trouble shooting
1 - Do you see COM1 in Control Panel->Ports? and see its properties by dblclicking
2 - Does Hyperterminal works on your computer? Open Hyperterminal set it to COM1 and try to send a file(to the line, no one needs to listen if you do not use flow control or any protocol)

If the items above are OK. You may have problem with parameters of CreateFile. In the first place I recomend you to perform non overlapped I/O. So the code that opens com1 is as follows:

  FileHandle:= CreateFile(
           'COM1',
           GENERIC_READ + GENERIC_WRITE{dwDesiredAccess},
           0{dwShareMode},
           nil,{lpSecurityAttributes: PSecurityAttributes}
           OPEN_EXISTING{dwCreationDisposition},
           FILE_ATTRIBUTE_NORMAL+FILE_FLAG_OVERLAPPED{dwFlagsAndAttributes: DWORD},
           0{hTemplateFile: THandle});
  if FileHandle=INVALID_HANDLE_VALUE then
    ShowMessage('Can not open COM port');
  //NOW USE FileHandle to read and write to com port

Regards, Igor
0
 
LVL 5

Expert Comment

by:inter
ID: 1355561
Hi,
johnrt, CreateFile do work on NT. If not you may have problems with your config. First of all trouble shooting
1 - Do you see COM1 in Control Panel->Ports? and see its properties by dblclicking
2 - Does Hyperterminal works on your computer? Open Hyperterminal set it to COM1 and try to send a file(to the line, no one needs to listen if you do not use flow control or any protocol)

If the items above are OK. You may have problem with parameters of CreateFile. In the first place I recomend you to perform non overlapped I/O. So the code that opens com1 is as follows:

  FileHandle:= CreateFile(
           'COM1',
           GENERIC_READ + GENERIC_WRITE{dwDesiredAccess},
           0{dwShareMode},
           nil,{lpSecurityAttributes: PSecurityAttributes}
           OPEN_EXISTING{dwCreationDisposition},
           FILE_ATTRIBUTE_NORMAL+FILE_FLAG_OVERLAPPED{dwFlagsAndAttributes: DWORD},
           0{hTemplateFile: THandle});
  if FileHandle=INVALID_HANDLE_VALUE then
    ShowMessage('Can not open COM port');
  //NOW USE FileHandle to read and write to com port

Regards, Igor
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 5

Expert Comment

by:inter
ID: 1355562
SORRYYYYY for doubling :-)
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1355563
I use AsyncPro components without any problem on NT 4.0
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 200 total points
ID: 1355564
Hi johnrt,

for this I use an excellent freeware component. It works on all windows OS (16bit needs another version). Look for yourself at :

http://www.mdlive.com/d3k/efreelib.htm It's made By M.Cocco.

Regards, Zif.
0
 

Author Comment

by:johnrt
ID: 1355565
Thanks all.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

759 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

22 Experts available now in Live!

Get 1:1 Help Now