First FWPPC App - Help :-)

Re: First FWPPC App - Help :-)

Postby Jeff Barnes » Sun Jan 11, 2009 7:55 pm

I am actually running my test app directly on a Dell Axim X50 running Windows Mobile 2003 Second Edition.

I was really hoping that the FWPPC commands would be the same as in FWH.

Other than TestComm.prg which seems to only have the functions but no real working sample, is there a sample file that actually takes control and sends/receives data from the comm port that I can play with?
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

Re: First FWPPC App - Help :-)

Postby Jeff Barnes » Sun Jan 11, 2009 8:44 pm

I found some code in the forum ...

Code: Select all  Expand view
Function SerialTest(lIRmode)
   local hComm, nChars, cRead
   IF (hComm:=OpenCom(1, 9600,,,, lIRmode )) > 0
      msginfo("Ok Com1: "+str(hComm) + ", lIRmode:"+if(lIRmode,".t.",".f."))
       ComSend( hComm, "hi there" )
         msginfo("ComSend(hithere) regreso .T.")
         cRead:=ComRead( hComm, nChars )
         msginfo("ComRead() regreso: "+cRead+ ",("+alltrim(str(len(cRead)))+" chs)")
      //else
         msginfo("ComSend(hithere) regreso .FALSO.")
      //ENDIF
      ComClose( hComm )
      msginfo("puerto cerrado")
   ENDIF
Return Nil


The port opens without any problems but it generates a GPF when it gets to the ComSend() function.
I also tried changing the code a bit so I could just issue a ComRead() ... same thing ... I get a GPF.

The above test was done using the emulator provided with FWPPC.

I am stumped ... I am not even able to read "junk" from the com port.

Can you please check your com functions and let me know if they work on you end?
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

Re: First FWPPC App - Help :-)

Postby Antonio Linares » Sun Jan 11, 2009 11:55 pm

Jeff,

What value is shown for hComm ?
regards, saludos

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

Re: First FWPPC App - Help :-)

Postby Jeff Barnes » Mon Jan 12, 2009 12:07 am

For hComm:=OpenCom(1, 9600,n,8,1, .f. )) is get a value of 767688654 (actually, the number changes)
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

Re: First FWPPC App - Help :-)

Postby Antonio Linares » Mon Jan 12, 2009 12:15 am

Jeff,

Have you tried it on the real Pocket PC ?
regards, saludos

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

Re: First FWPPC App - Help :-)

Postby Jeff Barnes » Mon Jan 12, 2009 12:47 am

on the real pocket pc I get different values as well.

I am having some luck with: ReadByte( hComm )

But this is only giving one char at a time. I am going to play with this one a bit.
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

Re: First FWPPC App - Help :-)

Postby Jeff Barnes » Mon Jan 12, 2009 1:28 am

I am able to read data as per my last post :-) so at least we know we are connecting and the ports are configured correctly.

Now I need a way of reading and writing the data without doing it one character at a time. Any Ideas???
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

Re: First FWPPC App - Help :-)

Postby Antonio Linares » Mon Jan 12, 2009 8:10 am

Jeff,

You could use a function like this:
Code: Select all  Expand view
function SendBytes( hComm, cString )

   local n

   for n = 1 to Len( cString )
      ComSend( hComm, SubStr( cString, n, 1 ) )
      // a SysRefresh() call could be needed here
   next

return nil // Len( cString )
regards, saludos

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

Re: First FWPPC App - Help :-)

Postby Jeff Barnes » Fri Jan 16, 2009 9:17 pm

Hi Antonio,

I tried the code you posted in the last message but I still get a GPF as soon as I try to issue the ComSend().

Code: Select all  Expand view
Function  ComSend( hComm, cString )
   LOCAL nBytesend, nBytes:= Len( cString )
   nByteSend := WriteComm( hComm, @cString, nBytes )
Return  ( nByteSend == nBytes )


The GPF is caused by ... nByteSend := WriteComm( hComm, @cString, nBytes )

Is it possible I am missing something in the build file?

Code: Select all  Expand view
@ECHO OFF
CLS
ECHO ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
ECHO ³ FiveWin for Pocket PC - October 2008             Harbour development power ³Ü
ECHO ³ (c) FiveTech, 1993-2008                    for Microsoft Windows Pocket PC ³Û
ECHO ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙÛ
ECHO ÿ ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß

if A%1 == A GOTO :SINTAX
if NOT EXIST %1.prg GOTO :NOEXIST

ECHO Compiling...

IF "%FWDIR%" == "" set FWDIR="c:\fwppc"

set hdir=c:\harbour_ce\
set hdirc=%hdir%\bin
set hdirl=%hdir%\lib
set fwppc=%FWDIR%
set vcdir=c:\vce
set include=%vcdir%\include\arm;%hdir%\include;%include%
set lib=%vcdir%\lib;%hdir%\lib;%lib%
set emulator_shared_folder=c:\pocketpc

%hdirc%\harbour %1 /n /i%fwppc%\include;%hdir%\include /p %2 %3 > clip.log
IF ERRORLEVEL 1 GOTO COMPILEERROR
@type clip.log

%vcdir%\bin\clarm -W3 -c /DARM /DUNICODE /I%hdir%\include /I%fwppc%\include %1.c
:ENDCOMPILE

IF EXIST %1.rc %vcdir%\bin\rc -r -d_CE %1

echo %1.obj  > msvc.tmp

echo %fwppc%\lib\FiveCE.lib %fwppc%\lib\FiveCEC.lib  >> msvc.tmp
echo %hdirl%\hbrtl.lib  >> msvc.tmp
echo %hdirl%\hbvm.lib  >> msvc.tmp
echo %hdirl%\gtgui.lib  >> msvc.tmp
echo %hdirl%\hblang.lib  >> msvc.tmp
echo %hdirl%\hbmacro.lib  >> msvc.tmp
echo %hdirl%\hbrdd.lib  >> msvc.tmp
echo %hdirl%\rddntx.lib  >> msvc.tmp
echo %hdirl%\rddcdx.lib  >> msvc.tmp
echo %hdirl%\rddfpt.lib  >> msvc.tmp
echo %hdirl%\hbsix.lib  >> msvc.tmp
echo %hdirl%\hbdebug.lib  >> msvc.tmp
echo %hdirl%\hbcommon.lib  >> msvc.tmp
echo %hdirl%\hbpp.lib  >> msvc.tmp
echo %hdirl%\hbcpage.lib  >> msvc.tmp
echo %hdirl%\hbw32.lib  >> msvc.tmp
rem echo %hdirl%\tip.lib  >> msvc.tmp
echo %hdirl%\hbpcre.lib  >> msvc.tmp

echo %vcdir%\lib\arm\coredll.lib   >> msvc.tmp
echo %vcdir%\lib\arm\corelibc.lib  >> msvc.tmp
echo %vcdir%\lib\arm\aygshell.lib  >> msvc.tmp
echo %vcdir%\lib\arm\ws2.lib  >> msvc.tmp
echo %vcdir%\lib\arm\mfcce400.lib  >> msvc.tmp
echo %vcdir%\lib\arm\ole32.lib  >> msvc.tmp
echo %vcdir%\lib\arm\oleaut32.lib  >> msvc.tmp
echo %vcdir%\lib\arm\olece400.lib  >> msvc.tmp
echo %vcdir%\lib\arm\uuid.lib  >> msvc.tmp
echo %vcdir%\lib\arm\ceshell.lib  >> msvc.tmp
echo %vcdir%\lib\arm\commctrl.lib  >> msvc.tmp
echo %vcdir%\lib\arm\wininet.lib  >> msvc.tmp

IF EXIST %1.res echo %1.res >> msvc.tmp

%vcdir%\bin\link @msvc.tmp /nologo /SUBSYSTEM:WINDOWSCE,4.20 /MACHINE:ARM /ARMPADCODE:NO

IF ERRORLEVEL 1 GOTO LINKERROR
ECHO * Application successfully built *
copy %1.exe %emulator_shared_folder%
GOTO EXIT
ECHO

