Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Accessing COM-Ports in NT

Posted on 1998-06-24
8
Medium Priority
?
240 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

971 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