私はTSC TTP-244 Proプリンタを使用して出荷ラベルを印刷するためのJavaアプリケーション(linuxデスクトップ上で動作する)を開発中です。このプリンタは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通信は正しいですか?
このUSB通信は、プリンタドライバ(Linux)をインストールせずにTSCプリンタと通信できますか?
ありがとうございます。コントロール合計または異なるエンドポイントの側面を調べます。 – Venky
私はまだ印刷に成功していませんでしたが、以前は 'PRINT'コマンドで何が問題だったのかを確認しました。プリンタが印刷を開始するために 'PRINT'コマンドの最後に' 'を発行しなければなりませんでした(恐らくそれが内部バッファをフラッシュする指示)。 ''プリンタが応答しましたが、設定問題(リボンの配置とラベルの位置に関する問題)のため、印刷中にプリンタがエラーを表示しています。とにかく、あなたの入力に感謝します。 –
Venky
はい、私の答えを受け入れるのに役立つなら、CR LFコマンドの最後に不可欠です。 –