?
Solved

Serial comms buffer problem

Posted on 1998-12-03
3
Medium Priority
?
173 Views
Last Modified: 2010-05-03
In VB5 when receiving 256 bytes of binary data through the serial port, on tranferring from com1input to a string, the data is truncated to less than 256 bytes, and the MSB is lost. This is in binary tranfer mode. Why is this, and how can I just receive 256 bytes of raw data.
0
Comment
Question by:JulianThomas
[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
  • 2
3 Comments
 
LVL 9

Expert Comment

by:Dalin
ID: 1448035
JulianThomas,
Could you post the code you have?
0
 

Author Comment

by:JulianThomas
ID: 1448036
****************************************************************  
    Dim BUFFER As Variant
    Dim INSTRING As String

Private Sub Command1_Click()
End
End Sub

Private Sub Command2_Click()
MSComm1.Output = "S" + Chr$(&H0E)
End Sub

Private Sub Command3_Click()
Print Len(INSTRING)
Print INSTRING
BV = Asc(Mid$(INSTRING, 1, 1))
End Sub

Private Sub Form_Load()

    MSComm1.InBufferSize = 1024
    MSComm1.InputMode = comInputModeText
    MSComm1.CommPort = 2
    MSComm1.Settings = "19200,N,8,1"
    MSComm1.InputLen = 0
    MSComm1.PortOpen = True
 
End Sub

Private Sub MSComm1_OnComm()
    INSTRING = INSTRING + MSComm1.Input
End Sub
****************************************************************

      When I send "S" + chr$(&H0E) the target unit sends back 257
bytes. I then wait until mscomm1 input buffer has 257 bytes in it.
If I use cominputmodetext then when i use INSTRING=mscomm1.input
the length of INSTRING varies even though the mscomm1 input buffer
had 257 bytes in it. If i use cominputmodebinary then i get half
the number of bytes in INSTRING as there were in the input buffer
and those bytes all have the top bit set to zero.

0
 
LVL 9

Accepted Solution

by:
Dalin earned 200 total points
ID: 1448037
Julian,
1. Make sure the device you receive data from is send you binary or Text, and then select the mode accordingly.
2. If the device is send you binary data, you need to put them in a byte array, and them convert back to text.  Instring is a string so that would not work.
For example, if you receive 2 bytes: the first bytes has a value of 1  and the 2nd byte has 9, you will get 19 in your current code, where as the real value depending on the way it was encoded, the two byte should total 264, now you may find a different ASC char for that. Image the first byte is 1 and the 2nd is 107, your cur code give you 2107. That is why your length vary.

Try:
Dim myBuffer as Variant
Dim myData() as Byte

' Store binary data in myBuffer, since it is variant.
myBuffer = MSComm1.Input

' Assign to byte array for processing
myData = Buffer

' Now you need to convert myData to ASC.

Let me know if I can be further help.
Regards
Dalin





 
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

650 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