Comm Port Settings

Post Reply
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Comm Port Settings

Post by Jeff Barnes »

Hi Everybody,

I have a small problem with setting up my comm port....

I use a USB to Serial adapter and connect to a medical device to read its data and all works fine if I use comm ports 1 to 9.

If I try to use a higher comm port (10+) I get a SetCommState error.

Code: Select all

nComm:= OpenComm( "Com"+alltrim(str(Config->Comm)), 1024, 128 )  
if ! BuildCommDcb( "COM"+alltrim(str(Config->Comm))+":9600,n,8,1", @cDcb )
      MsgInfo("BuildComm Error")
      oDlg1:End()
      lError := .t.
      RETURN NIL
endif
		
if ! SetCommState(  nComm, cDcb )
      MsgInfo("SetComm Error")
      oDlg1:End()
      lError := .t.
      RETURN NIL
endif

if FlushComm( nComm, 1 ) != 0
      MsgInfo("FlushComm Error")
      oDlg1:End()
      lError := .t.
      RETURN NIL
endif

Anyone know why this is happening?
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Jeff,

Please do a MsgInfo( nComm ) just to check what value you get when you use a port higher than 10, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

Antonio,

I get: 44466720 (Comm set to 11)
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Jeff,

Please do this call:

MsgInfo( GetLastError() ) after the error to know what error reports Windows, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

Antonio,

The last error is: 6
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Jeff,

It means "invalid handle". Maybe there is a sign issue.

Lets review the source code for OpenComm()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Jeff,

Please define this function in your PRG and use this one instead of OpenComm():

Code: Select all

#pragma BEGINDUMP

#include <hbapi.>
#include <windows.h>

unsigned long OpenComm( char *, WORD, WORD );

HB_FUNC( MYOPENCOMM )
{
   WORD cbInQueue  = IF( ISNUM( 2 ), hb_parni( 2 ), 1024 );
   WORD cbOutQueue = IF( ISNUM( 3 ), hb_parni( 3 ),  128 );

   hb_retnl( ( unsigned long ) OpenComm( hb_parc( 1 ), cbInQueue, cbOutQueue ) );
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

Hi Antonio,

Sorry for the delay in getting back to you on this one ... I have been very busy the past few weeks :-)


I tried adding the code and get the following error at compile:
EzSat.c:
Warning W8065 ezsat.prg 18910: Call to function 'IF' with no prototype in function HB_FUN_MYOPENCOMM
Warning W8065 ezsat.prg 18911: Call to function 'IF' with no prototype in function HB_FUN_MYOPENCOMM
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external '_IF' referenced from C:\EZSAT\EZSAT.OBJ
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Jeff,

Please add this define just below the last #include:

#define IF(x,y,z) ( (x) ? (y) : (z) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply