?
Solved

Serial comms buffer problem

Posted on 1998-12-03
3
Medium Priority
?
172 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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
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