Results 1 to 40 of 102

Thread: [RESOLVED] SerialPort VB.NET : Write/buffer/timing and Data Received Event (VS2010 and VS2008)

Threaded View

  1. #10

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    144

    Re: SerialPort VB.NET : Write/buffer/timing and Data Received Event (VS2010 and VS200

    Hi again,

    I've been through some work and I think I've correctly analyzed (maybe not 100% understood) your code. I've also sequenced my needs. For both points, I have global questions.

    After reading your code several time, I think I see this:

    Form.Shown
    LOAD SETTINGS
    OPEN COM PORT
    CALLS THE BCKGND WORKER: GoTo « DoWork ».

    BackgroundWorker.DoWork
    CHECKS IF A “CR” CHAR IS IN THE RETURN STRING
    IF NO / IF YES: FIRST RUN = NO -> DataAvailable.WaitOne()
    WaitOne here means the BCKGND WORKER will stay like this as long as there is no “SET”, i.e. as long as we don’t click on the “SEND” button which contains the “SET” for the WaitHandle. So, the BACKGND WORKER runs “empty” indefinitely if we don’t click on “SEND”.

    Send.Click
    CLICK ON SEND:
    SerialPort.Write() -> TRIGGERS THE DATA RECEIVED.

    DataReceived Event
    READ THE BYTES IN THE BUFFER
    PUTS THE BYTES IN AN ARRAY AND POPULATES A LIST
    SETS THE WAITHANDLE INTO THE SIGNALED STATE: DataAvailable.Set()
    DataAvailable.Set() -> TRIGGERS ACTION ON THE BCKGND WORKER as it releases the handle from his HALTED STATE. The “Do…Loop” in the BCKGND WORKER resumes.

    Back to the BCKGND WORKER:
    The “DO…LOOP” loop: orders the received bytes by checking if the CR is there in the list and by parsing the string at its found “EndOfLine” index.
    IF YES (i.e. there is enough data in the buffer as it contains a “CR” byte-code): CONVERTS THE BYTES INTO A STRING OF CHAR.
    REPORTS THE PROGRESS TO THE BCKGND WORKER
    ReportProgress() -> TRIGGERS PROGRESSCHANGED.

    BackgroundWorker.ProgressChanged
    HAS THE FINAL STRING in INPUT PARAMETER (e.UserState)
    APPENDS THE STRING TO THE RICHTEXTBOX (DISPLAY).

    QUESTION:
    1. Is this correct or close to ?


    As the other point is concerned, it's the analysis of the sequence needs in this program:

    SEND COMMAND is the first action (step1).
    RETURN & READ STRING (step2) is triggered by step1 (BackGroundWorker + Data Received).
    CHECK RETURN STRING (step3) waits on a WaitHandle that step2 SIGNALS.
    ACQUIRE IMAGE (step4) waits on a WaitHandle that step3 SIGNALS.
    For the next position:
    SEND COMMAND waits on a WaitHandle that step4 SIGNALS. ETC. (49 times)

    The difference in these tasks is that SEND COMMAND needs to run the first time without waiting.

    QUESTIONS:

    2. I guess step1 should be started in the SIGNALED STATE (=AutoResetEvent (True)) if I want to have a loop around SerialPort.Write() ?

    3. Are the Waithandles the best way to have all these other tasks working separately and at the right time, the way you did with the first 2 (to return the string in the TxtBox) ?


    Thank you for your input !
    Last edited by LiamC; Sep 30th, 2013 at 07:44 AM.

Tags for this Thread

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