问题
The following is a C# function that sends ZPL command through serial port. the ZPL Command Starts with ~RVE (which telling the printer to send RFID encoding success or failure results).
How can I receive the encoding result in the context of my code and check that the encoding process succeed?
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();
}
回答1:
Probably you won't be able to retrieve result using LPT and CreateFile. You need to use bi-directional communication, using sockets.
Update: There is a inpout32 library available, which allows two-way lpt port communications.
Reading from Parallel Port using Inpout32.dll
Converting Visual Basic parallel port app using inpout32.dll in to Delphi
Download inpout32 binaries and sources
来源:https://stackoverflow.com/questions/16775701/verify-encoding-tags-by-zebra-printer-rz400