Solved

Accessing COM-Ports in NT

Posted on 1998-06-24
8
236 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month5 days, 6 hours left to enroll

636 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