FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour BuildComDcb()
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
BuildComDcb()
Posted: Thu Jan 17, 2013 12:49 PM
I have a strange problem with BuildComDbc()....

When using the MicroSoft Bluetooth Stack if I try:

IF BuildCommDcb( "COM"+alltrim(str(nComPort))+":9600,N,8,1", @cDcb )
Endif

It returns .f.

On the Toshiba Bluetooth Stack it returns .t.

Here is the strange part....
If I remove the "IF" and just try "BuildCommDcb( "COM"+alltrim(str(nComPort))+":9600,N,8,1", @cDcb )"
then continue with my connection it does connect to the COM port BUT, if I connect and disconnect 4 times in a row the software will freeze when I do a:
WriteComm( nComm, Hex2Str("027004020861DF03"))

Again, using the Toshiba Bluetooth stack I can connect/disconnect as many times as I want without any problems.

Any ideas?
Is there any other way to connect to a Bluetooth Serial Port (other lib maybe) ???
Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: BuildComDcb()
Posted: Thu Jan 17, 2013 03:29 PM

Jeff,
I had problems with FW-build in COM support and RDP.
I have substituted through this obj.

http://www.atzwanger-software.com/fw/COMTOOLS.ZIP

Best regards,
Otto

Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: BuildComDcb()
Posted: Thu Jan 17, 2013 03:42 PM

Thanks Otto ... Is there a Com Write function?

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: BuildComDcb()
Posted: Thu Jan 17, 2013 03:50 PM
Jeff,
yes.
I never tried these functions.
Best regards,
Otto

Code (fw): Select all Collapse
//*****************************************************************************
//*
//*     ComWrite
//*
//*****************************************************************************
//  Ein Zeichen senden
//  Nr      : Ist die Nummer des Com-Ports (0=COM1 1=COM2 ...)
//  Zeichen : Ist das Zeichen das gesendet werden soll.
//  Ergibt die Anzahl der gesendeten Zeichen
int ComWrite(unsigned Nr,int Zeichen)
{
DWORD           dwCount;


    if(Nr>=MAX_COM_PORTS)return 0;
    if(!bIsOpen[Nr])return 0;

    WriteFile(hComFile[Nr],&Zeichen,1,&dwCount,0);


return dwCount;
}

//*****************************************************************************
//*
//*     ComWrite
//*
//*****************************************************************************
//  Mehrere Zeichen schreiben
//  Nr      : Ist die Nummer des Com-Ports (0=COM1 1=COM2 ...)
//  Buffer  : Buffer in dem die Zeichen gespeichert werden
//  Count   : Anzahl der zu sendenden Zeichen
//  Ergibt die Anzahl der gesendeten Zeichen
int ComWriteBuf(unsigned Nr,void *Buffer,int Count)
{
DWORD           dwCount;


    if(Nr>=MAX_COM_PORTS)return 0;
    if(!bIsOpen[Nr])return 0;

    WriteFile(hComFile[Nr],Buffer,Count,&dwCount,0);

return dwCount;
}
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: BuildComDcb()
Posted: Fri Jan 18, 2013 01:07 AM

Otto, I don't see where I can set the post speed, parity etc...

Am I missing something?

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: BuildComDcb()
Posted: Fri Jan 18, 2013 10:04 AM
Best regards,
otto
Code (fw): Select all Collapse
HB_FUNC( COMOPEN ) // () --> nPorts
{
    unsigned Nr     = hb_parni( 1 );
    int iBaud       = 9600;
    int iParity     = P_NONE;
    int iStopbits = S_1BIT;
    int iDatabits = D_8BIT;

    if ISNUM( 2 ) iBaud         = hb_parni( 2 );
    if ISNUM( 3 ) iParity   = hb_parni( 3 );
    if ISNUM( 4 ) iStopbits = hb_parni( 4 );
    if ISNUM( 5 ) iDatabits = hb_parni( 5 );


    hb_retl( ComOpen ( Nr, iBaud, iParity, iStopbits, iDatabits ) );
}
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: BuildComDcb()
Posted: Fri Jan 18, 2013 12:46 PM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: BuildComDcb()
Posted: Fri Jan 18, 2013 02:45 PM

Not having any luck with this...

ComOpen returns .t. but ComWrite returns 0

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: BuildComDcb()
Posted: Sat Jan 26, 2013 12:31 PM
Try this terminal sample:

Code (fw): Select all Collapse
#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
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: BuildComDcb()
Posted: Sat Jan 26, 2013 12:45 PM

Thanks Enrico,

Your test program seems to be collecting data from com port...
I will need to modify my program to see if it solves the problem of connecting/disconnecting. With the MS stack I can only connect/disconnect about 4 times before the system locks up... This never happens with the Toshiba Stack.

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: BuildComDcb()
Posted: Sat Jan 26, 2013 01:01 PM
Jeff Barnes wrote:Thanks Enrico,

Your test program seems to be collecting data from com port...


You can also send data hitting keys on the keyboard.

EMG

Continue the discussion