Serial Communication (RS232) append issue

Currently, I have connected two computers via serial cables and a null modemn adaptor.  I have set the two computers up to simulate a VB application that will need to communicate with a plc computer that will reply with a hex string, upon receiving an ASCII "S".  

Private Sub scTimer_Timer()
    On Error GoTo ERRH
    If msComm.PortOpen Then
        msComm.Output = "S"
    Else
        msComm.PortOpen = True
    End If
Exit Sub
ERRH:
    MsgBox "ERROR ... TIMER WILL BE DISABLED." & Chr(13) & Err.Number & Chr(13) & Err.Description
    scTimer.Enabled = False
End Sub

Private Sub msComm_OnComm()
    If msComm.CommEvent = comEvReceive Then
            Text1.Text = Text1.Text + StrConv(msComm.Input, vbUnicode)
   
        Text2.Text = ""
        For y = 1 To Len(Text1.Text)
            Text2.Text = Text2.Text & Chr(Val("&h" & (Mid(Text1.Text, y + 1, 2))))
            y = y + 2
        Next y
       
    End If
End Sub

Basically, what happens is the hexadecimal string is received into text1.text and is converted into ASCII in Text2.  The event is updated every three seconds, so the timer is set to resend the "S" every 3 seconds.  The first time, everything works exactly as it should, however when it fires the second "S", the new data is just appended on to the previously received data in Text1.  Everythin I try messes up the data I receive in Text1.  Please let me know your suggestions!  
daeggmanAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
JH0401Connect With a Mentor Commented:
Did you figure this out?  Once you've used the
data in Text1 & converted it into ASCII in Text2,
you no longer need the data in Text1???    

Did you find a good place to clear the data in
Text1???

    If msComm.PortOpen Then
        Text1.Text = ""
        msComm.Output = "S"
    Else
        msComm.PortOpen = True
    End If
0
 
GivenRandyCommented:
Can you describe it more? I am confused. By the way, do you want "y = y + 2" to be "y = y + 1"? The ForLoop will already increment y by 1 each time.
0
 
marconovaroCommented:

> the new data is just appended on to the previously received data in Text1

Isn't it simply because you are using:

Text1.Text = Text1.Text + StrConv(msComm.Input, vbUnicode)

i.e. _you_ are appending data to Text1 ? :-)
M
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
deepeeCommented:
I think with
Text1.Text = Text1.Text + StrConv(msComm.Input, vbUnicode)

this statment you r trying to read data send in previous 3 seconds. If it is so then just clear Text1.text before next "S" is sent.

Hope this will help
If no please ask in some different way, so that I can understand it better.

0
 
GivenRandyCommented:
No, because he is constantly adding to Text1 and then does the conversion of the whole Text1 to Text2 after resetting Text2 to null.

Of course, this could be sped up in two stages: 1) only convert the NEW stuff and append to Text2; and 2) set the text point to append instead of merely appending. These would speed things up, but not solve the original problem (which we are still trying to do).
0
 
daeggmanAuthor Commented:
Thank you very much for the help, I placed the Text1.Text = "" right before I sent the "S" and everything now works perfectly.  Thanks again.
0
All Courses

From novice to tech pro — start learning today.