Serial port

Serial port

Postby Enrico Maria Giordano » Fri Jan 13, 2006 1:13 pm

I'm trying to use the serial port through the emulator using the following test sample:

Code: Select all  Expand view  RUN
#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
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Serial port

Postby Richard Chidiak » Fri Jan 13, 2006 9:20 pm

EnricoMaria wrote:I'm trying to use the serial port through the emulator using the following test sample:

Code: Select all  Expand view  RUN
#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
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: Serial port

Postby Enrico Maria Giordano » Fri Jan 13, 2006 9: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
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Serial port

Postby Richard Chidiak » 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
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: Serial port

Postby Enrico Maria Giordano » 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
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Jon Munro » Mon Jan 16, 2006 2: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
User avatar
Jon Munro
 
Posts: 42
Joined: Sun Oct 09, 2005 11:47 am
Location: Brisbane Australia

Postby Jon Munro » Mon Jan 16, 2006 2:59 am

Enrico
Sorry I meant .AND. !!

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

hth
User avatar
Jon Munro
 
Posts: 42
Joined: Sun Oct 09, 2005 11:47 am
Location: Brisbane Australia

Postby Enrico Maria Giordano » Mon Jan 16, 2006 7:44 am

Thank you Jon! I will try...

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


Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 28 guests