Announcement

Collapse
No announcement yet.

High speed text box

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

  • High speed text box

    Hi,

    I am trying to write a program, basically a terminal emulator
    (with 24x80 display) that receives data from the serial port,
    displays new data on the bottom line and scrolls old data up a
    line, and sends keyboard data out the serial port.

    VB has problems keeping up with the serial data (depending on
    what the other applications are doing) and also cannot keep
    up with the display requirements.

    I purchased PB/DLL and am trying to come up to speed with it.
    I have compiled the "serial.bas" sample program which is very
    close to what I need to do. The program puts the received data
    in a text box, but the text scrolls up so slow, it doesn't look
    like it could keep up with 300 baud, much less 38,400 baud or more.

    Can anyone help me with this, or guide me to information on
    creating a text window/box that can scroll data (24 x 80 format)
    at a very high speed. It doesn't have to have the ability of
    scrolling backwards with a scroll bar. The old data can just
    be ignored after it has scrolled off the screen. I just need a
    simple fixed column width font, just like an old "Adam" terminal.

    Thank you very much for your time,

    Russ


  • #2
    Windows has a lot to do when you fill this box.
    I recommend storing your incomming data in memory.
    Only 'paint' what is becomming visible using the ordinary wm_paint message.

    To invoke;
    Invalidaterect ByVal 0&, -1 invokes the wmpaint (triggered by incomming data)
    There's the place where you decide WHAT to paint on the screen.
    For example len of data -80x25



    ------------------

    Comment


    • #3
      Russ;

      If the text does not need to be edited in any way, then I would use a Static control (like the Label control in VB). In DDT it would be a Label control.

      Create a Label control and then set the font to "Terminal" using the %WM_SETFONT message . This will force the text to be fiexed width.

      Then use the API to find out the metrics (size) of the Terminal Font used for the control. Lets say the font is 8 x 16 pixels (an example). Use this info to resize your control to hold an 80 x 24 grid.

      Update the data in a string variable and then update the entire Label controls text with every new line.

      You can use code like this:

      Code:
      SUB UpdateTerminal(byval ND$)
      ' D$ hold the current text
      ' N& holds the number of lines
      ' ND$ holds the new data received (by Line)
      STATIC D$
      STATIC N&
      N&=N&+1
      if ND$=chr$(27) then N&=0   ' use esc char for Clear command
      Select case N&
         case 1
            D$=ND$
         case 2 to 24
            D$=D$+chr$(13)+chr$(10)+ND$
         case 25
            D$=mid$(D$, instr(D$, chr$(10)+1))
            D$=D$+chr$(13)+chr$(10)+ND$
         case 0
            D$=""   ' clear terminal
         case else
      end select
      
      CONTROL SET TEXT hDlg&, Id&, D$
      
      END SUB
      The Text (Edit) control has more overhead because it must track the Caret, which a Label control avoids.

      A Label control implimented as above will "appear" to scroll as you pass it data.



      ------------------
      Chris Boss
      Computer Workshop
      Developer of "EZGUI"
      http://cwsof.com
      http://twitter.com/EZGUIProGuy

      Comment


      • #4
        Perhaps it is the way you are updating it. You will do quite a bit of wheel reinventing to write scrollback & copy/paste into a label control. These are 2 critical terminal emulator features. Perhaps if you could paste the function that does all the output to the textbox.
        If you really need high high speed output, it might be better to consider pb/cc and do everything with the console.


        ------------------

        Comment


        • #5
          I had the same problem.
          Forget the edit control and write directly to the window using
          TextOut API.
          The following is the function I use. Works just like:
          locate n,n:color,nrint n$ does in Dos.

          'Declare hFont as global & PrintStr as asciiz * 80 & Ink AS LONG
          FUNCTION SPRINT(BYVAL hDlg AS LONG,BYVAL Row AS LONG,BYVAL Col AS LONG,BYVAL Ink AS LONG,PrintStr AS ASCIIZ) AS LONG

          LOCAL hDC AS LONG
          LOCAL Trect AS Rect
          LOCAL DiUnit AS DWORD
          LOCAL HZDBU AS LONG
          LOCAL VTDBU AS LONG
          LOCAL ch AS LONG
          LOCAL cv AS LONG
          LOCAL hBkCol AS LONG
          LOCAL STRINGPTR AS ASCIIZ PTR
          LOCAL STRINGLEN AS LONG

          GetDC hDlG TO hDC
          SelectObject hDc,hFont
          GetClientRect hDlg,Trect
          GetDialogBaseUnits TO DiUnit
          HZDBU = LOWRD(DiUnit)
          VTDBU = HIWRD(DiUnit)
          ch = Col * HZDBU
          cv = Row * VTDBU
          SetBkMode hDC, %OPAQUE
          SetTextColor hDC,Ink
          APGREY& = RGB (190,190,190)
          SETBKCOLOR hDC,APGREY&
          STRINGPTR = VARPTR(PrintStr)
          STRINGLEN = LEN(PrintStr)
          TextOut hDC,ch,cv,@STRINGPTR,STRINGLEN
          ReleaseDC hDlg,hDC
          FUNCTION = %TRUE
          END FUNCTION
          '-----------------
          you will need to keep an image of what you write to the screen.
          i.e dim buffer(24) as global asciiz * 82
          the buffer contents can be used to repaint the screen.
          Ink is any predefined color in the winapi.inc

          ------------------

          Comment


          • #6
            If you don't wish to use what is effectively an owner-drawn control, then it may be easier to tell the edit control or label control not to display new text immediately when you change the content.

            Windows provides a method to 'postpone' controls updating themselves - the %WM_SETREDRAW message. Send this message with a false (0) value before sending a 'stream' of new data to the control, and then send a true (non-zero) value to tell the control it can update itself. See WIN32.HLP for more information on this message.

            In this way, you could add one character at a time to the edit control, and only let the control update it's appearance when you have a complete line of 'data'.

            Food for thought anyway.

            ------------------
            Lance
            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            Lance
            mailto:[email protected]

            Comment

            Working...
            X