Page 1 of 1

TIMER on Dialog

Posted: Tue Jun 12, 2012 1:34 pm
by mosh1
Hi! Why TIMER doesn't work on dialogs? I can set TIMER on Window, but not on a dilaog

Re: TIMER on Dialog

Posted: Tue Jun 12, 2012 1:54 pm
by Antonio Linares
You have to create the TIMER from the ON INIT clause of the ACTIVATE DIALOG ...

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

Posted: Fri Jun 15, 2012 2:41 pm
by mosh1
Thanks!

Re: TIMER on Dialog

Posted: Tue Jun 26, 2012 10:08 pm
by mosh1
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)

Re: TIMER on Dialog

Posted: Wed Jun 27, 2012 1:25 am
by Antonio Linares
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

Re: TIMER on Dialog

Posted: Wed Jun 27, 2012 3:14 am
by mosh1
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
EnableCommNotification( nComm, oDlg:hWnd, IN_BUFFER, IN_BUFFER )
Are these functions compatible with HBcomm? Can I use handle from HBcomm?

Re: TIMER on Dialog

Posted: Wed Jun 27, 2012 8:44 am
by Antonio Linares
I am afraid they use different implementations. FWH comm management is based on GUI and events

Re: TIMER on Dialog

Posted: Wed Jun 27, 2012 2:21 pm
by mosh1
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 ?

Re: TIMER on Dialog

Posted: Wed Jun 27, 2012 4:47 pm
by RuFerSo
Sorry for my bad English.

Could be that the "o" should be a number? "COM1:9600,o,7,0"
Best regards Ruben Fernandez

Re: TIMER on Dialog

Posted: Wed Jun 27, 2012 5:07 pm
by mosh1
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
No, it's letter "o".
Problem solved : the "0" to the right should be "1"

Re: TIMER on Dialog

Posted: Wed Jun 27, 2012 5:09 pm
by mosh1
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.
Now all is working now except one thing : how to make it work on Dialog which get a focus?

Re: TIMER on Dialog

Posted: Wed Jun 27, 2012 5:52 pm
by Antonio Linares
Mosh,

Please provide a PRG example, thanks

Re: TIMER on Dialog

Posted: Wed Jun 27, 2012 6:30 pm
by mosh1

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

Posted: Thu Jun 28, 2012 6:54 pm
by mosh1
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

Re: TIMER on Dialog

Posted: Thu Jun 28, 2012 10:12 pm
by Enrico Maria Giordano
Try

Code: Select all

EnableCommNotification( nComm, 0, IN_BUFFER, IN_BUFFER)
EMG