Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Comm Control

Status
Not open for further replies.

cdelaney

Programmer
Mar 2, 2000
8
0
0
CA
How to read in a binary value from a microcontroller and put it in a text box. I seem to only be able to put it in the text box as a ascii value.<br>

<br>

<br>

Any help is appreciated<br>

<br>


 
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 = &quot;00000000&quot; 'init<br>
For i = 1 To 8<br>
Mid$(strBitField, i, 1) = IIf(bt And j, &quot;1&quot;, &quot;0&quot;)<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
 
cdelany,<br>
a big Homer D'OH!--I have the bitfield reversed above, just set the for next to<br>
For i = 8 to 1 step -1<br>
<br>
...sorry,<br>
--Jim
 
I noticed that when I ran the code. Changed it and everthing works fine now. Not a problem.<br>
<br>
<br>
Thanks<br>
Curtis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top