以下是通过串口发送ZPL命令的C#功能。 ZPL命令以~RVE开头(告诉打印机发送RFID编码成功或失败的结果)。
如何在代码上下文中接收编码结果并检查编码过程是否成功?
private void Print()
{
// Command to be sent to the printer
string command = "~RVE^XA^RFw,H^FD033B2E3C9FD0803CE8000001^FS ^XZ";
// Create a buffer with the command
Byte[] buffer = new byte[command.Length];
buffer = System.Text.Encoding.ASCII.GetBytes(command);
// Use the CreateFile external func to connect to the LPT1 port
SafeFileHandle printer = CreateFile("LPT1:", FileAccess.ReadWrite,
0, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
// Aqui verifico se a impressora é válida
if (printer.IsInvalid == true)
{
return;
}
// Open the filestream to the lpt1 port and send the command
FileStream lpt1 = new FileStream(printer, FileAccess.ReadWrite);
Byte[] ResultBuffer = new byte[255];
lpt1.Write(buffer, 0, buffer.Length);
// Close the FileStream connection
lpt1.Close();
}
答案 0 :(得分:0)
可能您无法使用LPT和CreateFile检索结果。 您需要使用bi-directional communication, using sockets.
更新: 有一个inpout32库,允许双向lpt端口通信。
Reading from Parallel Port using Inpout32.dll
Converting Visual Basic parallel port app using inpout32.dll in to Delphi