Solved

Accessing COM-Ports in NT

Posted on 1998-06-24
8
232 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

815 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

8 Experts available now in Live!

Get 1:1 Help Now