#include "FiveWin.ch"
static oWnd, oTimer
//----------------------------------------------------------------------------//
function Main()
DEFINE DIALOG oWnd FROM 3, 3 TO 20, 50 ;
TITLE OemToAnsi( "Testing timers" )
ACTIVATE DIALOG oWnd ;
ON INIT oWnd:SetMenu( BuildMenu() )
return nil
//----------------------------------------------------------------------------//
function BuildMenu()
local oMenu
MENU oMenu
MENUITEM "&Timers"
MENU
MENUITEM "&Build a Timer" ACTION Timers()
SEPARATOR
MENUITEM "&Bye, bye..." ACTION oWnd:End()
ENDMENU
ENDMENU
return oMenu
//----------------------------------------------------------------------------//
function Timers()
if oTimer == nil
DEFINE TIMER oTimer ACTION oWnd:Say( 2, 2, Time() ) ;
ACTIVATE TIMER oTimer
else
Alert( "There is already a working timer..." )
endif
return nil
//----------------------------------------------------------------------------//
Antonio Linares wrote:Check FWH\samples\phone.prg to review the right way to manage a comm port:
oDlg:bCommNotify = { | nComm, nStatus | BytesAtPort( nComm, nStatus ) }
bCommNotify will be evaluated when data arrives.
Regarding the timer, if you need to use it in a different scope from the dialog, then create it associated to the main window:
viewtopic.php?p=131532#p131532
EnableCommNotification( nComm, oDlg:hWnd, IN_BUFFER, IN_BUFFER )
RuFerSo wrote:Sorry for my bad English.
Could be that the "o" should be a number? "COM1:9600,o,7,0"
Best regards Ruben Fernandez
Antonio Linares wrote:Check FWH\samples\phone.prg to review the right way to manage a comm port:
oDlg:bCommNotify = { | nComm, nStatus | BytesAtPort( nComm, nStatus ) }
bCommNotify will be evaluated when data arrives.
#include "FiveWin.ch"
#include "buch.ch"
#include "posrc.ch"
#define nComm nScanComHandle
#define IN_BUFFER 1024
#define OUT_BUFFER 128
static nKtr
static oDlg,oFont
static oWndChild
static lPortReady
static cBarcode := " "
function ScnBr(oWnd)
local oCartBmp,oScanBmp
DEFAULT nKtr TO 0
nKtr++
lPortReady := InitPort()
cBarcode := " "
DEFINE WINDOW oWndChild MDICHILD OF oWnd ;
FROM 5+nKtr,5+nKtr TO 6,6;
COLOR "N/W" ;
TITLE " New Sale" ;
border none nomaximize nominimize
DEFINE Font oFont Name 'Times New Roman' Bold SIZE 7,-13
DEFINE DIALOG oDlg ;
RESOURCE "SALE" ;
TITLE "Sale" ;
COLOR "N/BG";
FONT oFont ;
OF oWndChild
oDlg:bCommNotify := { | nCom, nStatus | BarScn() }
REDEFINE BUTTONBMP oCartBmp ID ID_CART OF oDlg ;
ACTION oCartBmp:LoadBitmap( "RedCart.bmp" ) ; // MsgInfo( "Checkout" ) ;
BITMAP "GreenCart.bmp"
ACTIVATE DIALOG oDlg NOWAIT ;
ON INIT (oDlg:Move( 0, 0 ),;
if(lPortReady ,EnableCommNotification( nComm, oDlg:hWnd, IN_BUFFER, IN_BUFFER),NIL))
oWndChild:nWidth := oDlg:nWidth+7
oWndChild:nHeight := oDlg:nHeight+32
ACTIVATE WINDOW oWndChild ;
ON INIT oWnd:paint() ;
VALID if(MsgYesNo("Do you want to end sales ?"),(if(lPortReady,CloseComm(nComm),NIL),.t.),.f.)
return nil
////////////////////////////////////////
function BarScn()
local cTmpChr1 := Space( 4 )
local cTmpChr := Space(128)
local nBytesRead
local nStartPos,from_off,to_off
do while .t.
nBytesRead := ReadComm( nComm, @cTmpChr )
if nBytesRead > 0
cTmpChr := substr(cTmpChr,1,nBytesRead)
endif
if nBytesRead > 0
cBarcode += cTmpChr
endif
if cScanDelim$cBarcode
if cScaleBkc$cBarcode
cBarcode := " "
FlushComm(nComm,1)
WriteComm(nComm,cScanPref)
exit
endif
if cScanBkc$cBarcode
nStartPos := at(cScanBkc,cBarcode)+len(cScanBkc)
cBarcode := substr(cBarcode,nStartPos)+space(3)
else
cBarcode := " "
FlushComm(nComm,1) // flush receiving queue
WriteComm(nComm,cScanPref)
exit
endif
BarcFrTo(cBarcode,@from_off,@to_off)
cBarcode := substr(cBarcode,from_off,to_off-from_off)
oDlg:Say( 9, 2,cBarcode ,,,oFont )
endif
exit
enddo
return NIL
//////////
function InitPort()
local cDcb, nError, nBytes
local cCom
if nComm == 0
cCom := "COM1"
nComm = OpenComm( cCom,IN_BUFFER , OUT_BUFFER )
if ! BuildCommDcb( cCom+":9600,o,7,1", @cDcb )
nError = GetCommError(nComm)
MsgInfo( "BuildCommDcb Error: " + Str( nError ) )
return .f.
endif
if ! SetCommState( nComm, cDcb )
nError = GetCommError( nComm )
MsgStop( "Error initializing port !" )
return .f.
endif
if ( nBytes := WriteComm(nComm,cScanPref) ) < 0
nError = GetCommError( nComm )
MsgStop( "Error initializing port!" )
return .f.
else
FlushComm(nComm,1)
endif
endif
return .t.
////////////////////
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 91 guests