TIMER on Dialog

Post Reply
mosh1
Posts: 129
Joined: Sun Oct 09, 2011 3:50 pm

TIMER on Dialog

Post by mosh1 »

Hi! Why TIMER doesn't work on dialogs? I can set TIMER on Window, but not on a dilaog
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: TIMER on Dialog

Post 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

//----------------------------------------------------------------------------//
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
mosh1
Posts: 129
Joined: Sun Oct 09, 2011 3:50 pm

Re: TIMER on Dialog

Post by mosh1 »

Thanks!
mosh1
Posts: 129
Joined: Sun Oct 09, 2011 3:50 pm

Re: TIMER on Dialog

Post 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)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: TIMER on Dialog

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
mosh1
Posts: 129
Joined: Sun Oct 09, 2011 3:50 pm

Re: TIMER on Dialog

Post 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?
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: TIMER on Dialog

Post by Antonio Linares »

I am afraid they use different implementations. FWH comm management is based on GUI and events
regards, saludos

Antonio Linares
www.fivetechsoft.com
mosh1
Posts: 129
Joined: Sun Oct 09, 2011 3:50 pm

Re: TIMER on Dialog

Post 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 ?
RuFerSo
Posts: 55
Joined: Mon Feb 20, 2012 2:56 pm

Re: TIMER on Dialog

Post 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
mosh1
Posts: 129
Joined: Sun Oct 09, 2011 3:50 pm

Re: TIMER on Dialog

Post 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"
mosh1
Posts: 129
Joined: Sun Oct 09, 2011 3:50 pm

Re: TIMER on Dialog

Post 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?
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: TIMER on Dialog

Post by Antonio Linares »

Mosh,

Please provide a PRG example, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
mosh1
Posts: 129
Joined: Sun Oct 09, 2011 3:50 pm

Re: TIMER on Dialog

Post 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.
////////////////////


 
mosh1
Posts: 129
Joined: Sun Oct 09, 2011 3:50 pm

Re: TIMER on Dialog

Post 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
Post Reply