wood burning stoves*
The moose likes Java in General and the fly likes Thermal printer commands: Cutter control Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Thermal printer commands: Cutter control" Watch "Thermal printer commands: Cutter control" New topic
Author

Thermal printer commands: Cutter control

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Hi, I am trying to send a cutter control command (ESC/P) to a thermal printer (Star TSP100).

The documentation says that you can send the command:
ESC d n

- where n is a function:

n Auto-cutter
0, 48 Full cut at the current position.
This command is ignored on tear-bar models.
1, 49 Partial cut at the current position.
This command is ignored on tear-bar models.
2, 50 Paper is fed to cutting position, then a full cut is executed. (*!)
On tear-bar models, paper is fed to the tear-bar position. (*2)
3, 51 Paper is fed to cutting position, then a partial cut is executed. (*1)
On tear-bar models, paper is fed to the tear-bar position. (*2)
(*1) Paper feed to cutting position: Executes a 1 inch

Please see documentation at:
http://www.starmicronics.com/support/Mannualfolder/dotcom_epm.pdf
Page 48: Cutter control

I am not sure how the function "n" works. What is meant by "0, 48"?

Here is my code:
str.append(ESC);
str.append( ( char ) 'd' );
str.append( ( char ) 0 );
str.append( ( char ) 48 );

or

str.append(ESC);
str.append( ( char ) 'd' );
str.append( ( char ) 0 );
str.append( ( char ) ',' );
str.append( ( char ) 48 );

- but it doesn't work? How do we understand the function n "0, 48"?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3581
    
  14

The commands exist of ASCII characters. In the document the ascii decimal values are listed with the commands. n may be either the numerical value of the command you want to perform, or the character code representing that number.

48 is the decimal value for ascii '0'.

You can easily create the correct String like so: (char) 27 + 'd' + '0';
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

You want to send what are normally called "escape sequences" They have been used for printer, modem, and CRT controls since the early 1970s. Maybe earlier, that's when I first started using them.

How is this printer connected to your computer? In the olden days, the printers were connected with either parallel or serial connections. Serial connections required manual setup of a lot of very low level communications parameters that we just let the network handle for us these days. Things like parity, number of bits in a byte, etc. were important and had to be managed in the application software. Stuff we usually ignore, like the highest order bit in a character, can cause serious headaches over a serial line.
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Stephan van Hulst wrote:The commands exist of ASCII characters. In the document the ascii decimal values are listed with the commands. n may be either the numerical value of the command you want to perform, or the character code representing that number.

48 is the decimal value for ascii '0'.

You can easily create the correct String like so: (char) 27 + 'd' + '0';


Thank, it works.
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Pat Farrell wrote:You want to send what are normally called "escape sequences" They have been used for printer, modem, and CRT controls since the early 1970s. Maybe earlier, that's when I first started using them.

How is this printer connected to your computer? In the olden days, the printers were connected with either parallel or serial connections. Serial connections required manual setup of a lot of very low level communications parameters that we just let the network handle for us these days. Things like parity, number of bits in a byte, etc. were important and had to be managed in the application software. Stuff we usually ignore, like the highest order bit in a character, can cause serious headaches over a serial line.


Stephans commands works.

I am using USB connection. I am wondering about if you know any java api to call ESC commands (something like setBoldFontOn(), setBoldFontOff(), setFontSize(12), etc.) or do you know any API where you can just send HTML and it will convert it to ESC commands?
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Alright I am facing a more complicated issue when printing QR barcode.

According to the manual:
http://www.starmicronics.com/support/Mannualfolder/linemode_cm_en.pdf
Page 3-128:

My code looks like, but its doesn't work. It's just printing the QR text, no QR image is shown. Do I make any mistakes in my code below?:


The following is an example showing the sending of the commands.

(1) Set bar code type
<ESC> <GS> "y" "S" "0" 1 Sets to model 1.
<ESC> <GS> "y" "S" "1" 0 Sets mistake correction level to L.
<ESC> <GS> "y" "S" "2" 3 Sets cell size to 3 dots.

(2) Set bar code data
<ESC> <GS> "y" "D" "1" 0 20 0 "2005, January, 1 (SAT)" <LF>
Sets bar code data (Data automatic analysis)
Sets bar code data (Data manual analysis)

<ESC> <GS> "y" "D" "2" 10 1 4 0 "2005" ","
4 2 0 "Year" ","
1 1 0 "1" ","
4 2 0 "Month" ","
1 1 0 "1" ","
4 2 0 "Day" ","
4 2 0 "(" ","
2 3 0 "SAT" ","
4 2 0 ")" ","
3 1 0 <LF>

(3) Print bar code
To verify whether to print with the current settings, check the bar code expansion information.
<ESC> <GS> "y" "I" Check bar code expansion information
<ESC> <GS> "y" "p" Print
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Jeppe Sommer wrote: I am wondering about if you know any java api to call ESC commands (something like setBoldFontOn(), setBoldFontOff(), setFontSize(12), etc.) or do you know any API where you can just send HTML and it will convert it to ESC commands?


I've never see an API for it, other than the many that I wrote over the years. In later years, the Unix folks provided termcap to handle some of it, and of course X-windows extends the idea around the basic idea.
 
jQuery in Action, 2nd edition
 
subject: Thermal printer commands: Cutter control
 
Similar Threads
Incrementing alphanumeric string
How to display all of the ascii characters
Convert image to raw binary data
Input redirection in Java
Check free space of a directory of linux environment in Java