FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Pocket PC Serial port
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Serial port
Posted: Fri Jan 13, 2006 01:13 PM
I'm trying to use the serial port through the emulator using the following test sample:

#include "Fwce.ch"


FUNCTION MAIN()

    LOCAL oWnd

    LOCAL cCom := " "

    LOCAL cCod := ""

    LOCAL oTmr, hSer, oGet

    DEFINE WINDOW oWnd;
           TITLE "Test seriale"

    @ 1, 1 SAY "Numero porta:"

    @ 1, 10 GET cCom;
            SIZE 30, 20;
            PICTURE "9";
            VALID !EMPTY( cCom )

    @ 3, 1 GET oGet VAR cCod MEMO;
           SIZE 200, 100

    @ 10, 1 BUTTON "Apri porta";
            SIZE 100, 20;
            ACTION hSer := APRI( cCom )

    @ 10, 20 BUTTON "Esci";
             SIZE 70, 20;
             ACTION oWnd:End();
             CANCEL

    DEFINE TIMER oTmr OF oWnd;
           INTERVAL 1000;
           ACTION LEGGI( oTmr, hSer, oGet )

    ACTIVATE WINDOW oWnd;
             ON INIT oTmr:Activate()

    IF hSer != -1; CLOSEHANDLE( hSer ); ENDIF

    oTmr:End()

    RETURN NIL


#define GENERIC_READ 0x80000000 
#define GENERIC_WRITE 0x40000000
#define OPEN_EXISTING 3 
#define FILE_ATTRIBUTE_NORMAL 0x00000080 


STATIC FUNCTION APRI( cCom )

    LOCAL hSer := CREATEFILE( "COM" + cCom + ":", GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL )

    IF hSer != -1
        MSGINFO( "Porta COM" + cCom + " aperta correttamente" )
    ELSE
        MSGINFO( "Impossibile aprire la porta COM" + cCom )
    ENDIF

    RETURN hSer


STATIC FUNCTION LEGGI( oTmr, hSer, oGet )

    LOCAL cTxt := ""

    LOCAL nChr := 0

    IF hSer = NIL .OR. hSer = -1; RETURN NIL; ENDIF

    oTmr:DeActivate()

    WHILE nChr != 0
        nChr = BIN2L( READBYTE( hSer ) )
        cTxt += CHR( nChr )
    ENDDO

    IF !EMPTY( cTxt )
        oGet:VarPut( cTxt )
        oGet:Refresh()
    ENDIF

    oTmr:Activate()

    RETURN NIL


Someone could test it on a real pocket PC?

A question: is it possible (and needed) to set the port parameters (ie. baud rate, stop bits) and how?

EMG
Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
Re: Serial port
Posted: Fri Jan 13, 2006 09:20 PM
EnricoMaria wrote:I'm trying to use the serial port through the emulator using the following test sample:

#include "Fwce.ch"


FUNCTION MAIN()

    LOCAL oWnd

    LOCAL cCom := " "

    LOCAL cCod := ""

    LOCAL oTmr, hSer, oGet

    DEFINE WINDOW oWnd;
           TITLE "Test seriale"

    @ 1, 1 SAY "Numero porta:"

    @ 1, 10 GET cCom;
            SIZE 30, 20;
            PICTURE "9";
            VALID !EMPTY( cCom )

    @ 3, 1 GET oGet VAR cCod MEMO;
           SIZE 200, 100

    @ 10, 1 BUTTON "Apri porta";
            SIZE 100, 20;
            ACTION hSer := APRI( cCom )

    @ 10, 20 BUTTON "Esci";
             SIZE 70, 20;
             ACTION oWnd:End();
             CANCEL

    DEFINE TIMER oTmr OF oWnd;
           INTERVAL 1000;
           ACTION LEGGI( oTmr, hSer, oGet )

    ACTIVATE WINDOW oWnd;
             ON INIT oTmr:Activate()

    IF hSer != -1; CLOSEHANDLE( hSer ); ENDIF

    oTmr:End()

    RETURN NIL


#define GENERIC_READ 0x80000000 
#define GENERIC_WRITE 0x40000000
#define OPEN_EXISTING 3 
#define FILE_ATTRIBUTE_NORMAL 0x00000080 


STATIC FUNCTION APRI( cCom )

    LOCAL hSer := CREATEFILE( "COM" + cCom + ":", GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL )

    IF hSer != -1
        MSGINFO( "Porta COM" + cCom + " aperta correttamente" )
    ELSE
        MSGINFO( "Impossibile aprire la porta COM" + cCom )
    ENDIF

    RETURN hSer


STATIC FUNCTION LEGGI( oTmr, hSer, oGet )

    LOCAL cTxt := ""

    LOCAL nChr := 0

    IF hSer = NIL .OR. hSer = -1; RETURN NIL; ENDIF

    oTmr:DeActivate()

    WHILE nChr != 0
        nChr = BIN2L( READBYTE( hSer ) )
        cTxt += CHR( nChr )
    ENDDO

    IF !EMPTY( cTxt )
        oGet:VarPut( cTxt )
        oGet:Refresh()
    ENDIF

    oTmr:Activate()

    RETURN NIL


Someone could test it on a real pocket PC?

A question: is it possible (and needed) to set the port parameters (ie. baud rate, stop bits) and how?

EMG


Enrico

Tested on HP IPAQ 6515

I tested port 1 opened OK without any change. No need to set baud, parity...etc
If i set 2 or any other value, it will not open correct.

If you need any further test, let me know

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Serial port
Posted: Fri Jan 13, 2006 09:45 PM

Thank you! But I need to know if the characters received from the serial port are displayed on the multiget. Can you test it?

EMG

Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
Re: Serial port
Posted: Sat Jan 14, 2006 10:51 AM
EnricoMaria wrote:Thank you! But I need to know if the characters received from the serial port are displayed on the multiget. Can you test it?

EMG


Sorry Enrico, I don't get exactly what you're looking after

Once the port opened correct (nothing is displayed in the multiget)

If you enter data in the multiget the data is kept after opening the com port

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Serial port
Posted: Sat Jan 14, 2006 11:59 AM

I need to display in the multiget the data received from a reader device connected to the serial port.

EMG

Posts: 42
Joined: Sun Oct 09, 2005 11:47 AM
Serial port
Posted: Mon Jan 16, 2006 02:49 AM

Enrico
I've compiled your program and run it with the emulator. It displays characters received OK with a few changes:

Try:

WHILE nChr != 236 .OR. nChr != 10
    nChr = ( READBYTE( hSer ) ) 
    cTxt += CHR( nChr ) 
ENDDO

Previously this was looping so never had a chance to display. Is it possible to transmit a 'prefix' character before your data and a suffix character (eg Chr(10) as above) afterwards so valid data is detected more easily? Notice that 'bin2l' is not required.
I use freeware 'BillSerialMonitor' from www.symcod.com to send test data.
I tried using a port of Telepathy with some success but have now decided to use Antonio's solution as the best (as usual!).

hth

Posts: 42
Joined: Sun Oct 09, 2005 11:47 AM
Serial port
Posted: Mon Jan 16, 2006 02:59 AM

Enrico
Sorry I meant .AND. !!

WHILE nChr != 236 .AND. nChr != 10
nChr = ( READBYTE( hSer ) )
cTxt += CHR( nChr )
ENDDO

hth

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Serial port
Posted: Mon Jan 16, 2006 07:44 AM

Thank you Jon! I will try...

EMG

Continue the discussion