Solved

API communications: SetCommEventMask

Posted on 1998-06-25
2
452 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
[X]
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
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

717 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