rem delete temporary files
@del %1.c
@del %1.obj
@del %1.ppo
@del msvc.tmp

:COMPILEERROR
@type clip.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


I am using the actual Pocket PC for the tests.
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

Re: First FWPPC App - Help :-)

Postby Antonio Linares » Sat Jan 17, 2009 10:40 am

Jeff,

Please change this function this way and lets see if the execution goes through it:
Code: Select all  Expand view
BOOL GetOverlappedResult( HANDLE hFile, LPOVERLAPPED lpOverlapped, LPDWORD lpNumberOfBytesTransferred, BOOL bWait )
{
   MessageBox( 0, L"Inside GetOverlappedResult", L"Ok", 0 );

   return FALSE;
}
regards, saludos

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

Re: First FWPPC App - Help :-)

Postby Antonio Linares » Sat Jan 17, 2009 10:44 am

Jeff,

Also, please add this function to your code (inside the #pragma BEGINDUMP section):
Code: Select all  Expand view
HB_FUNC( WRITECOMM )
{
  DWORD dw = 0;
  WriteFile( (HANDLE ) hb_parnl( 1 ), ( LPVOID ) hb_parc( 2 ), ( DWORD ) hb_parni( 3 ), &dw, NULL );
  hb_retni( ( int ) dw ? dw : -1);
}
regards, saludos

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

Re: First FWPPC App - Help :-)

Postby Antonio Linares » Sat Jan 17, 2009 4:05 pm

Jeff,

Much better if you include all these functions to your PRG:
Code: Select all  Expand view
/////////////////////////////////////////////
//
// Funciones de comunicacion por Rs232
//
////////////////////////////////////////////
#include "Fwce.ch"

#define BUFF_IN               1024
#define BUFF_OUT              1024
#define GENERIC_READ          0x80000000
#define GENERIC_WRITE         0x40000000
#define OPEN_EXISTING         3
#define FILE_ATTRIBUTE_NORMAL 0x00000080

#define NOPARITY            0
#define ODDPARITY           1
#define EVENPARITY          2
#define MARKPARITY          3
#define SPACEPARITY         4

#define ONESTOPBIT          0
#define ONE5STOPBITS        1
#define TWOSTOPBITS         2

///////////////////////////////////////////////
//
// OpenCom
// Abre el puerto especificado y lo configura
//////////////////////////////////////////////
Function OpenCom( nCom, nBauds, nParity, nDataByt, nStopBits, lIRmode )
LOCAL hComm, cComm

DEFAULT nCom := 1, nBauds := 2400, nParity := NOPARITY, nDataByt := 8, lIRmode := .f.
DEFAULT nStopBits := ONESTOPBIT
cComm := "Com"+ AllTrim( Str( nCom, 2 ) )+ ":"

hComm := CreateFile( cComm, nOr(GENERIC_WRITE, GENERIC_READ) , 0, 0, OPEN_EXISTING, 0,0 )

IF hComm ==-1
  Msginfo("Fallo al abrir "+ cComm)
  Return -1
ENDIF

IF lIRMode
  IF !RAWIRON( hComm )
    Msginfo( "Fallo al iniciar RAWIR")
    ComClose( hComm )
    RETURN -1
  ENDIF
ENDIF


IF !SetComm( hComm, nBauds, nParity, nDataByt, nStopBits )
  MsgInfo("Fallo al configurar "+ cComm)
  ComClose( hComm )
  RETURN -1
ENDIF

RETURN hComm


///////////////////////////////////
//
// ComSend( nHdlCom, cString )
//
////////////////////////////////////////////

Function  ComSend( hComm, cString )

LOCAL nBytesend, nBytes:= Len( cString )

nByteSend := WriteComm( hComm, @cString, nBytes )

Return  ( nByteSend == nBytes )


////////////////////////////////////
//
// ComRead( nHdlCom, nChars )
//
////////////////////////////////////////////
Function ComRead( nHdlCom, nChars )
LOCAL nBytes, cBuffIn := Space(BUFF_IN)

nBytes := ReadComm( nHdlCom, @cBuffIn, nChars )

RETURN if( nBytes >0, Left( cBuffIn, nBytes ),"" )


