How to receive binary data in VB6?
Posted on 2005-05-04
I can receive ascii-formatted integers without a problem - I just want to avoid the overhead of formatting on my embedded PIC microprocessor & I the overhead of extracting the data back into integer form at the PC end.
I've set MScomm.InputMode to binary, and the Rthreshold to 10 bytes (0 because I have 5 channels worth of 16 bit data)
Every string received is minced: its either the null string"", or "?????"
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim InBufferCount As Integer
Dim Tmp As Integer
UploadData As String ' I've tried Byte and Variant. A byte array might work, but I don't know how to copy a String into a
' Byte array
InBufferCount = MSComm1.InBufferCount ' is 10 only if inputMode is set to Text
UploadData = MSComm1.Input ' copy Input in case it gets overwritten by more incoming data
For i = 0 To 4 ' 5 channels of 16 bit data - haven't included the stuff to combine the hi & lo bytes.
' this is the bit that doesn't work....
'Tmp = Val(Mid(UploadData, i, 1)) ' Tmp and Val give a type mismatch - can't seem to extract the data from the sub
' string from Mid(UploadData, i, 1))
Ch(i).Text = MidB(UploadData, (2 * i) + 1, 1) * 256 ' this works but only
' when UploadData contain Text rather than binary