List of COM Ports

List of COM Ports

Postby Jeff Barnes » Sun Feb 17, 2013 1:04 am

Hi,

Is there a way to get a list of the available COM ports on a system?
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: List of COM Ports

Postby anserkk » Mon Feb 18, 2013 4:19 am

I think you can get the list by reading the following registry entries

HKEY_LOCAL_MACHINE\Hardware\DeviceMap\SerialComm

Regards
Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: List of COM Ports

Postby Jeff Barnes » Mon Feb 18, 2013 7:54 pm

Hi Anser,

I checked my registry ... you are correct. They are listed there.
Now the question is, how would I get an array of the com ports when I don't know what the key names will be?

Image
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: List of COM Ports

Postby StefanHaupt » Tue Feb 19, 2013 7:34 am

Jeff,

you can use ::EnumVkey() from my reg32.prg

Code: Select all  Expand view
//-------------------------------------------------------------------------//
METHOD EnumKey () CLASS TReg32

LOCAL i := 0, nError := 0
LOCAL cBuffer := Space (255)
LOCAL nBufSize := 255
LOCAL cClass := Space (255)
LOCAL nClsSize := 255
LOCAL aRet := {}

 While (nError := RegEnumKeyExA( ::nHandle, i++, @cBuffer, nBufSize,0,cClass, nClsSize )) == ERROR_SUCCESS

    cBuffer := StrTran (cBuffer,",","\")         // Replace "," with "\"
    AADD (aRet,cBuffer)

 End

::nError := nError

RETURN (aRet)

//-------------------------------------------------------------------------//
DLL32 static ;
FUNCTION RegEnumKeyExA(nhKey      AS LONG   ,;
                       nIndex     AS LONG   ,;
                       @cBuffer   AS LPSTR  ,;   //By reference
                       @nBufSize  AS PTR    ,;   //By reference
                       nReserved  AS LONG   ,;   //Must be NULL
                       @cClass    AS LPSTR  ,;   //By reference (can be NULL)
                       @nClsSize  AS PTR    ,;   //By reference (can be NULL)
                       @pFileTime AS PTR    );   //By reference (can be NULL)
         ;
         AS LONG PASCAL LIB "
ADVAPI32.DLL"


kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], SantaCroya and 112 guests