Announcement

Collapse
No announcement yet.

TxBuffer problem on serial port

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • TxBuffer problem on serial port

    hi all,
    i have a (small?) problem concerning the serial com ports.
    this problem was already mentioned once by somebody else in the following post: http://www.powerbasic.com/support/pb...ead.php?t=1691
    but no replies...
    thing is that the comm(#hcomm, txbuffer) statement returns 0 as the
    txbuffer length although it has been set to a certain value before.
    i tried the "c:\pbdll60\samples\comm\comm.bas" example.
    this works fine until you try to send a file. then comm.bas tries
    to retrieve the txbuffer length using comm(#hcomm, txbuffer).
    this statement returns 0 as a value. this causes a program crash later
    on in the program because of a division by zero error.
    you can try it in the sample program on your drive by adding 1 line to
    the following routine:
    Code:
    function startcomms as long
        comm open $comport as #hcomm
        if errclear then exit function          ' exit if port cannot be opened
    
        comm set #hcomm, baud     = 9600        'baud
        comm set #hcomm, byte     = 8           ' 8 bits
        comm set #hcomm, parity   = %true       ' parity
        comm set #hcomm, paritytype   = 2         '0 = none, 1 = odd, 2 = even, 3 = mark, 4 = space
        comm set #hcomm, stop     = 2           ' 2 stop bit
        comm set #hcomm, txbuffer = 4096        ' 4k transmit buffer
        comm set #hcomm, rxbuffer = 4096        ' 4k receive buffer
    
    'add the following line to display buffer size:
    msgbox str$(comm(#hcomm, txbuffer)),,"read size of txbuffer"
    
        function = %true
    end function
    on my windows 2000 pc the messagebox shows a returned value of 0...
    does anybody have any suggestion?
    kind regards
    eddy


    ------------------
    [email protected]



    [this message has been edited by eddy van esch (edited june 12, 2001).]
    Eddy

  • #2
    Check the GetCommProperties API. The input and output buffer sizes may not be available from windows.

    Comment


    • #3
      The design of the 32-bit Windows communications APIs is very flexible, but
      noticeably demented. There are a number of little gotcha's, documented or
      otherwise. In particular, retrieving the number of characters in a comm tx
      buffer may return zero in all cases (the issue you've discovered). Another
      fine problem is, setting the size of a buffer may fail under different
      versions of Windows for various reasons: buffer too large, buffer too small,
      buffer not a power of two, buffer not a power of two minus one, or it's
      Wednesday and the moon is full.

      So, if possible, avoid setting the size of comm buffers, and don't expect a
      useful result from TXBUFFER. Or consider writing a 16-bit Windows program:
      the 16-bit comm APIs also had problems, but were less dramatically screwy.


      ------------------
      Tom Hanlin
      PowerBASIC Staff

      Comment


      • #4
        Thanks guys for your answer.
        It is clear to me now.. forget the txbuffer...
        Eddy


        ------------------
        [email protected]
        Eddy

        Comment

        Working...
        X