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
#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 );
}
}
#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
}
Antonio Linares wrote:Enrico,
Thanks. I guess you declare hComm as static HANDLE hComm;
Antonio Linares wrote:But the problem I see is that you can only manage one comm port at the same time, isn't it ?
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 );
}
static HANDLE hCom = INVALID_HANDLE_VALUE;
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: dutch, Google [Bot] and 39 guests