locked
Comm port communications RRS feed

  • Question

  • I'm using serial communications to receive inputs from 6 barcode readers to one comm port.  I have an oncomm event that takes just under 2 seconds to complete.  If i receive another oncomm event within that time, it starts another oncomm event on top of the first one.  I have had some problems with this code and think it might be related to this.  My first question is is this second oncomm event interupting the first event and stopping it from completing and if so, is there a way around this.  My second question involves a possible solution, which is after the oncomm event starts and i read the information from the port, can i then close the port until the 2 second code has finished and then open the port back up, thus avoiding the possible conflict of 2 oncomms running at the same time?  Will opening and closing this port all the time cause problems in the long run?  Thanks.

     

    PS.  I am far from a .net guru and have written this code in the most basic way, ie everything is sequential.  I don't know a thing about threading or parallel processing or what ever it's called.  I'm hoping to find a solution to this that won't involve a complete rewrite of this code in a style that is currently beyond my knowledge.  Time is a big factor here.  Thanks again.

    Monday, January 29, 2007 7:00 PM

Answers

  • If it doesn't matter whether the second event gets handled or not, then I'd use a simple boolean flag at the start of the event and resetting it at the end. (To be sure, make a local copy of the passedparameters)

    Event Sub(passedparameters)
    if zReadyForNewEvent = false then Exit Sub

    dim zLocalCopy as Object = passedparameterX

    ' do stuff to handle the event here

    zReadyForNewEvent = True
    End Sub



    I'm not sure it's proper coding, but it'll work.
    Monday, January 29, 2007 8:32 PM