Start a conversation

Working with hexadecimal (hex) data in a control string

Let's say you are working with a device that is controlled via serial or Telnet.  The manufacturers manual specifies that the command requires sending hex data.  What is this and how do you do that?

Image result for ascii chart

The chart above is commonly referred to as an ASCII chart.  In this chart, the 3 columns to the right all represent characters you can type on your keyboard or write down on a piece of paper, for instance "A" or "5" or "?".  Those are simple, we can send those in a text string.

But the first column on the left is a little different - those are all non-printable control characters.  Example, how could you write the Backspace key or the Esc key in a text document or on a piece of paper?

To do that, there is alternate notation to handle representing those characters as a string.  In the image, you see decimal (Dec) and hexadecimal (Hex) codes for the characters.  These are different ways of representing these non-printable characters as a string, kind of like an alternate alphabet.  Hex is what you typically use in control system programming for these non-printable characters.

One common problem is, every manufacturer seems to want to represent this data differently, below are some variations of a carriage return (hex 0D):

  • <cr>
  • <0D>
  • $0D
  • %0D
  • \r
  • \x0D
  • 0x0D
  • [0D]
  • {0D}
  • 0Dh

...and the list goes on.  As you browse through more control protocol manuals, you will start seeing references similar to these.  Typically, the command will either show a reference to the hex code (0D, 02, 03...) or the character name (CR [carriage return], STX [start of text], ETX [end of text]...).  Identifying those will allow you to know which character it is, and input the appropriate hex character code.

Aurora products use the percent character to prefix a 2 digit hex code, such as %0D, %02, %03.  To send an actual percent sign, you simply send %%

Example 1 (Panasonic projector):

In this example, the document shows both the printable characters and the hex codes.  To send a power on command, you would input the following string:


Example 2 (Sharp LCD display):

In this example, to send a power on command, you would send the following string (notice the 3 spaces between the "1" and the carriage return, as specified in the manual):

POWR1   %0D

Example 3 (Optoma Projector):

In this example, to send a power on command, you would send the following string.  This commands uses a 2-digit ID (bytes 2 and 3, represented by the XX:

~0000 1%0D

Should I use ASCII or HEX in my programming?

This is a common question.  The answer - you can use either, or mix and match .  They are both a different ways of representing the same character.  The suggested method is to use printable ASCII when the character is printable, and HEX when it is not.  However, many control protocol guides from device manufacturers may only specify HEX - it will not hurt entering all hex (*see note below).

As you can see in example 1 above, the manual shows notation for both ASCII and HEX notation.  The first and last characters cannot be represented as ASCII, so HEX must be used.  This means that the following 2 commands are functionally identical:


The same for example 3 above, the manual shows ASCII and HEX.  The following commands are also identical:

~0000 1%0D

*NOTE: If you input HEX data in the Event Manager that can be represented as ASCII, the Event Manager will automatically simplify it to ASCII once saved.  This is normal, and why using ASCII characters when possible is recommended.

Feel free to contact us via email, chat, social media, or a phone call if you need assistance with programming your Aurora control system.

Choose files or drag and drop files
Was this article helpful?
  1. Chris Koerner

  2. Posted
  3. Updated