Page 3 of 3

Re: Enumerating serial ports

Posted: Wed Oct 23, 2013 5:42 am
by mol
I have working demo program from my fiscal printers vendor written in Borland Delphi, I think.
There is used such a function to detect COM ports:

Code: Select all

 procedure FindSerialPorts(Strings: TStrings);
  var
    vs: Cardinal;
    v: _COMMCONFIG;
    i: Integer;
  begin
    Strings.Clear;
    vs := SizeOf(v);
    for i := 1 to 32 do
      if GetDefaultCommConfig(PChar('COM' + IntToStr(i)), v, vs) then
        Strings.Add('COM' + IntToStr(i));
    Strings.Add('OICCommHub');
  end;
When googled, I found GetDefaultCommConfig

Code: Select all

BOOL WINAPI GetDefaultCommConfig(
  _In_     LPCTSTR lpszName,
  _Out_    LPCOMMCONFIG lpCC,
  _Inout_  LPDWORD lpdwSize
);
in

http://msdn.microsoft.com/en-us/library ... 85%29.aspx" onclick="window.open(this.href);return false;


But, I don't know how to use it with harbour.

Re: Enumerating serial ports

Posted: Wed Oct 23, 2013 6:41 am
by mol
There is also harbour function win_comIsValid, but I don't know how to use it...

Re: Enumerating serial ports

Posted: Wed Oct 23, 2013 9:33 am
by mol
I've tried such a code:

Code: Select all

   LOCAL cCom       := "COM1"
   LOCAL nBaudeRate := 9600
   LOCAL nDatabits  := 8
   LOCAL nParity    := 0 /* none */
   LOCAL nStopbit   := 1
   LOCAL nBuff      := 8000

aPorts := {}
for i:=1 to 32
	cPortName := "COM"+alltrim(str(i))
   s_nHandle := INIT_PORT( cPortName, nBaudeRate, nDatabits, nParity, nStopbit, nBuff )
   IF s_nHandle > 0 	
			aAdd(aPorts,cPortName)
	endif
next i

MsgDebug1("Com port list",aPorts)
and works OK

PS. rememeber to link with hbcomm library

Enumerating serial ports

Posted: Fri Jun 06, 2014 6:12 pm
by Pablo César
Our good friend Andrés gave us a solution for parallel ports and adapting for serial it will work perfectly too. See at: http://hmgforum.com/viewtopic.php?p=34894#p34894

Re: Enumerating serial ports

Posted: Sat Jun 07, 2014 6:25 am
by mol
That's great! Many thanks!

Re: Enumerating serial ports

Posted: Sun Jun 08, 2014 4:11 pm
by Javier Tovar
Gracias a todos por compartir sus conocimientos!

Saludos
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Thank you all for sharing your knowledge!

regards