PABX System with COM WAIT EVENT

PABX System with COM WAIT EVENT

Postby areang » Sat Sep 23, 2006 9:09 am

Hi All !

I used COMMUNICATION port :
- SetComstateDb
- InitCom
- ReadCom
- CloseCom

Anyone can help me how to use COM WAIT EVENT ?

#include "FiveWin.ch"

function Main()

local oDlg, nComm := InitComm()

DEFINE DIALOG oDlg TITLE "Testing Comm functions"

oDlg:bCommNotify = { | nComm, nStatus | BytesAtPort( nComm, nStatus ) }

>>>???? this block for wait event every time for read comport ????<<<
is that true ?

ACTIVATE DIALOG oDlg ;
ON INIT EnableCommNotification( nComm, oDlg:hWnd, 20, 20 )

CloseComm( nComm )

return nil

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

#ifdef __CLIPPER__
if ! SetCommState( cDcb )
#else
if ! SetCommState( nComm, cDcb )
#endif
MsgStop( "Error SETCOMM!" )
return .f.
endif

return nComm

function BytesAtPort( nComm, nStatus )

local cBuffer := Space(20 )

Msginfo( nSTATUS)
ReadComm( nComm, @cBuffer ) // <<<<---- program will lock here
Msginfo( AllTrim( cBuffer ))

return nil

thanks
Areang
areang
 
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Re: PABX System with COM WAIT EVENT

Postby Enrico Maria Giordano » Sat Sep 23, 2006 12:17 pm

This is a working sample of a simple ASCII terminal program:

Code: Select all  Expand view  RUN
#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 ) )


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby areang » Sun Sep 24, 2006 7:10 am

Enrico.

Thank, you are good guru

Best Regard
Areang
areang
 
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Postby Antonio Linares » Sun Sep 24, 2006 8:55 am

Enrico,

We are going to include it in FWH\samples if you don't mind it. Thanks! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Enrico Maria Giordano » Sun Sep 24, 2006 10:19 am

It is my great pleasure to see any of my samples included in FWH and you are very welcome to do it!

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Sun Sep 24, 2006 1:12 pm

Enrico,

Thanks again :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby areang » Mon Sep 25, 2006 2:19 pm

Enrico, Antonio,

Yes this is good source.

I tried to add some code for save data in my files :

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 )

do while .t.
if mydata->(rlock())
mydata->memofile := cTxt
exit
endif
enddo
mydata->(dbUnlock())

/*
mydata->memofile is memo field type
*/

RETURN NIL
areang
 
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 107 guests