////////////////////////////////////
//
// ComClose( nHdlCom)
//
////////////////////////////////////////////
FUNCTION ComClose( hComm )

RAWIROFF( hComm )
CloseHandle( hComm )

RETURN .t.


#pragma BEGINDUMP

#include <windows.h>
#include <winbase.h>
#include <hbapi.h>
#include <aygshell.h>

HB_FUNC( SETCOMM )
{
   DCB dcb;
   COMMTIMEOUTS timeouts;

   SetupComm(( HANDLE) hb_parnl( 1 ), BUFF_IN, BUFF_OUT ) ;

   GetCommState( ( HANDLE ) hb_parnl( 1 ), &dcb );

   dcb.BaudRate             = hb_parnl( 2 );
   dcb.Parity               = hb_parni( 3 );
   dcb.ByteSize             = hb_parni( 4 );
   dcb.StopBits             = hb_parni( 5 );

   dcb.fBinary              = TRUE;
   dcb.fParity              = TRUE;
   dcb.fOutxCtsFlow         = FALSE;
   dcb.fOutxDsrFlow         = FALSE;
   dcb.fDtrControl          = DTR_CONTROL_DISABLE;
   dcb.fDsrSensitivity      = FALSE;
   dcb.fTXContinueOnXoff    = FALSE;
   dcb.fOutX                = FALSE;
   dcb.fInX                 = FALSE;
   dcb.fErrorChar           = FALSE;
   dcb.fNull                = FALSE;
   dcb.fRtsControl          = RTS_CONTROL_DISABLE;
   dcb.fAbortOnError        = FALSE;

   GetCommTimeouts(( HANDLE) hb_parnl, &timeouts);

   timeouts.ReadIntervalTimeout         = 0;
   timeouts.ReadTotalTimeoutMultiplier  = 0;
   timeouts.ReadTotalTimeoutConstant    = 1000;
   timeouts.WriteTotalTimeoutMultiplier = 0;
   timeouts.WriteTotalTimeoutConstant   = 0;


   SetCommTimeouts(( HANDLE) hb_parnl( 1 ), &timeouts );

   hb_retl(SetCommState( ( HANDLE ) hb_parnl( 1 ), &dcb ));
}

HB_FUNC( READCOMM )
{
  DWORD dw = 0;
  ReadFile( ( HANDLE ) hb_parnl( 1 ), ( LPVOID ) hb_parc( 2 ), ( DWORD ) hb_parni( 3 ), &dw, NULL );

  hb_retni( ( int ) dw ? dw : -1 );
}

HB_FUNC( WRITECOMM )
{
  DWORD dw = 0;
  WriteFile( (HANDLE ) hb_parnl( 1 ), ( LPVOID ) hb_parc( 2 ), ( DWORD ) hb_parni( 3 ), &dw, NULL );
  hb_retni( ( int ) dw ? dw : -1);
}


HB_FUNC( RAWIRON )
{

   hb_retl( EscapeCommFunction( ( HANDLE ) hb_parnl( 1 ), SETIR ) );
}

HB_FUNC( RAWIROFF )
{

   hb_retl( EscapeCommFunction( ( HANDLE ) hb_parnl( 1 ), CLRIR ) );
}

#pragma ENDDUMP
regards, saludos

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

Re: First FWPPC App - Help :-)

Postby Jeff Barnes » Sun Jan 18, 2009 12:41 am

Antonio,

Many thanks for all your help on this.

I am successfully reading the data from my device on my pocket pc.

I still need to do some "write" tests but my initial tests show the the GPF is now gone. :D


Again, thank you thank you thank you.
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

Re: First FWPPC App - Help :-)

Postby Jeff Barnes » Sun Jan 18, 2009 1:54 am

I am also now writing to my device :D :D :D
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

Re: First FWPPC App - Help :-)

Postby Antonio Linares » Sun Jan 18, 2009 7:50 am

Jeff,

Very good! :-)

Would you mind to post a little working example for other FWPPC users ?

many thanks :-)
regards, saludos

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

PreviousNext

Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 21 guests

cron