TIMER on Dialog
TIMER on Dialog
Hi! Why TIMER doesn't work on dialogs? I can set TIMER on Window, but not on a dilaog
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: TIMER on Dialog
You have to create the TIMER from the ON INIT clause of the ACTIVATE DIALOG ...
FWH\samples\TestTim4.prg
FWH\samples\TestTim4.prg
Code: Select all
#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
//----------------------------------------------------------------------------//
Re: TIMER on Dialog
Can I set timer to work on different dialogs ? I need to set several MDI Children with dialogs on them. Timer is checking serial port for data from barcode scanner.
One more question : when i open MDI Child
DEFINE WINDOW oWndChild MDICHILD OF oWnd ;
FROM 5,5 TO 6,6;
COLOR "N/W" ;
TITLE " New Sale " ;
border none nomaximize nominimize
oWnd is in static it creates new instance but not the timer ? (Timer created ON INIT of Dialog)
One more question : when i open MDI Child
DEFINE WINDOW oWndChild MDICHILD OF oWnd ;
FROM 5,5 TO 6,6;
COLOR "N/W" ;
TITLE " New Sale " ;
border none nomaximize nominimize
oWnd is in static it creates new instance but not the timer ? (Timer created ON INIT of Dialog)
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: TIMER on Dialog
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:
http://forums.fivetechsupport.com/viewt ... 32#p131532
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:
http://forums.fivetechsupport.com/viewt ... 32#p131532
Re: TIMER on Dialog
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:
http://forums.fivetechsupport.com/viewt ... 32#p131532
Are these functions compatible with HBcomm? Can I use handle from HBcomm?EnableCommNotification( nComm, oDlg:hWnd, IN_BUFFER, IN_BUFFER )
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: TIMER on Dialog
I am afraid they use different implementations. FWH comm management is based on GUI and events
Re: TIMER on Dialog
Hi! Trying to rewrite my project with FW comm functions. First question :
Why string : "COM1:9600,n,8,1"
is accepted by BuildCommDcb( )
but string (which are port defaults taken from registry!) : "COM1:9600,o,7,0"
is rejected ?
Why string : "COM1:9600,n,8,1"
is accepted by BuildCommDcb( )
but string (which are port defaults taken from registry!) : "COM1:9600,o,7,0"
is rejected ?
Re: TIMER on Dialog
Sorry for my bad English.
Could be that the "o" should be a number? "COM1:9600,o,7,0"
Best regards Ruben Fernandez
Could be that the "o" should be a number? "COM1:9600,o,7,0"
Best regards Ruben Fernandez
Re: TIMER on Dialog
No, it's letter "o".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
Problem solved : the "0" to the right should be "1"
Re: TIMER on Dialog
Now all is working now except one thing : how to make it work on Dialog which get a focus?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.
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: TIMER on Dialog
Mosh,
Please provide a PRG example, thanks
Please provide a PRG example, thanks
Re: TIMER on Dialog
Code: Select all
#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,_
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.
////////////////////
Re: TIMER on Dialog
There are another problem too : when I close child window and open it again it gives exception error. May be there should be a
some DisableCommNotification() too? ? Also when I close comm port and open it again it gives
SetCommState Error initializing port error
some DisableCommNotification() too? ? Also when I close comm port and open it again it gives
SetCommState Error initializing port error
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: TIMER on Dialog
Try
EMG
Code: Select all
EnableCommNotification( nComm, 0, IN_BUFFER, IN_BUFFER)