#include "Fivewin.ch"
FUNCTION MAIN()
LOCAL oDlg
LOCAL oGet, cTxt := ""
LOCAL nCom
DEFINE DIALOG oDlg;
SIZE 500, 500;
TITLE "Terminale"
@ 0, 0 GET oGet VAR cTxt MEMO READONLY
oGet:bKeyDown = { | nKey | Tasti( nCom, nKey ) }
ACTIVATE DIALOG oDlg;
ON INIT ( oGet:AdjClient(),;
nCom := APRICOM( oDlg, oGet ),;
IF( nCom < 0, oDlg:End(), ) );
CENTER
IF nCom >= 0; CLOSECOMM( nCom ); ENDIF
RETURN NIL
STATIC FUNCTION TASTI( nCom, nKey )
SENDSTR( nCom, CHR( nKey ) )
RETURN NIL
STATIC FUNCTION APRICOM( oDlg, oGet )
LOCAL nCom, cDcb
BEGIN SEQUENCE
nCom = OPENCOMM( "COM1", 16384, 16384 )
IF nCom < 0
? "Errore di apertura della porta di comunicazione."
BREAK
ENDIF
BUILDCOMMDCB( "COM1:115200,N,8,1", @cDcb )
IF !SETCOMMSTATE( nCom, cDcb )
? "Errore di impostazione della porta di comunicazione."
BREAK
ENDIF
oDlg:bCommNotify = { | nCom | Connect( nCom, oGet ),;
EnableCommNotification( nCom, oDlg:hWnd, 1, -1 ) }
IF !ENABLECOMMNOTIFICATION( nCom, oDlg:hWnd, 1, -1 )
? "Errore di abilitazione della notifica."
BREAK
ENDIF
RECOVER
nCom = -1
END SEQUENCE
RETURN nCom
STATIC FUNCTION CONNECT( nCom, oGet )
LOCAL cStr
ENABLECOMMNOTIFICATION( nCom, 0, 1, -1 )
cStr = RECEIVESTR( nCom )
cStr = STRTRAN( cStr, CHR( 13 ), "" )
cStr = STRTRAN( cStr, CHR( 10 ), CRLF )
oGet:Append( cStr )
RETURN NIL
STATIC FUNCTION SENDSTR( nCom, cString )
LOCAL nBytes := WRITECOMM( nCom, cString )
RETURN nBytes = LEN( cString )
STATIC FUNCTION RECEIVESTR( nCom )
LOCAL cBuf := SPACE( 1000 )
RETURN LEFT( cBuf, READCOMM( nCom, @cBuf ) )
BUILDCOMMDCB( "COM1:115200,N,8,1", @cDcb )
BUILDCOMMDCB( "COM1:9600,N,8,1", @cDcb )
*********************************************
function InitCOMM()
local cDcb, nError, nBytes
local nComm := OpenComm( "COM1", 1024 , 128)
if ! BuildCommDcb( "COM1:9600,N,8,1", @cDcb )
MsgStop( "Error BUILD!" )
return .f.
endif
if ! SetCommState( cDcb )
MsgStop( "Error SETCOMM!" )
return .f.
endif
return nComm
favory wrote:
- Code: Select all Expand view
if ! SetCommState( cDcb )
if ! SetCommState( nComm, cDcb )
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 104 guests