[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

API communications: SetCommEventMask

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
MHaverty
Asked:
MHaverty
1 Solution
 
peterwestCommented:
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
 
khaledcCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now