Serial port
Posted: Fri Jan 13, 2006 1:13 pm
I'm trying to use the serial port through the emulator using the following test sample:
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
Code: Select all
#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
A question: is it possible (and needed) to set the port parameters (ie. baud rate, stop bits) and how?
EMG