BuildComDcb()

BuildComDcb()

Postby Jeff Barnes » 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)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: BuildComDcb()

Postby Otto » Thu Jan 17, 2013 3: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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: BuildComDcb()

Postby Jeff Barnes » Thu Jan 17, 2013 3:42 pm

Thanks Otto ... Is there a Com Write function?
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: BuildComDcb()

Postby Otto » Thu Jan 17, 2013 3:50 pm

Jeff,
yes.
I never tried these functions.
Best regards,
Otto

Code: Select all  Expand view
//*****************************************************************************
//*
//*     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;
}

 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: BuildComDcb()

Postby Jeff Barnes » Fri Jan 18, 2013 1: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)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: BuildComDcb()

Postby Otto » Fri Jan 18, 2013 10:04 am

Best regards,
otto
Code: Select all  Expand view
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 ) );
}
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: BuildComDcb()

Postby Antonio Linares » Fri Jan 18, 2013 12:46 pm

regards, saludos

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

Re: BuildComDcb()

Postby Jeff Barnes » Fri Jan 18, 2013 2: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)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: BuildComDcb()

Postby Enrico Maria Giordano » Sat Jan 26, 2013 12:31 pm

Try this terminal sample:

Code: Select all  Expand view
#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: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: BuildComDcb()

Postby Jeff Barnes » 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)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: BuildComDcb()

Postby Enrico Maria Giordano » Sat Jan 26, 2013 1: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
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

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