CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2001
    Location
    TX,USA
    Posts
    5

    MSComm, Timer and OnComm Event problem

    Hi Codegurus,

    I'm communicating through a serial port using mscomm control. I tried both the timer and the oncomm event for receiving the messages from the serial port.

    The problem is:
    1. I have a button in my form when i press the button it will send a message for eg:"A" to the serial port and to the corresponding device. The device will send me back the answer as "B".

    2. The above step is working fine initially. But Some Times if i press the button, I'm getting the old pressed message only. I mean if recd a message 10 secs back, the same message is coming again instead of original expected message.


    I dunno where the problem is.

    Any Help in this will be greatly appreciated.

    Thanks!!
    moydheen




  2. #2
    Join Date
    Mar 2001
    Posts
    7

    Re: MSComm, Timer and OnComm Event problem

    Use in mscomm_oncom()
    if mscomm.comevent=comRecieve then str = str & mscomm.input}}do your stuff clear the str you can use mscomm.inBufferCount =0 to clear the buffer. you can also do it like mscom.output = "hello": then a loop with str = str & mscomm.input in it break when you get enough chrs



  3. #3
    Join Date
    Jun 1999
    Location
    Switzerland
    Posts
    398

    Re: MSComm, Timer and OnComm Event problem

    There may be several reasons for your problem.

    - do you send what you intend to send?
    - does your device reply what you expect to get?
    - do you read all data from serial input buffer (InputLen property = 0)
    - try to clear serial input buffer and any related string buffer before sending

    Perhaps you can post some code fragment how you send/receive?

    Leica Geosystems - when it has to be right

  4. #4
    Join Date
    Mar 2001
    Location
    TX,USA
    Posts
    5

    Re: MSComm, Timer and OnComm Event problem

    Thanks for ur reply!!!

    "Try to clear serial input buffer and any related string buffer before sending"

    Is there any way to clear the serial input buffer, becoz I checked my code line by line, where actualy I'm getting problem is at the line

    Private Sub tmrWaitInput_Timer()
    strReceived = mscomm1.Input 'Here I'm getting problem
    End sub

    In the above code when i get into that line, instead of showing the newly received buffer content, its showing the old one, after one more iteration sometimes fewmore iterations its showing the actual newly received content.


    Thanks!!!
    shiek




  5. #5
    Join Date
    Jun 1999
    Location
    Switzerland
    Posts
    398

    Re: MSComm, Timer and OnComm Event problem

    You can clear the serial input buffer by InBufferCount property.

    MSDN
    InBufferCount refers to the number of characters that have been received by the modem and are waiting in the receive buffer for you to take them out. You can clear the receive buffer by setting the InBufferCount property to 0.

    But normaly, and if InputLen property is set to 0, you should get all data by Input property. So the serial buffer should be clear after reading.


    Leica Geosystems - when it has to be right

  6. #6
    Join Date
    Jul 2001
    Location
    England
    Posts
    20

    Re: MSComm, Timer and OnComm Event problem

    Wonder if you've come across my problem in your MSComm work :-

    I send a string of say 50 characters to my 'OnComm' event handler . The event triggers for every 8 characters i.e I get 7 receive events. (6*8 + 1*2) If I put a breakpoint in the code just before reading the input then I get the whole string read for a single receive event (which is what I want) Some sort of timing problem ?? I have 'InputLen = 0' and 'RThreshold = 1'. Any ideas ??

    Thanks in advance,
    Dave.


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

Featured