저는 Linux 데스크탑에서 실행되는 Java 응용 프로그램을 개발하여 TSC TTP-244 Pro 프린터를 사용하여 운송 레이블을 인쇄합니다. 이 프린터는 TSPL2 명령을 지원합니다.Java 응용 프로그램에서 TSC 프린터로 인쇄
USB 연결을 사용하고 있으며이 프린터와 통신하기 위해 usb4java 고급 API를 사용하여 간단한 테스트를 작성하기 시작했습니다. 프린터 상태/상태 <ESC>?!
또는 <ESC>?S
(<ESC>
여기 ASCII 27)을 쿼리 할 수 있지만 문제는 없지만 PRINT
명령을 실행할 수는 없습니다.
아래 코드는 제 코드입니다.
@Test
public void printTest() throws UsbException
{
final UsbServices services = UsbHostManager.getUsbServices();
UsbDevice printerUsbDevice = findDevice(services.getRootUsbHub(), 0x1234, 0x1734);
UsbConfiguration configuration = device.getActiveUsbConfiguration();
UsbInterface iface = configuration.getUsbInterface((byte) 1);
iface.claim();
try
{
UsbEndpoint inEndpoint = iface.getUsbEndpoint(0x01);
UsbPipe pipe = inEndpoint.getUsbPipe();
UsbEndpoint outEndpoint = iface.getUsbEndpoint(0x82);
UsbPipe pipe2 = outEndpoint.getUsbPipe();
pipe2.open();
pipe.open();
pipe.syncSubmit(27 + "!?".getBytes("US-ASCII"));
pipe.close();
pipe2.open();
byte[] statusResponse = pipe2.syncSubmit(new byte[1]);
pipe2.close();
System.out.println(new String(statusResponse, "US-ASCII")); // Here status got is "00" if ok otherwise getting error code
pipe.open();
pipe.syncSubmit("SIZE 57 mm,37 mm");
pipe.syncSubmit("GAP 3 mm,0 mm");
pipe.syncSubmit("DIRECTION 1");
pipe.syncSubmit("CLS");
pipe.syncSubmit("TEXT 10,10 "3",0,1,1, "Test printing");
pipe.syncSubmit("PRINT 1");
pipe.close();
// at this pint of time, printer is not printing anything instead just idle
}
finally
{
iface.release();
}
}
private UsbDevice findDevice(UsbHub hub, short vendorId, short productId)
{
for (UsbDevice device : (List<UsbDevice>) hub.getAttachedUsbDevices())
{
UsbDeviceDescriptor desc = device.getUsbDeviceDescriptor();
if (desc.idVendor() == vendorId && desc.idProduct() == productId) return device;
if (device.isUsbHub())
{
device = findDevice((UsbHub) device, vendorId, productId);
if (device != null) return device;
}
}
return null;
}
내 USB 통신이 정확합니까?
프린터 드라이버 (Linux)를 설치하지 않고이 USB 통신이 TSC 프린터와 작동합니까?
고맙습니다. 컨트롤 합계 또는 다른 끝점 측면을 조사합니다. – Venky
아직 인쇄 작업에 성공하지는 못했지만 'PRINT' 명령으로 문제가 무엇인지 먼저 확인했습니다. 프린터가 인쇄를 시작하기 위해'PRINT' 명령의 마지막에''을 실행해야했습니다 (아마 내부 버퍼를 비울 것이라는 표시 였을 것입니다). ' '프린터가 응답했지만 내 설정 문제 (리본 배치 및 라벨 위치와 관련 있음)로 인해 프린터가 인쇄 중에 오류를 표시합니다. 아무튼, 귀하의 의견을 보내 주셔서 감사합니다. –
Venky
예, 답장을 수락하는 데 도움이된다면 명령 끝의 CR LF가 필수적입니다. –