Solved

Accessing COM-Ports in NT

Posted on 1998-06-24
8
235 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
[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
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
Independent Software Vendors: 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 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

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

Suggested Solutions

Title # Comments Views Activity
Magic Software info 18 154
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 100
Firemonkey android show image from resource ? 1 72
Posting a string with PostMessage 23 48
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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