Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

ESC/P Printer Codes

  • Please log in to reply




  • Member
  • PipPipPip
  • 714 posts
My intention is to move the "cursor" on the printer several spaces to the right.
According to Epson's ESC/P manual:

ESC $ Set absolute horizontal print position
27 36 nL nH

· Set the defined unit with the ESC ( U command.

So...me taking a guess, I execute the ff code:
//out.write(10);  // line feed
out.write(27); // esc
out.write(40); // (
out.write(85); // U
out.write(1);  // nl
out.write(0);  // nh
out.write(5);  // m
out.write(27); // esc
out.write(36); // $
out.write(120); // move 2 inches
out.write(120); // move 2 inches
out.write(12); // form feed
out.write(7);  // beep

Expected output:
1234567890                   		!@#$%^&*()

Actual output:

What am I doing wrong?

Thanks. :cool:
  • 0





  • Member
  • PipPipPipPip
  • 1,355 posts
Hey again Sera,

So I must be honest haven't really had experience with dev for printers... But I have looked into it a bit and hopefully I can help a little.... It looks like your values for setting the "absolute print position" is incorrect... Value for nL and nH don't make sense according to a function I came across when trying to learn more about the topic. It looks like if values nL and nH are the same, they basically cancel each other out. Here is the function that I trust will come in handy:
private static final float CM_PER_INCH = 2.54f;

public void setAbsoluteHorizontalPosition(float centimeters) {
        //pre: centimenters >= 0 (cm)
        //post: sets absolute horizontal print position to x centimeters from left margin
        float inches = centimeters / CM_PER_INCH;
        int units_low = (int) (inches * 60) % 256;
        int units_high = (int) (inches * 60) / 256;
        pstream.print((char) units_low);
        pstream.print((char) units_high);

So in your case you would like to set the position 2 inches from the left margin, using the function above should result in the same thing... But to adapt for the code you have written this section should look like this when setting absolute position:
out.write(27); // esc
out.write(36); // $
out.write(120); // move 2 inches
out.write(0); // This is the value that needed to change

That's about it, give it a try and let me know if it works... Unfortunately I have no way of testing this, also it looks like its working fine for you but just to make sure send a return sequence before flushing (If it results in error, just remove it)

I really hope I helped a litte bit, here is a refrence to where I got that function from. Maybe you can find other functions that might prove useful to you or use the whole class all together:

Here's another useful reference:

Peace Out Posted Image
  • 1




  • Topic Starter
  • Member
  • PipPipPip
  • 714 posts
Hi spike_hacker_inc,

Your response was perfect!
Thanks so much for the help.
It's really true that sometimes, all you need is someone with a fresh perspective on things to see the problem.

Peace Out :cool:
  • 0

Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP