High speed Serial Port output

Posted on 2004-11-19
Last Modified: 2010-05-02
 I am writing an application in which i need to output 3 bytes of data to the serial port 20 times a second. I tried to use the MSComm control but it seems to delay the output of the data (presumably because of buffering or something) and can not cope with the speed I require, so i get 'Out of stack space' errors. I am running my port and serial device at 9600baud so I would have thought this would have been fast enough as i should only require 480 baud (3 bytes * 8 bits per byte * 20 times a second = 480.) Is there any way to output the data faster without the delay/buffering using the MSComm control or any other alternative ways of serial port output? Sample code would be great too :)
Question by:pyromatt
    LVL 76

    Expert Comment

    There should be no problem running at that speed with the MSComm component

    'Out of stack space' is usually caused by a recursive call gone out of control. I can't understand the connection with slow output.

    Perhaps you should post your code

    Author Comment

    Public Function SerOut(PortData As String)
      DoEvents 'Prevent 'Port already open' errors
     Loop Until frmMain.SerPort.PortOpen = False
     frmMain.SerPort.PortOpen = True
     frmMain.SerPort.Output = PortData
     frmMain.SerPort.PortOpen = False
    End Function

    PortData always contains 3 characters, and this fuction is used 20 times a second. The serial port however, only manages to output around 2 a second and so after a few seconds i get a stack space error.
    LVL 76

    Expert Comment

    Why don't you just leave the port open?

    Author Comment

    I thought you had to close the port to send the data? I always thought 'output' just buffers it and it isnt sent until you close it.

    Author Comment

    Doh! Ive found the problem. I forgot to disable DTR and hence having to close the port everytime i need to send data (and hence the slowness)!

    Accepted Solution

    Closed, 200 points refunded.

    Community Support Moderator
    Experts Exchange

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now