Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Component for COM ports beyond COM9?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 6 - Last Post: Jul 16, 2014 6:12 AM Last Post By: Erik Salaj
J Hviid

Posts: 8
Registered: 3/25/02
Component for COM ports beyond COM9?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 10, 2014 11:18 PM
I am using D6 on Win XP and have to write several applications able to handle binary data to and from COM ports. Incoming data is to be handled by event.

As COM 1-9 are already in use, I must go higher.

I know these ports require strange names like '\\.\COMxx', but so far none of the components tried has been able to get me ports in that range.

I have so far tried VarianAsync and AsyncPro.
I have tried to change port names acording to the '
..etc.' but I get the same result. Some %d failure.

Does anybody know components, that can actually handle the upper reach of COM ports, or how to make those mentioned above handle them?

An update:
I have now tried to run my code on two other PCs. There both those components seem able to give me COM ports in the upper band.
Could it be XP SP3? (Can not remember, if that is installed on the one in question. Unfortunately it is located 2 hours drive away!)

Other ideas?

Edited by: Registered User on Jul 11, 2014 12:24 AM
Angus Robertson

Posts: 205
Registered: 3/17/00
Re: Component for COM ports beyond COM9?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 11, 2014 12:24 AM   in response to: J Hviid in response to: J Hviid
As COM 1-9 are already in use, I must go higher.

I have so far tried VarianAsync and AsyncPro.
I have tried to change port names acording to the '
..etc.' but I
get the same result. Some %d failure.

I modified Async Pro many years ago to support named COM ports as well as
numeric ports, they don't all have numbers.

In adport.pas, add new public variable:

public
ComPortName: String ; // ie COMA33 used if ComNumber = 999

Then update this existing function:

