Charmed Quark Systems, Ltd. - Support Forums and Community
Insert HEX value into buffer - Printable Version

+- Charmed Quark Systems, Ltd. - Support Forums and Community (https://www.charmedquark.com/vb_forums)
+-- Forum: General Discussion (https://www.charmedquark.com/vb_forums/forumdisplay.php?fid=3)
+--- Forum: Driver Development (https://www.charmedquark.com/vb_forums/forumdisplay.php?fid=13)
+--- Thread: Insert HEX value into buffer (/showthread.php?tid=10686)



Insert HEX value into buffer - jnolting - 09-26-2018

I have a Hex string that I need to I need to but into a buffer and have sent across the wire as is.

The string I have I have is: AA 11 00 01 00 12

and when its going across the wire I need it to look like:

[img]data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAmQAAABYCAYAAABbNutDAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABYvSURBVHhe7Z2/bh07kof1SBPrOS42WWBD5c423mQTA1cP4NgTODegRA71AiOsAQNjwJhkcJOLiSY721Uku4tssrrIJtV9jn4fULb68LC6qlisrvNHrbs///zzAoFAIBAIBAI5TtCQQSAQCAQCgRwsaMggEAgEAoFADhY0ZBAIBAKBQCAHCxoyCAQCgUAgkIPl7n/+9/ECgUAgEAgEAjlOuCHLdWpnFAAAAACAWwQNGQAAAADAwaAhAwAAAAA4GDRkABzO18vD3cP0LwDgLfj6cHd5wIYDJ8PWkP16uXz59OnyieXL5eXX4LGC7OLH4+X+7u5yx3J/efzhHz8pPx7v2VZT0fj64P2KZWjBic5Z0Uxo65D6UelANmZNOn9cHu/FnNW8ZbxPjJWGbM/aqr63+tDb9y0azzcizzSdO+vLOne3clBhoJ23AMdaxpLy4f5xinjAxX5+ShSzt8r7t4Oa0+CbE7w4PApDQ/Z6eZqapqdXf8yN1NPlddhYWdqhC166wU6cdFwgHi4PsihUQf4OLLZp/FYFrQQVumUeF8Z5XtqUVPqQjVmrzqQgRwQd2nNqSe3UsPqg+d7qQ+u8VvbYKZ4f5SuNteTEls7SmIFs7rbGeKCdt0DOZ7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z44uYGrOizgltTCNpvCSuCXNy//g42b23IUt8rylyw3zvp5MKpmu0HD+e/5g8Xi7gxTG10FJzscY1C9rYDuHmMSAam60xTYrzdvjQ3U7FlkjfAo2BW8a9cHZ1oK4etICGDJwFW0N2EgEgpblgXkmhheQFgF6gIQNnAQ0ZuGrQkL1PAaAXaMjAWUBDBq4aNGTvUwDoBdcCTTL5dzYBtwEaMnDVPDw8NAsAAABwFtCQAQAAAAAcDBoyAAAAAICDQUMGAAAAAHAwaMgAAAAAAA4GDRkAAAAAwMGgIQMAAAAAOBg0ZAAAAAAAB4OGDAAAAADgYNCQAQAAAAAcDBoyAAAAAICDQUMGAAAAAHAwaMgAAAAAAA4GDRkAAAAAwMGgIQMAAAAAOBg0ZAAAAAAAB4OGDAAAAADgYNCQAQAAAAAcDBoyAAAAAICDQUMGAAAAAHAwaMgAAAAAAA4GDRkAAAAAwKFcLv8PfDa0EYmUpcUAAAAASUVORK5CYII=[/img]

The device is a Samsung Display device that speaks the MDC protocol. However I import the Hex vals they end up
getting sent as something else when the hit the wire.


RE: Insert HEX value into buffer - Dean Roddey - 09-26-2018

If you just try to import the string, you are getting the values of the characters. If you literally need the binary bytes represented by those two digit numbers, then you need to pull each two digit chunk out and convert to a hex value. If the format is consistently like that, then you could basically do this in a loop:

Code:
While (Index < FullStrLen)
     Card4Val := SrcStr.ExtractCard4R(Index, 2, Radices.Hex);
     TarBuf.PutCard1(OutBufIndex++, Card4Val.GetLowByte());
     Index += 3;
EndWhile;

So you loop through the string. Each time you extract a Hex digit. It will take the characters AA, for instance, and convert to the actual binary value 0xAA. You get a Card4 but only need a Card1, so get the low byte out, and put it into the next available index in the output buffer.

Then skip the string index forward by 3 to get to the next two digit chunk.

Once you get the whole buffer built up. Use the Base64 class to Base64 encode it, and that gets you the output format you want.


RE: Insert HEX value into buffer - jnolting - 09-27-2018

That did the trick! Thanks Dean.