PC Review


Reply
Thread Tools Rate Thread

Converting a HEX string

 
 
Andrew P.
Guest
Posts: n/a
 
      27th May 2010
Hello All

I'm using "modCOMM - Written by: David M. Hitchner" to send data out of the
serial port. I need to send HEX strings (eg 0E0E00000505000C20450164A5A5 ) to
external devices. Each part of the string is 2 HEX characters. If I send a
HEX string directly to it, I get incorrect data at the other end.

By using 2 HEX programs and a null cable, I can pass the strings correctly
to the equipment, and also monitor what Excel is sending out of the serial
port.

If I send this -> I get this on the HEX comms program

0E0E00000505000C20450164A5A5 ->
3045304530303030303530353030304332303435303136344135413500

0 -> 30
1 -> 31
A -> 41
a ->61
0E -> 3045
Chr(1) & Chr(255) -> 01FF

So, I can see that there is a way to get the correct data out, but I don't
want to have to encode each and every pair of HEX digits into a "chr()".
Whats the intelligent way of getting a string?

Thanks a lot!!
Andrew
 
Reply With Quote
 
 
 
 
Andrew P.
Guest
Posts: n/a
 
      28th May 2010
GOT IT!!!!!

Solution:
Work on the HEX string 2 digits at a time, and take the result of Chr(), not
the string containing "Chr(xx)". And its even working in the real world, not
just a HEX editor. Happy days!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For i = 1 To Len(hexstring) Step 2
Dim temp As String
temp = WorksheetFunction.Hex2Dec(Mid(hexstring, i, 2))
outputstring = outputstring & Chr(temp)
Next i
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"Andrew P." wrote:

> Hello All
>
> I'm using "modCOMM - Written by: David M. Hitchner" to send data out of the
> serial port. I need to send HEX strings (eg 0E0E00000505000C20450164A5A5 ) to
> external devices. Each part of the string is 2 HEX characters. If I send a
> HEX string directly to it, I get incorrect data at the other end.
>
> By using 2 HEX programs and a null cable, I can pass the strings correctly
> to the equipment, and also monitor what Excel is sending out of the serial
> port.
>
> If I send this -> I get this on the HEX comms program
>
> 0E0E00000505000C20450164A5A5 ->
> 3045304530303030303530353030304332303435303136344135413500
>
> 0 -> 30
> 1 -> 31
> A -> 41
> a ->61
> 0E -> 3045
> Chr(1) & Chr(255) -> 01FF
>
> So, I can see that there is a way to get the correct data out, but I don't
> want to have to encode each and every pair of HEX digits into a "chr()".
> Whats the intelligent way of getting a string?
>
> Thanks a lot!!
> Andrew

 
Reply With Quote
 
GS
Guest
Posts: n/a
 
      29th May 2010
Andrew P. presented the following explanation :
> GOT IT!!!!!
>
> Solution:
> Work on the HEX string 2 digits at a time, and take the result of Chr(), not
> the string containing "Chr(xx)". And its even working in the real world, not
> just a HEX editor. Happy days!
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> For i = 1 To Len(hexstring) Step 2
> Dim temp As String
> temp = WorksheetFunction.Hex2Dec(Mid(hexstring, i, 2))
> outputstring = outputstring & Chr(temp)
> Next i
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> "Andrew P." wrote:
>
>> Hello All
>>
>> I'm using "modCOMM - Written by: David M. Hitchner" to send data out of the
>> serial port. I need to send HEX strings (eg 0E0E00000505000C20450164A5A5 )
>> to external devices. Each part of the string is 2 HEX characters. If I send
>> a HEX string directly to it, I get incorrect data at the other end.
>>
>> By using 2 HEX programs and a null cable, I can pass the strings correctly
>> to the equipment, and also monitor what Excel is sending out of the serial
>> port.
>>
>> If I send this -> I get this on the HEX comms program
>>
>> 0E0E00000505000C20450164A5A5 ->
>> 3045304530303030303530353030304332303435303136344135413500
>>
>> 0 -> 30
>> 1 -> 31
>> A -> 41
>> a ->61
>> 0E -> 3045
>> Chr(1) & Chr(255) -> 01FF
>>
>> So, I can see that there is a way to get the correct data out, but I don't
>> want to have to encode each and every pair of HEX digits into a "chr()".
>> Whats the intelligent way of getting a string?
>>
>> Thanks a lot!!
>> Andrew


Curious...
I don't see how the code you posted here returns the result you say it
gave you. It appears that your Chr() function returns a different set
of values than VB's Chr() function, because using this example returns
gobbly-gook characters. I suspect you're using a custom algorythm to
convert to Chr().

Is the Hex2Dec() you refer to here part of the Analysis Toolpak addin?
Or is it custom? <FYI>The result of passing each iteration of your
For...Next loop on the original 28 character HexString to Hex2Dec()
returns the following 14 values:
"14,14,0,0,5,5,0,12,32,69,1,100,165,165"
How does that become what you post here? For example, Chr(14) (result
of passing "0E") returns "", not 3045. Not only that, your reported
result has 2 extra characters (Len()=58, not 56).

Clearly, there's some missing info here. I suspect your "modComm"
program uses its own custom functions to process the original HexString
to get the result you claim it gives you. Not sure why you need to use
2 Hex progs to achieve the same result. Why not just get the same
function the modComm prog uses and use it with VBA by way of a lookup
function?

regards,

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
incorrect result when converting from basic string to System::String Vivienne Microsoft C# .NET 1 20th Aug 2007 07:00 AM
Re: Converting a string to a string that contains the ASCII values of each letter in the origional string Jay B. Harlow [MVP - Outlook] Microsoft C# .NET 7 1st Aug 2003 06:03 PM
Re: Converting a string to a string that contains the ASCII values of each letter in the origional string Mikael Jansson Microsoft C# .NET 0 31st Jul 2003 08:42 PM
Re: Converting a string to a string that contains the ASCII values of each letter in the origional string Jon Skeet Microsoft C# .NET 0 31st Jul 2003 08:38 PM
Re: Converting a string to a string that contains the ASCII values of each letter in the origional string Frank Oquendo Microsoft C# .NET 0 31st Jul 2003 08:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:49 AM.