function MakeComName(const ComNum : Word) : PChar;
{-Return a string like 'COMXX'}
begin
if TapiMode <> tmOn then begin
if (ComNum = 999) and (ComPortName <> '') then
result := PChar ('\\.\' + ComPortName)
else begin
StrFmt(Temp, '\\.\COM%d', [ComNum]);
Result := Temp;
end;
end else
Result := nil;
end;

In your application, set ComNumber=999 and the component will use
ComPortName instead, which you set to 'COM45', 'COMA33' or whatever.

Note you can not use the Async Pro function to determine the installed
serial ports which only works with numbers, you'll need a better function
reading registry keys and/or using the SetupApi to find the actual serial
ports, and these are often dynamic, with virtual serial ports coming and
going as USB leads are plugged in.
I wrote a function that also includes disabled ports including, this is
some of the ports on my PC:

Serial Ports Found:
COM1, Enabled=Y, Communications Port, (Standard port types), Serial0,
ACPI\PNP0501,
COM3, Enabled=N, Prolific USB-to-Serial Comm Port, Prolific, ,
USB\VID_067B&PID_2303&REV_0400, Port_#0001.Hub_#0003
COM11, Enabled=Y, D-Link DU-562M External Modem, CXT, Winachsf0,
USB\VID_0572&PID_1300&REV_0100, Port_#0007.Hub_#0004
COM12, Enabled=Y, Enhanced Communication Port, Oxford Semiconductor, OXMF0,
OXMF\*PNP0501, oxmf bus, port 0
COM24, Enabled=Y, Standard Serial over Bluetooth link, Microsoft, BthModem0,
BTHENUM{00001101-0000-1000-8000-00805f9b34fb}_VID&0001000f_PID&1200,
COM26, Enabled=Y, USB Serial Port, FTDI, VCP0,
FTDIBUS\COMPORT&VID_0403&PID_6001,
COM27, Enabled=N, USB-SERIAL CH340, wch.cn, ,
USB\VID_1A86&PID_7523&REV_0254, Port_#0001.Hub_#0003
CNCA0, Enabled=Y, com0com - serial port emulator, Vyacheslav Frolov,
com0com10, com0com\port, CNCA0

Angus

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Component for COM ports beyond COM9?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 11, 2014 11:45 AM   in response to: Angus Robertson in response to: Angus Robertson
Angus wrote:

In your application, set ComNumber=999 and the component will use
ComPortName instead, which you set to 'COM45', 'COMA33' or whatever.

Why do you need a magic number? Why not just give ComPortName priority if
it is not blank?

function MakeComName(const ComNum : Word) : PChar;
{-Return a string like 'COMXX'}
begin
  if TapiMode <> tmOn then begin
    if ComPortName <> '' then
      Result := PChar ('\\.\' + ComPortName)
    else begin
      StrFmt(Temp, '\\.\COM%d', [ComNum]);
      Result := Temp;
    end;
  end else
    Result := nil;
end;


MakeComName() returns a PChar instead of a String, but "Result := PChar('\\.\'
+ ComPortName)" allocates a temp String that goes out of scope when the function
exits, leaving the Result pointing to freed memory. I am guessing Temp is
a pre-allocated buffer, so the following would be safer (assuming the function
cannot be changed to return a String instead):

function MakeComName(const ComNum : Word) : PChar;
{-Return a string like 'COMXX'}
begin
  if TapiMode <> tmOn then begin
    if ComPortName <> '' then
      StrFmt(Temp, '\\.\'%s', [ComPortName]) // or StrLFmt() to avoid a buffer 
overflow if ComPortName is too long
    else
      StrFmt(Temp, '\\.\COM%d', [ComNum]);
    end;
    Result := Temp;
  end else
    Result := nil;
end;


--
Remy Lebeau (TeamB)
J Hviid

Posts: 8
Registered: 3/25/02
Re: Component for COM ports beyond COM9?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 11, 2014 11:32 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Well, the ideas put forward are interesting!
Unfortunately, I am rather new to writing components. Even modifying existing ones.

In order to add a new public, I guess it has to be a Property, with routines to handle read from and write to that?

Sorry to go all the way that low, but I have to start, where I can understand those things.

And I still have to find a reason for the same code to run perfectly on two machines, but fails on a third.

I believe to have installed all available D6 updates on all machines in question, but XP SP3 I can not remember.
It could also be different versions of the components, but then I would have to install a different version of two different components, because they both work/fail.

And, of course, now it is weekend, and I am not able to access any of the PCs.

Edited by: Registered User on Jul 11, 2014 11:34 PM

Edited by: Registered User on Jul 11, 2014 11:37 PM

Edited by: Registered User on Jul 11, 2014 11:38 PM
Angus Robertson

Posts: 205
Registered: 3/17/00
Re: Component for COM ports beyond COM9? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 12, 2014 3:10 AM   in response to: J Hviid in response to: J Hviid
And I still have to find a reason for the same code to run
perfectly on two machines, but fails on a third.

Not uncommon with different configurations, that's why we all use Virtual
Machines with different versions of Windows for testing.

I believe to have installed all available D6 updates on all
machines in question, but XP SP3 I can not remember.
It could also be different versions of the components

We seem to getting confused here between a single application not running
on three different machines, and three separate machines each with Delphi 6
installed not being able to build and run the same source code.

Trying to get the Delphi development environment synchronised between
machines is not trivial - options, components, patches, etc, can all be
different.

Certainly Async Pro supported COM ports up to 999 for XP3, I had users
doing exactly that.

Angus
Angus Robertson

Posts: 205
Registered: 3/17/00
Re: Component for COM ports beyond COM9?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 12, 2014 3:10 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Why do you need a magic number? Why not just give ComPortName
priority if it is not blank?

Seemed a good idea at the time.

leaving the Result pointing to freed memory.

Thanks, will fix the leak.

Angus
Erik Salaj

Posts: 144
Registered: 12/23/11
Re: Component for COM ports beyond COM9? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 16, 2014 6:12 AM   in response to: J Hviid in response to: J Hviid
As COM 1-9 are already in use, I must go higher.

I know these ports require strange names like '\\.\COMxx', but so far none of the components tried has been able to get me ports in that range.

I have so far tried VarianAsync and AsyncPro.
I have tried to change port names acording to the '
..etc.' but I get the same result. Some %d failure.

Does anybody know components, that can actually handle the upper reach of COM ports, or how to make those mentioned above handle them?

http://www.winsoft.sk/comport.htm

Erik Salaj, WINSOFT
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02