Bug in SetCommState()

Bug in SetCommState()

Postby Enrico Maria Giordano » Tue Jun 06, 2006 8:21 pm

It seems that SetCommState() is not able to change the serial communication port baud rate.

Antonio, can you look at it? If you need a sample of the problem please let me know.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bug in SetCommState()

Postby Enrico Maria Giordano » Tue Jun 06, 2006 10:29 pm

Found! There are at least the following functions to fix:

Code: Select all  Expand view
#ifdef __HARBOUR__
   CLIPPER BUILDCOMMDCB( PARAMS )   //  ()   cInfoDef, @ cDeviceBlock  --> lOk
#else
   CLIPPER BUILDCOMMD( PARAMS )   //  CB()   cInfoDef, @ cDeviceBlock  --> lOk
#endif
{
   DCB dcb;

   GetCommState( hCom, &dcb ); // EMG

   #ifdef __FLAT__
      if( BuildCommDCB( _parc( 1 ), &dcb ) )     // OK
   #else
      if( BuildCommDCB( _parc( 1 ), &dcb ) == 0 )     // OK
   #endif
   {
      _storclen( ( char * ) &dcb, sizeof( dcb ), 2 );
      _retl( TRUE );
   }
   else                                            // Error
   {
      _storc( "", 2 );
      _retl( FALSE );
   }
}


Code: Select all  Expand view
#ifdef __HARBOUR__
   CLIPPER SETCOMMSTATE( PARAMS )  // ()
#else
   CLIPPER SETCOMMSTA( PARAMS )  // TE()
#endif
{
   #ifdef __FLAT__
   _retl( SetCommState( hCom, ( DCB FAR * ) _parc( 2 ) ) != 0 ); // EMG
   #else
   _retl( SetCommState( ( DCB FAR * ) _parc( 1 ) ) == 0 );
   #endif
}


and obviously move up nCom definition.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Tue Jun 06, 2006 11:17 pm

Enrico,

Thanks. I guess you declare hComm as static HANDLE hComm;

But the problem I see is that you can only manage one comm port at the same time, isn't it ?
regards, saludos

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

Postby Enrico Maria Giordano » Tue Jun 06, 2006 11:43 pm

Antonio Linares wrote:Enrico,

Thanks. I guess you declare hComm as static HANDLE hComm;


No, you declared it that way. :-)

Antonio Linares wrote:But the problem I see is that you can only manage one comm port at the same time, isn't it ?


Yes, this is another problem. Why did you organize comm.c in such way?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Tue Jun 06, 2006 11:52 pm

Enrico,

> No, you declared it that way.

You are totally right :)

> Why did you organize comm.c in such way?

It has been evolving since 16 bits days: Backwards compatibity, learning and improving, changes... :)
regards, saludos

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

Postby Enrico Maria Giordano » Wed Jun 07, 2006 9:04 am

I know. :-)

There is one more problem: WriteComm() seems to not stop the execution till the sending is completed. How to check if a sending is in progress or make WriteComm() to work sinchronously?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Enrico Maria Giordano » Wed Jun 07, 2006 11:47 am

Solved:

Code: Select all  Expand view
short int WriteComm( short int idComDev, void FAR * lpvBuf, short int cbWrite )
{
   DWORD dwBytesWritten = cbWrite;

   overlap.hEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); // EMG
   dwEventsRead = WriteFile( hCom, lpvBuf, cbWrite, &dwBytesWritten, &overlap );
   WaitForSingleObject( overlap.hEvent, INFINITE ); // EMG
   GetOverlappedResult( hCom, &overlap, &dwBytesWritten, FALSE );
   CloseHandle( overlap.hEvent ); // EMG
   return ( ( short int ) dwBytesWritten );
}


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Sun Jul 02, 2006 9:05 pm

Enrico,

I missed this one. Many thanks! :)
regards, saludos

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

Postby Enrico Maria Giordano » Sun Jul 02, 2006 9:16 pm

Thank you!

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby pymsoft » Fri Sep 15, 2006 2:57 pm

I try to fix comm.c with the EMG code, but
i have compiling errors:



Progetto: WP32, Ambiente: BorlandWin:
[1]:Bcc32.Exe -M -c -O2 -tW -v- -X -DHB_FM_STATISTICS_OFF -DHB_NO_DEFAULT_API_MACROS -DHB_NO_DEFAULT_STACK_MACROS -DHB_OS_WIN_32 -Ic:\ut\fwh27\include -IC:\BCC55\Include;C:\xHxFw27\Include -nObj comm.c
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
comm.c:
Error E2451 comm.c 58: Undefined symbol 'hCom' in function BUILDCOMMD
Error E2451 comm.c 85: Undefined symbol 'hCom' in function SETCOMMSTA
*** 2 errors in Compile ***

I have FWH 2.7 December/2005

Directory di C:\ut\fwh27\source\winapi
16/05/2003 10.05 11.841 comm.c
Pedro Gonzalez
User avatar
pymsoft
 
Posts: 383
Joined: Tue Oct 11, 2005 1:01 pm
Location: Savona - Italia

Postby Enrico Maria Giordano » Fri Sep 15, 2006 3:52 pm

Put this just before OPENCOMM():

Code: Select all  Expand view
static HANDLE hCom = INVALID_HANDLE_VALUE;


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby pymsoft » Fri Sep 15, 2006 4:18 pm

Thanks, now works.
Pedro Gonzalez
User avatar
pymsoft
 
Posts: 383
Joined: Tue Oct 11, 2005 1:01 pm
Location: Savona - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: dutch, Google [Bot] and 39 guests