?
Solved

Serial Communication (RS232) append issue

Posted on 2003-03-11
6
Medium Priority
?
202 Views
Last Modified: 2008-03-10
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!  
0
Comment
Question by:daeggman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 9

Expert Comment

by:GivenRandy
ID: 8116082
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
 
LVL 6

Expert Comment

by:marconovaro
ID: 8117944

> 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
 

Expert Comment

by:deepee
ID: 8118077
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:GivenRandy
ID: 8119581
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
 
LVL 1

Accepted Solution

by:
JH0401 earned 320 total points
ID: 8122395
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
 

Author Comment

by:daeggman
ID: 8128061
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

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question