Results 1 to 5 of 5

Thread: [RESOLVED] Using ONCOMM Event

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    63

    Resolved [RESOLVED] Using ONCOMM Event

    I have searched the forum and found several several topics for using ONCOMM. I want to detect the arrival of data at the com port without polling nor do I want to wait for the data. Each received message will end with <ETX> &h03/chr$(3). Is this too ambitious?

  2. #2

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    63

    Re: Using ONCOMM Event

    Figured it out on my own. Thanks

  3. #3
    Lively Member
    Join Date
    Mar 2010
    Posts
    78

    Re: Using ONCOMM Event

    So, how dd you do it?

    I am using similar end string - chr$(3) to end my incomming data.
    And because I am a beginner in programming, I just want to see if I do it right.

    Thanks.

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    63

    Re: Using ONCOMM Event

    I set RThreshold = 1 and used the following code (some was taken from this forum):

    Private Sub MSComm1_OnComm()
    Dim strInput As String
    With MSComm1
    'test for incoming event
    Select Case .CommEvent
    Case comEvReceive
    'display incoming event data to displaying textbox
    strInput = .Input


    Do Until Right$(strInput, 1) = Chr$(3)
    strInput = strInput + .Input
    Loop

    SerialInASCII.Text = strInput
    End Select
    End With 'MSComm1
    End Sub


    'by setting RThreshold = 1, each byte is compared and added to the string strInput until chr$(3) is detected. This code may be cluggy to some but it works. By the way, I am novoice programmer myself and ask questions and search this forum reguarly. There are good people on this forum that want to help

  5. #5
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Using ONCOMM Event

    You would be wise to not use "+" to concatenate strings. The "&" char is the proper way to do it.
    Code:
    strInput = strInput & .Input
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width