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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HEX Help 1

Status
Not open for further replies.

WildGun

Technical User
Jan 13, 2005
15
US
Hi

I receive a HEX string using the MSComm RS-232 port interface, it is received in the following way "01 D0 05 07" most of the binary bit are useful and I understand how to break it down. The HEX string is retransmitted every 500ms with new data but always in the same format.
"01 D0 05 07"
"02 D2 05 05"
"03 A0 05 03"
I only need to deal with one string at a time so out with the old and in with the new. My question is how should I configure MSComm to collect the HEX and is there an easy way to convert it to Binary?

Thanks

Randy
 
Look in VBHelp for the MSComm control properties InputLen and InputMode.

To convert a Long to Binary I use a std function
Code:
'---------------------------------------------------------------------------------------
' Procedure : fncBinary
' DateTime  : 15/06/2001 08:33
' (C)       : John M
' Purpose   : Generates Binary string
' Takes     : Long to convert
' Returns   : Binary string
'---------------------------------------------------------------------------------------
'
Public Function fncBinary(inpLong As Long) As String
Dim Remainder As Long
Remainder = inpLong
Do While Remainder > 0
fncBinary = Remainder Mod 2 & fncBinary
Remainder = Remainder \ 2
Loop
End Function

To get the numeric value of a Hex string just evaluate the string with &H in front. If myHstring contains FF then

myValue = "&H" & myHstring

will give 255

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

For tsunami relief donations

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top