I am having trouble with setting the horizontal print position in an Epson LX-300 II dot matrix printer. The command to set the horizontal print position does not work somet
The problem I found is that UTF-8 is multi-byte encoding and ESC-P needs the commands to be in a single byte, from 0-256
ISO-8859-1 is single byte encoding up to 256.
Java byte is a decimal from a signed 2's compliment so numbers over 127 are negative.
public byte getN1(int total) {
// a java byte can only be -127 > 127
// so the negative numbers represent the numbers greater than 127
int n1 = total % 256;
if (n1 > 127) {
n1 = n1 - 256;
}
return (byte) n1;
}
public byte getN2(int total) {
// N2 is a factor of 256. so it is multiplied by 265 and added to N1.
// generally it is either 1 or 0 but can be more for things like vertical
// position.
int n2 = total / 256;
return (byte) n2;
}
public String setAbsoluteHorizontalPosition(int dots) throws UnsupportedEncodingException {
byte[] x = { ESC, '$', this.getN1(dots), this.getN2(dots) };
return new String(x, "ISO-8859-1");
}