Comm Port Settings

Comm Port Settings

Postby Jeff Barnes » Thu Sep 18, 2008 11:43 pm

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  Expand view
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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Antonio Linares » Fri Sep 19, 2008 8:47 pm

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
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Sat Sep 20, 2008 2:38 pm

Antonio,

I get: 44466720 (Comm set to 11)
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

Postby Antonio Linares » Sat Sep 20, 2008 3:23 pm

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
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Sat Sep 20, 2008 8:39 pm

Antonio,

The last error is: 6
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

Postby Antonio Linares » Sat Sep 20, 2008 11:25 pm

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: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Sat Sep 20, 2008 11:35 pm

Jeff,

Please define this function in your PRG and use this one instead of OpenComm():
Code: Select all  Expand view
#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
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Sun Oct 05, 2008 11:31 pm

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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Antonio Linares » Sun Oct 05, 2008 11:32 pm

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
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 69 guests