下面是一个通过串口发送 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();
}