Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

In my battle with VB I have no got solid reliable comms with the Unit Under Test.
I can get it to reply to a rich text box, how ever I want to get the complete reply
If I monitor it in the below function
VB
Private Sub port_DataReceived_ATE(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)

        TmrNoDataAtPortATE.Enabled = False
        InputData = ATEComPort.ReadExisting
        Reply_Status = REPLY_ATE.YES_REPLY

        If InputData <> [String].Empty Then
            Me.BeginInvoke(New SetTextCallbackATE(AddressOf SetTextATE), New Object() {InputData})
            'MsgBox("here!")
        Else
            MsgBox("null")
        End If
        TmrNoDataAtPortATE.Enabled = False
        If (Reply_Status = REPLY_ATE.TIMEOUT_REPLY) Then
            Data_Back = "TIMEOUT"
        ElseIf (Reply_Status = REPLY_ATE.YES_REPLY) Then
            TmrNoDataAtPortATE.Enabled = False

        End If
        'Me.Invoke(Me.rtbIncomingATE.Text)

    End Sub

and change invoked function is
VB
Private Sub SetTextATE(ByVal textATE As String)

      ' If (textATE = Chr(13)) Then MsgBox(rtbIncomingATE.Text) works once
      Me.rtbIncomingATE.Text += textATE

      'in here use an if or switch (Select) to sort out what goes where

  End Sub

the if() statement to catch the Cr that the unit has as the end only seems to work once,
the board I am talking to does produce a carriage return after each reply. What I was hoping to do was to monitor textATE for a Chr(13) when one was encountered that means the reply is terminated so I could go and process it. The worst thing is it appears to work once but only once. Is there a correct method of getting the contents of the rtb on the main GUI thread?

Glenn, I think it might be something to do with BeginInvoke switching to Invoke... and testing!
Posted
Updated 20-Mar-14 4:22am
v2
Comments
Sergey Alexandrovich Kryukov 20-Mar-14 10:52am    
If you battle with language, you won't go far. :-) You need to collaborate.
You see, you need to get more familiar with threads and thread synchronization first, pretty much from the very beginning. Right now, you are mixing together different concept. For example, Invoke is not thread synchronization, this is delegation of some action to the UI thread, specifically, from the calling thread...

And why BeginInvoke, not Invoke...

—SA
glennPattonWork3 20-Mar-14 11:00am    
The worst bit is I can send and receive reply, the worst bit I can see the reply in the text box I just can't get at it!

Instead of
Me.BeginInvoke(New SetTextCallbackATE(AddressOf SetTextATE), New Object() {InputData})


Why don't you just call SetTextATE as follows:
Call SetTextATE(InputData)
 
Share this answer
 
Comments
glennPattonWork3 20-Mar-14 11:51am    
Yup, tried that. That's where the cross threading came from in the first place! I think the problem is the rich text box the data is in is on a different thread to the GUI thread and it gets beyond me!
I have hacked a solution together to allow me to proceed below:

VB
Private Sub btnRE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRE.Click

       rtbIncomingATE.Text = ""
       TmrNoDataAtPortATE.Enabled = True
       Reply_Status = REPLY_ATE.NO_REPLY
       Write_HyperTerm_Style("#RE" & Chr(13)) 'sends RE command
       While (rtbIncomingATE.Text.Length < 5)
           Application.DoEvents()
       End While
       Call btnBodge_Click(sender, e)
       rtbIncomingATE.Text = ""


   End Sub


And I had a separate click routine to get the data from it:
VB
Public Sub btnBodge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBodge.Click
    Dim StringReply, StringReplyA As String

    StringReply = rtbIncomingATE.Text
    ' MsgBox(StringReply)
    StringReplyA = StringReply.Substring(0, 5)
    txtREresponce.Text = StringReplyA
    'MsgBox(StringReplyA)
    rtbIncomingATE.Clear()

End Sub

It's nasty but it gets me over a hump, at the moment that is the main thing!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900