Solved

Serial comms buffer problem

Posted on 1998-12-03
3
165 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
  • 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 100 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now