이미 블루투스 용 EPSON SDK를 구현하고 잘 작동하지만 다른 프린터에서 작동하지 않는 경우 일반적인 방법으로이를 수행 할 수 있습니까? ESC 명령이란 무엇입니까?,어떻게 공급 업체 SDK를 사용하지 않고 Android의 열전 사 프린터 (USB/이더넷)를 사용합니까?
답변
this을 찾으십시오. 문제를 해결하는 데 도움이됩니다. ESC/POS 명령 참조는 표준 명령 구문 및 프로토콜과 같은 ESC/POS 명령에 대한 자세한 정보를 제공합니다. ESC/POS 명령을 사용하여 프린터를 제어하려는 프로그래머를 대상으로합니다.
ESC/POS 명령 참조서는 용지 롤 프린터 용 ESC/POS APG를 대체합니다. 따라서 용지 롤 프린터 용 ESC/POS APG는 더 이상 개정되지 않습니다. ESC/POS Command Reference에는 ANK 모델 또는 일본 모델과 같은 표준 모델에 대한 명령 정보가 들어 있으며 중국어 모델 또는 남아시아 모델이 포함될 수 있습니다. 사용자 지정과 같은 다른 모델은 다른 명령을 지원하거나 명령 매개 변수의 다른 기본값 또는 다른 기본값을 가질 수 있습니다. 각 제품 사양을 참조하십시오. 코드 아래
는사용
참고 : ESC/POS 직접 출력 스트림에 명령을 쓸 수
public class PrinterConstants {
public static int PORT=9100,TOTAL_CHAR=45,DIV1=10,DIV2=5,DIV3=10,DIV4=10,DIV5=10;
public static String IP="192.168.1.35";
private OutputStream printer;
public static final String UUID="00001101-0000-1000-8000-00805f9b34fb";
public PrinterConstants(OutputStream printer){
this.printer=printer;
}
public void printString(String str) throws IOException {
Log.i("PRINTER_PRE",str);
printer.write(str.getBytes());
printer.write(0xA);
printer.flush();
}
public void storeString(String str) throws IOException {
printer.write(str.getBytes());
printer.flush();
}
public void printStorage() throws IOException {
printer.write(0xA);
printer.flush();
}
public void feed(int feed) throws IOException {
//escInit();
printer.write(0x1B);
printer.write("d".getBytes());
printer.write(feed);printer.flush();
}
public void printAndFeed(String str, int feed) throws IOException {
//escInit();
printer.write(str.getBytes());
printer.write(0x1B);
printer.write("d".getBytes());
printer.write(feed);printer.flush();
}
public void setBold(Boolean bool) throws IOException {
printer.write(0x1B);
printer.write("E".getBytes());
printer.write((int)(bool?1:0));printer.flush();
}
/**
* Sets white on black printing
* */
public void setInverse(Boolean bool) throws IOException {
bool=false;
printer.write(0x1D);
printer.write("B".getBytes());
printer.write((int)(bool?1:0));printer.flush();
}
public void resetToDefault() throws IOException {
setInverse(false);
setBold(false);
setUnderline(0);
setJustification(0);printer.flush();
}
/**
* Sets underline and weight
*
* @param val
* 0 = no underline.
* 1 = single weight underline.
* 2 = double weight underline.
* */
public void setUnderline(int val) throws IOException {
printer.write(0x1B);
printer.write("-".getBytes());
printer.write(val);printer.flush();
}
/**
* Sets left, center, right justification
*
* @param val
* 0 = left justify.
* 1 = center justify.
* 2 = right justify.
* */
public void setJustification(int val) throws IOException {
printer.write(0x1B);
printer.write("a".getBytes());
printer.write(val);
printer.flush();
}
public void setLeftRight(String left,String right) throws IOException {
printer.write(0x1B);
printer.write("a".getBytes());
printer.write(0);
printString(left);
printer.write(0x1B);
printer.write("a".getBytes());
printer.write(2);
printString(right);
printer.flush();
}
public void printBarcode(String code, int type, int h, int w, int font, int pos) throws IOException {
//need to test for errors in length of code
//also control for input type=0-6
//GS H = HRI position
printer.write(0x1D);
printer.write("H".getBytes());
printer.write(pos); //0=no print, 1=above, 2=below, 3=above & below
//GS f = set barcode characters
printer.write(0x1D);
printer.write("f".getBytes());
printer.write(font);
//GS h = sets barcode height
printer.write(0x1D);
printer.write("h".getBytes());
printer.write(h);
//GS w = sets barcode width
printer.write(0x1D);
printer.write("w".getBytes());
printer.write(w);//module = 1-6
//GS k
printer.write(0x1D); //GS
printer.write("k".getBytes()); //k
printer.write(type);//m = barcode type 0-6
printer.write(code.length()); //length of encoded string
printer.write(code.getBytes());//d1-dk
printer.write(0);//print barcode
printer.flush();
}
public void beep() throws IOException {
printer.write(0x1B);
printer.write("(A".getBytes());
printer.write(4);
printer.write(0);
printer.write(48);
printer.write(55);
printer.write(3);
printer.write(15);printer.flush();
}
public void setLineSpacing(int spacing) throws IOException {
//function ESC 3
printer.write(0x1B);
printer.write("3".getBytes());
printer.write(spacing);
}
public void cut() throws IOException {
printer.write(0x1D);
printer.write("V".getBytes());
printer.write(48);
printer.write(0);printer.flush();
}
}
당신 위에 사용하여 프린터에 상관없이 블루투스 또는 이더넷 또는 무선 랜을 쓸 수의 OutputStream 객체를 사용할 수 있습니다
대부분의 프린터와 호환되는 대부분의 프린터에 대한 구현을 찾아서 만들었으므로 다른 프린터와 호환되므로 어렵지 않을 것입니다 (또한 공급 업체 SDK를 복사하게 될 것입니다).
그리고 ..., printText는, printImage, printBarCode
읽기
static String getDeviceName() {
String manufacturer = Build.MANUFACTURER;
String model = Build.MODEL;
if (model.startsWith(manufacturer)) {
return capitalize(model);
} else {
return capitalize(manufacturer) + " " + model;
}
}
그렇게 같은 장치를 모두 구현 스캔, 초기화 등을 사용할 수있는 인터페이스를 만들고 결정하는 결과를 사용하는 대부분의 장치에서 작동하는 기본값으로 설정하기 전에 사용할 구현입니다. 인터페이스를 통해 진행 한 문제를 곧 잊어 버릴 수 있습니다.
ESC 명령, 이러한 그들은 정렬, 새 줄을 시작 에 사용되는 대부분의 장치와 거의 동일한 프린터에 바로 명령입니다 된 텍스트, 대담 등 그 생각해처럼 html 마크 업 (strong, h1, center)은 멋진 텍스트를 쉽게 만들 수 있도록 인쇄 할 텍스트와 혼합하기 때문에 유용합니다.믿을만한 소스 또는 공식 소스에 관해서는 ... 내가 마지막으로 체크했다. 안드로이드에서 감열 인쇄는 표준화되지 않았습니다. 적어도 제조는 표준을 따릅니다. – konzo
Build.MANUFACTURER는 반환되는 안드로이드 장치입니다. 어떻게 ESC 명령을 사용할 수 있습니까? 어떻게 OutPutStream에 작성합니까? –
거의 모든 제품이 ESC 프린터의 표준은 무엇입니까? –
감열 프린터 [have_look] (https://github.com/imrankst1221/Thermal-Printer-in-Android) –
을 사용할 수 있지만 Bluetooth 만 지원합니까? 나는 USB 또는 이더넷이 필요하다 ... : ( –
나는 벤더 SDK가 필요하고, 벤더 만이 USB/이더넷을위한 하드웨어와 I2C 통신 링크를 알고 있다고 생각한다. – YinKiet