Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

API communications: SetCommEventMask

Posted on 1998-06-25
2
445 Views
Last Modified: 2008-02-01
I need my VB program to generate an event when a specific character is received in a comm port.  I've tried using MSComm control with InputLen=1 to analyze each character, but the data is received too fast for this method.  I've heard that by using the API I can generate an event when a specific character is received (ie. carriage return or linefeed). I'm not extremely familar with the API; can anyone provide a detailed example. I would like to be able to leave the received string in the buffer until a carriage return and linefeed are received, then read the string from the buffer.
0
Comment
Question by:MHaverty
2 Comments
 
LVL 2

Expert Comment

by:peterwest
ID: 1464328
Hi there,

You may want to check out the Knowledge Base Article Q75856.  This details how to use to Windows API to control the Comm port and also allows you to download a file which gives you the constants and API declarations.

If you need any further help then give me a shout!!

Pete

0
 
LVL 1

Accepted Solution

by:
khaledc earned 170 total points
ID: 1464329
Try using the OnComm Event in MSComm, help in VB gave the following description:

The OnComm event is generated whenever the value of the CommEvent property changes, indicating that either a communication event or an error occurred.

An example would be:

Private Sub MSComm_OnComm ()
      Select Case MSComm1.CommEvent
      ' Handle each event or error by placing
      ' code below each case statement

      ' Errors
            Case comEventBreak      ' A Break was received.
            Case comEventCDTO      ' CD (RLSD) Timeout.
            Case comEventCTSTO      ' CTS Timeout.
            Case comEventDSRTO      ' DSR Timeout.
            Case comEventFrame      ' Framing Error
            Case comEventOverrun      ' Data Lost.
            Case comEventRxOver      ' Receive buffer overflow.
            Case comEventRxParity      ' Parity Error.

Case comEventTxFull      ' Transmit buffer full.
            Case comEventDCB      ' Unexpected error retrieving DCB]

      ' Events
            Case comEvCD      ' Change in the CD line.
            Case comEvCTS      ' Change in the CTS line.
            Case comEvDSR      ' Change in the DSR line.
            Case comEvRing      ' Change in the Ring Indicator.
            Case comEvReceive      ' Received RThreshold # of chars
***************************      'Put your Code Here                  
            Case comEvSend      ' There are SThreshold number of ' characters in the transmit  buffer.
                                          
                                          

Case comEvEof      ' An EOF charater was found in                                                 ' the input stream
      End Select
End Sub


What you are after is to check when you receive data, therefore you are after the case when MSComm1.CommEvent=comEvReceive

Hope this may help
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

860 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