我已经通过USB连接了Zebra打印机,我正在尝试使用命令读取打印机的内存
^XA^HWR:^XZ
. 该命令在TCP/IP上工作。
我甚至不确定我是否有正确的方法头。
[DllImport("winspool.Drv", EntryPoint = "ReadPrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
static extern bool ReadPrinter(IntPtr hPrinter, IntPtr pBuf, int cbBuf, out int pNoBytesRead);
方法
ReadPrinter
始终返回false和0个读取字节。当我试图
LastWin32Error
,我得到了0,6或63的变化(
ERROR_SUCCESS
-尽管它返回false并且没有数据,
ERROR_INVALID_HANDLE
或
ERROR_PRINT_CANCELLED
),这取决于我正在努力。我尝试了几种方法头和不同的方法,但都没有成功读取数据。我启用了“双向支持”,并安装了打印机驱动程序。它看起来像是其他线程的副本,但我已经通过了它们,没有一个是有用的。
代码段:
private static void SendBytesToPrinter(string printerName, IntPtr pointerBytes, int bytesCount)
{
int written = 0;
PrintResult printResult = new PrintResult();
IntPtr pointerPrinter = new IntPtr(0);
DOCINFOA docInfo = new DOCINFOA();
bool success = false;
docInfo.DocName = "RAW Document";
docInfo.DataType = "RAW";
try
{
if (OpenPrinter(printerName.Normalize(), out pointerPrinter, IntPtr.Zero))
{
if (StartDocPrinter(pointerPrinter, 1, docInfo))
{
if (StartPagePrinter(pointerPrinter))
{
success = WritePrinter(pointerPrinter, pointerBytes, bytesCount, out written);
EndPagePrinter(pointerPrinter);
}
EndDocPrinter(pointerPrinter);
}
// READ HERE
Int32 bufLen = 32;
IntPtr pStatus = Marshal.AllocCoTaskMem(bufLen);
Int32 statusLen = 0;
bool bSuccess = ReadPrinter(hPrintJob, pStatus, bufLen, out statusLen);
ClosePrinter(pointerPrinter);
}
} catch (Exception ex) { }
}