revisa esto:
https://technet.microsoft.com/en-us/library/cc770631(v=ws.11).aspx
LPCOMDATA OpenComm( LPCSTR lpszDevControl, unsigned short int cbInQueue,
unsigned short int cbOutQueue )
{
LPCOMDATA pComm = ( LPCOMDATA ) hb_xgrab( sizeof( COMDATA ) );
memset( ( char * ) pComm, 0, sizeof ( COMDATA ) );
pComm->hCom = CreateFile( lpszDevControl,
GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL );
SetupComm( pComm->hCom, cbInQueue, cbOutQueue );
SetCommMask( pComm->hCom, EV_RXCHAR );
EscapeCommFunction( pComm->hCom, SETDTR );
pComm->hThread = CreateThread( NULL, 0, listenThread, pComm, 0, &pComm->dwThreadID );
if( pComm->hThread == 0 )
{
MessageBox( 0, "error", "error", 0 ); // nuevo !!!
CloseHandle( pComm->hCom );
hb_xfree( ( void * ) pComm );
return ( LPCOMDATA ) -1;
}
return pComm;
}
static DWORD __stdcall listenThread( LPVOID pVoid )
{
char buf[ 1024 ];
DWORD dwBytesReaded, event;
COMSTAT stat;
OVERLAPPED overlap; // A.L. 2007, Keep this here!!! Not on the struct!!!
LPCOMDATA pComm = ( LPCOMDATA ) pVoid;
SetCommMask( pComm->hCom, EV_RXCHAR );
memset( ( char * ) &overlap, 0, sizeof ( overlap ) );
while( 1 )
{
DWORD x;
WaitCommEvent( pComm->hCom, &event, NULL );
ClearCommError( pComm->hCom, &event, &stat );
ReadFile( pComm->hCom, buf, min( 1023, stat.cbInQue ), &dwBytesReaded, &overlap );
GetOverlappedResult( pComm->hCom, &overlap, &dwBytesReaded, FALSE );
buf[ dwBytesReaded + 1 ] = 0;
for( x = 0; x < dwBytesReaded; x++ )
{
pComm->combuf[ pComm->comheadbuf ] = buf[ x ];
pComm->comheadbuf++;
if( pComm->comheadbuf > COMBUFSIZE - 1 )
pComm->comheadbuf = 0;
}
if( pComm->CommNotifyHwnd != NULL )
{ // nuevo
SendMessage( pComm->CommNotifyHwnd, WM_COMMNOTIFY, ( WPARAM ) pComm,
MAKELONG( CN_RECEIVE, 0 ) );
MessageBox( 0, "mensaje enviado", "ok", 0 ); // nuevo
} // nuevo
}
}
@ECHO OFF
CLS
ECHO ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
ECHO ³ FiveWin for xHarbour 15.01 - Jan. 2015 xHarbour development power ³Ü
ECHO ³ (c) FiveTech, 1993-2015 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8 ³Û
ECHO ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙÛ
ECHO ÿ ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
if A%1 == A GOTO :SINTAX
if NOT EXIST %1.prg GOTO :NOEXIST
ECHO Compiling...
if "%FWDIR%" == "" set FWDIR=.\..\
if "%XHDIR%" == "" set XHDIR=c:\xharbour
rem if "%2" == "/b" set GT=gtwin
rem if not "%2" == "/b" set GT=gtgui
set GT=gtgui
set hdir=%XHDIR%
set hdirl=%hdir%\lib
set bcdir=c:\bcc582
set fwh=%FWDIR%
%hdir%\bin\harbour %1 /n /i%fwh%\include;%hdir%\include /w /p %2 %3 > comp.log 2> warnings.log
IF ERRORLEVEL 1 GOTO COMPILEERRORS
@type comp.log
@type warnings.log
echo -O2 -e%1.exe -I%hdir%\include -I%bcdir%\include %1.c > b32.bc
%bcdir%\bin\bcc32 -M -c -v @b32.bc
:ENDCOMPILE
IF EXIST %1.rc %bcdir%\bin\brc32 -r -I%bcdir%\include %1
echo %bcdir%\lib\c0w32.obj + > b32.bc
echo %1.obj, + >> b32.bc
echo %1.exe, + >> b32.bc
echo %1.map, + >> b32.bc
echo %fwh%\lib\Fivehx.lib %fwh%\lib\FiveHC.lib + >> b32.bc
echo %hdirl%\rtl.lib + >> b32.bc
echo %hdirl%\vm.lib + >> b32.bc
echo %hdirl%\%GT%.lib + >> b32.bc
echo %hdirl%\lang.lib + >> b32.bc
echo %hdirl%\macro.lib + >> b32.bc
echo %hdirl%\rdd.lib + >> b32.bc
echo %hdirl%\dbfntx.lib + >> b32.bc
echo %hdirl%\dbfcdx.lib + >> b32.bc
echo %hdirl%\dbffpt.lib + >> b32.bc
echo %hdirl%\hbsix.lib + >> b32.bc
echo %hdirl%\debug.lib + >> b32.bc
echo %hdirl%\common.lib + >> b32.bc
echo %hdirl%\pp.lib + >> b32.bc
echo %hdirl%\pcrepos.lib + >> b32.bc
echo %hdirl%\ct.lib + >> b32.bc
echo %hdirl%\zlib.lib + >> b32.bc
echo %hdirl%\hbzip.lib + >> b32.bc
echo %hdirl%\libmisc.lib + >> b32.bc
echo %hdirl%\tip.lib + >> b32.bc
echo %hdirl%\png.lib + >> b32.bc
rem Uncomment these two lines to use Advantage RDD
rem echo %hdir%\lib\rddads.lib + >> b32.bc
rem echo %hdir%\lib\Ace32.lib + >> b32.bc
echo %bcdir%\lib\cw32.lib + >> b32.bc
echo %bcdir%\lib\import32.lib + >> b32.bc
echo %bcdir%\lib\uuid.lib + >> b32.bc
echo %bcdir%\lib\ws2_32.lib + >> b32.bc
echo %bcdir%\lib\psdk\odbc32.lib + >> b32.bc
echo %bcdir%\lib\psdk\rasapi32.lib + >> b32.bc
echo %bcdir%\lib\psdk\nddeapi.lib + >> b32.bc
echo %bcdir%\lib\psdk\msimg32.lib + >> b32.bc
echo %bcdir%\lib\psdk\psapi.lib + >> b32.bc
echo %bcdir%\lib\psdk\gdiplus.lib + >> b32.bc
echo %bcdir%\lib\psdk\iphlpapi.lib + >> b32.bc
echo %bcdir%\lib\psdk\shell32.lib, >> b32.bc
IF EXIST %1.res echo %1.res >> b32.bc
rem uncomment this line to use the debugger and comment the following one
if %GT% == gtwin %bcdir%\bin\ilink32 -Gn -Tpe -s -v @b32.bc
IF ERRORLEVEL 1 GOTO LINKERROR
if %GT% == gtgui %bcdir%\bin\ilink32 -Gn -aa -Tpe -s -v @b32.bc
IF ERRORLEVEL 1 GOTO LINKERROR
ECHO * Application successfully built *
%1
GOTO EXIT
ECHO
rem delete temporary files
@del %1.c
:COMPILEERRORS
@type comp.log
ECHO * Compile errors *
GOTO EXIT
:LINKERROR
ECHO * Linking errors *
GOTO EXIT
:SINTAX
ECHO SYNTAX: Build [Program] {-- No especifiques la extensi¢n PRG
ECHO {-- Don't specify .PRG extension
GOTO EXIT
:NOEXIST
ECHO The specified PRG %1 does not exist
:EXIT
1. if( pComm->CommNotifyHwnd != NULL )
SendMessage( pComm->CommNotifyHwnd, WM_COMMNOTIFY, ( WPARAM ) pComm,
MAKELONG( CN_RECEIVE, 0 ) );
MessageBox( 0, "mensaje enviado", "ok", 0 ); // nuevo ... despliega este mensaje , tanto en local como en el remoto
2. ReadFile( pComm->hCom, buf, min( 1023, stat.cbInQue ), &dwBytesReaded, &overlap );
GetOverlappedResult( pComm->hCom, &overlap, &dwBytesReaded, FALSE );
MessageBox( 0, buf , "contenido de buf", 0 ); // ver contenido de buf
en modo local -> buf = 0.145
0.145 ....
en modo remoto -> buf = 0
0
....
4
0
5
0
....
1 -> irregular el retorno
3. for( x = 0; x < dwBytesReaded ; x++ )
{
MessageBox( 0, "entro for" , "contenido de buf", 0 ); // en modo local si entra... en modo remoto no => dwBytesReaded es cero ???
pComm->combuf[ pComm->comheadbuf ] = buf[ x ];
pComm->comheadbuf++;
if( pComm->comheadbuf > COMBUFSIZE - 1 )
pComm->comheadbuf = 0;
}
while( 1 )
{
DWORD x;
WaitCommEvent( pComm->hCom, &event, NULL );
ClearCommError( pComm->hCom, &event, &stat );
Sleep(10); // agregue este tiempo de espera
ReadFile( pComm->hCom, buf, min( 1023, stat.cbInQue ), &dwBytesReaded, &overlap );
GetOverlappedResult( pComm->hCom, &overlap, &dwBytesReaded, FALSE );
buf[ dwBytesReaded + 1 ] = 0;
for( x = 0; x < dwBytesReaded ; x++ )
{
pComm->combuf[ pComm->comheadbuf ] = buf[ x ];
pComm->comheadbuf++;
if( pComm->comheadbuf > COMBUFSIZE - 1 )
pComm->comheadbuf = 0;
}
if( pComm->CommNotifyHwnd != NULL )
SendMessage( pComm->CommNotifyHwnd, WM_COMMNOTIFY, ( WPARAM ) pComm,
MAKELONG( CN_RECEIVE, 0 ) );
};
2. agregando tiempo de espera en los .prg, entre el readcomm y BuildCommDcb : MySleep(nTieEsp) ejp 10
IdPort := OpenComm("COM"+STR(nNroPue,1), 1024,128) //,2048,512
MySleep(nTieEsp) // agregue este tiempo de espera
IF ! BuildCommDcb(sarta, @cDcb)
nError = GetCommError( IdPort)
MsgInfo( "Error al Configurar: " + Str( nError ) )
BREAK
ELSE
//MsgRun("Puerto Configurado")
ENDIF
russimicro wrote:Antonio...
Lo solucione asi : Sleep(10);
1. Modificacion de comm.c :
- Code: Select all Expand view
while( 1 )
{
DWORD x;
WaitCommEvent( pComm->hCom, &event, NULL );
ClearCommError( pComm->hCom, &event, &stat );
Sleep(10); // agregue este tiempo de espera
ReadFile( pComm->hCom, buf, min( 1023, stat.cbInQue ), &dwBytesReaded, &overlap );
GetOverlappedResult( pComm->hCom, &overlap, &dwBytesReaded, FALSE );
buf[ dwBytesReaded + 1 ] = 0;
for( x = 0; x < dwBytesReaded ; x++ )
{
pComm->combuf[ pComm->comheadbuf ] = buf[ x ];
pComm->comheadbuf++;
if( pComm->comheadbuf > COMBUFSIZE - 1 )
pComm->comheadbuf = 0;
}
if( pComm->CommNotifyHwnd != NULL )
SendMessage( pComm->CommNotifyHwnd, WM_COMMNOTIFY, ( WPARAM ) pComm,
MAKELONG( CN_RECEIVE, 0 ) );
};
2. agregando tiempo de espera en los .prg, entre el readcomm y BuildCommDcb : MySleep(nTieEsp) ejp 10
IdPort := OpenComm("COM"+STR(nNroPue,1), 1024,128) //,2048,512
MySleep(nTieEsp) // agregue este tiempo de espera
IF ! BuildCommDcb(sarta, @cDcb)
nError = GetCommError( IdPort)
MsgInfo( "Error al Configurar: " + Str( nError ) )
BREAK
ELSE
//MsgRun("Puerto Configurado")
ENDIF
Gracias por su valiosa colaboración
// favor incluir ese pequeño detalle en las lib de fivewin (xharbour.com)
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: No registered users and 52 guests