LibUsbDotNetを使用して、GC420t Zebra プリンターと通信しています。
印刷に関してはうまく機能します。
MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
if (MyUsbDevice == null) throw new Exception("Device Not Found.");
IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
{
wholeUsbDevice.SetConfiguration(1);
wholeUsbDevice.ClaimInterface(0);
}
UsbEndpointWriter writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01);
int bytesWritten;
if (writer.Write(Encoding.Default.GetBytes(someString), 2000, out bytesWritten) != ErrorCode.None)
throw new Exception(UsbDevice.LastErrorString);
しかし、リーダー コードを機能させる方法が見つかりません... 常に 0 バイトの読み取り値を返します。上記のコードの最後にそれを配置し、プリンターのふたを開けました(エラー コードが表示されるはずです)。
UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
// above code...
ErrorCode ec = ErrorCode.None;
byte[] readBuffer = new byte[1024];
while (ec == ErrorCode.None)
{
int bytesRead;
ec = reader.Read(readBuffer, 5000, out bytesRead);
Console.WriteLine("{0} bytes read", bytesRead);
Console.Write(Encoding.Default.GetString(readBuffer, 0, bytesRead));
}
あなたがそれを機能させる方法を知っていれば...またはそれを行うためのより良い/より速い/より簡単な方法を知っているなら、私はそれを受け入れます、ありがとう。
編集:それで、さらにいくつかのことを試し、さらに調査を行いました。
winspool を使用してプリンターのステータスにアクセスする
-> プリンターからメディアを取り外したにもかかわらず、0 が返されました。まあ、0 に初期化されただけで、値を受け取っていないと思います。このコードはOpenPrinter/GetPrinter/ClosePrinterパターンを使用しています。
LibUsbDotNet -> リストされたすべてのステータス読み取り方法を試しましたが、常に 0 バイトが読み取られました。
RawPrinterHelper -> 印刷用に動作しますが、プリンターのステータスを取得する方法が見つかりませんでした。
次に、プリンターが印刷している間にステータスを読む必要があるという何かを読みました(どのサイトで覚えていない) 。どうすればそれができますか?
編集:完全を期すために、プリンター用のコマンドを生成する方法を次に示します(これは、印刷に関しては問題なく動作するため、おそらく役に立たないでしょう):
StringBuilder sb = new StringBuilder().AppendLine()
.AppendLine("N")
.AppendLine("^ee") // The "give me an answer" code, also tested at the end of the commands, or as the only command (with newline and N)
// more appending...
.AppendLine(String.Format("P{0},{1}", 1, 1));
編集: 記録として、この GC420t のステータスを取得できると私が確信している理由は、Zebra Setup Utilities を使用して取得できるからです。提供されているツール ( Open Communication With Printer ) で^eeを送信すると、エラー コードが正しく取得されます。それがどのように行われるかを知る必要があります。