cdelaney,<br>
Change the comInputMode to the 'binary' (in the Properties listbox, it's called something else but you'll get the picture). Read into a Byte. What do you want to display in the textbox? The visual representation of the byte value, such as you'd see in a dump from dos's debug or Norton's disk editor? Or just the ascii value of the byte?<br>
--Jim
I have already changed the value in MSCOMM to input binary but I want to be able to show the actual contents of the byte for example if the byte that came in was 01010101 I would like to show it as this or if not at least be able to convert it to hex so I can easily work with it.
cdelany,<br>
Here is an example--The oncomm event, and a function to parse/display the bytes as you want-(-admittedly theres little error control, but you can do that as you like)<br>
Private Sub MSComm2_OnComm()<br>
If Me!MSComm2.CommEvent = 2 Then<br>
Dim vr As Variant, bt As Byte<br>
vr = Me!MSComm2.Input<br>
On Error Resume Next<br>
For i = 0 To 1024 'or whatever input buff is<br>
Debug.Print vr(i)<br>
If Err = 9 Then Exit For 'subscript out of range--not sure how to get ubound of vr<br>
bt = vr(i)<br>
Me!Text2.Text = Me!Text2.Text & BitField(bt)<br>
Next i<br>
End If<br>
End Sub<br>
<br>
Function BitField(bt As Byte) As String<br>
Dim j As Integer, i As Integer, strBitField As String<br>
j = 1<br>
strBitField = "00000000" 'init<br>
For i = 1 To 8<br>
Mid$(strBitField, i, 1) = IIf(bt And j, "1", "0"<br>
j = j * 2 'Increment AND mask<br>
Next i<br>
BitField = strBitField<br>
End Function<br>
<br>
<br>
I don't know how much experience you have with comm, I've got moderate, so as a caveat, you need to keep an eye on the Recieve threshold and input len, etc. I typically set both to 1 (if text mode) so my oncomm is always guaranteed to have 1 char, in binary mode, I'm not sure what's the best<br>
--Jim
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.