Page 1 of 1

Comm Port Settings

Posted: Thu Sep 18, 2008 11:43 pm
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?

Posted: Fri Sep 19, 2008 8:47 pm
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

Posted: Sat Sep 20, 2008 2:38 pm
by Jeff Barnes
Antonio,

I get: 44466720 (Comm set to 11)

Posted: Sat Sep 20, 2008 3:23 pm
by Antonio Linares
Jeff,

Please do this call:

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

Posted: Sat Sep 20, 2008 8:39 pm
by Jeff Barnes
Antonio,

The last error is: 6

Posted: Sat Sep 20, 2008 11:25 pm
by Antonio Linares
Jeff,

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

Lets review the source code for OpenComm()

Posted: Sat Sep 20, 2008 11:35 pm
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

Posted: Sun Oct 05, 2008 11:31 pm
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

Posted: Sun Oct 05, 2008 11:32 pm
by Antonio Linares
Jeff,

Please add this define just below the last #include:

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