Microsoft Developer Network > Forums Home > Microsoft ISV Community Center Forums > Visual Basic for Applications (VBA) > Accessing continuous data from serial port in event triggered (asynchronous) mode
Ask a questionAsk a question
 

General DiscussionAccessing continuous data from serial port in event triggered (asynchronous) mode

  • Monday, November 02, 2009 6:32 AMCharlieee Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I am trying to write a VBA (vb 6.3) macro that:
    1. Reads Text data from first device connected to Serial port, and
    2. On receiving the data, calls second device through the TCP-IP port, which sends a string of data at that instant.
    3. This data is put into an Excel 2003 spread sheet.

    At present i am limiting my task to receiving the data from the first device through the serial port.

    The data from the first device (serial port) is coming continuously at an interval of 100ms, so i need to read the serial port in event driven mode. The reading should happen automatically (without pressing any button) and the main thread should be interrupted when ever the data is received from the serial port.

    My basic understanding of system serial communication is:

    1. Serial port is configured
    2. Serial port interrupt is enabled
    3. when serial data comes, a serial interrupt is triggered
    4. On the trigger the processor goes to Interrupt Vector Table
    5. and from there to the interrupt service routine location

    How does these things happen in VB?

    At present i got hold of a sample program which is using API calls

    http://www.stumbleupon.com/to/2EjQH1/dev.emcelettronica.com/serial-port-communication-excel-vba/t:4aee75e455dd1;src:reviews

    1. I guess the interrupt (event) is enabled using SetCommMask()
    2. I guess i have to use the overlapped I/O operation for asynchronous (event triggered mode and not polling of the serial port).
    3. I am using CreateFile() to create the serial port device handle.
    4. I suppose i have to use waitcommevent function in overlapped mode(any other method). I guess the function comes out to the main routine after been timed out as set by commtimeout. In asynchronous operation, the system itself then sets the event handle in overlapped structure when a data is received in the serial port.

    5. My doubt is how to associate this event with a subroutine or in case i am wrong, what is the event triggered and how to associate the event with a subroutine (handle).

    2. How to run the main program in a loop until a close button is pressed by the user in the excell sheet.

    If anyone can suggest other ways or methods for the particular task, he's welcome