Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Garyhlucas on October 29, 2025, 04:29:27 PM

Title: String to Hex
Post by: Garyhlucas on October 29, 2025, 04:29:27 PM
We have a printer that requires serial data to be in hexidecimal. How do we convert a string to hex?
Title: Re: String to Hex
Post by: franji1 on October 29, 2025, 04:49:26 PM
So you mean ASCII HEX, e.g. you want to send the characters "ABC" needs to go out as ASCII "414243"?

Better - provide me an example of a SOURCE STRING you are starting with (e.g. "Hello"), and what the printer expects.
Title: Re: String to Hex
Post by: Garyhlucas on October 30, 2025, 08:28:13 AM
Yes that is exactly what I need.  We are printing the results of a test on a card using a Sneed inkjet printer that uses an HP45 cartridge to print 1/2" wide as it is moved.
Title: Re: String to Hex
Post by: franji1 on October 30, 2025, 09:31:51 AM
I wrote it (it was an interesting problem)

I created a subroutine ConvertToHexBuff that converts the string in SS0 into an ASCII Hex string in the heap item ASCIIHexBuff that is 1024 max bytes long (so max string of 512 since it's 2x the original text length)

The attached works in the sim in 2.10
Title: Re: String to Hex
Post by: Garyhlucas on October 30, 2025, 01:34:28 PM
AWESOME!
I write PLC code about every 6 months or so which means I will never be very good at it!  This saves me hours of frustration.

Is there a repository of useful code pieces like this for the BRX that I should know about?

Thanks!
Title: Re: String to Hex
Post by: franji1 on October 30, 2025, 01:43:19 PM
AWESOME!
I write PLC code about every 6 months or so which means I will never be very good at it!  This saves me hours of frustration.

Is there a repository of useful code pieces like this for the BRX that I should know about?

Thanks!

Yes there is, below this forum is "Examples".  I probably need to put it there too.

EDIT:
Here's a link to that "sub-forum" - I just added a link to yours there
https://forum.hosteng.com/index.php?board=20.0