News:

  • May 14, 2026, 10:36:29 AM

Login with username, password and session length

Author Topic: String to Hex  (Read 11370 times)

Garyhlucas

  • Hero Member
  • *****
  • Posts: 421
String to Hex
« 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?

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3814
    • Host Engineering
Re: String to Hex
« Reply #1 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.

Garyhlucas

  • Hero Member
  • *****
  • Posts: 421
Re: String to Hex
« Reply #2 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.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3814
    • Host Engineering
Re: String to Hex
« Reply #3 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

Garyhlucas

  • Hero Member
  • *****
  • Posts: 421
Re: String to Hex
« Reply #4 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!

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3814
    • Host Engineering
Re: String to Hex
« Reply #5 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
« Last Edit: October 30, 2025, 01:46:16 PM by franji1 »