Solved

API communications: SetCommEventMask

Posted on 1998-06-25
2
433 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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

762 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

6 Experts available now in Live!

Get 1:1 Help Now