I have been logging onto the blog for a long time. I have just been in the development field for a year. I don't know what to write on my blog. Now I want to share some of my work experience with bar code printers.CodeI hope to give some help to scholars. I have a limited level and cannot write much. The specific code is as follows:
// Enable the serial port of the printer.
Internal class barcodeprinter
{
// Port
Private string filename;
Public barcodeprinter (string port)
{
This. filename = port;
}
[Dllimport ("printedll. dll")]
Private Static extern int closeprinter ();
// Obtain the print command
Public String getlabelcommand (string filename)
{
Streamreader reader = new streamreader (filename );
String STR = "";
String str2 = NULL;
While (str2 = reader. Readline ())! = NULL)
{
STR = STR + str2;
}
Reader. Close ();
Return STR;
}
[Dllimport ("printedll. dll")]
Private Static extern int openprinter (string filename );
// Print the barcode
Public void printlabel (string text)
{
If (openprinter (this. filename) <0)
{
Throw new exception ("tag printing: Open" + this. filename + "failed. ");
}
Write (text );
Closeprinter ();
}
[Dllimport ("printedll. dll")]
Private Static extern int write (string text );
}
// Call
// Instantiate the Print Object
Barcodeprinter v_barcode_printer = new pack_barcode.model.barcodeprinter (Serial Port );
// Zpl II language (For details, refer to zpl II description)
String strprint = "^ XA
^ Lh0, 0
^ Fo60, 303 ^ gb1100, 0, 10 ^ FS
^ Fo550, 303 ^ gb0, 647,10 ^ FS
^ Fo120, 670 ^ A0, 25, 40 ^ fdpn: $ P ^ FS
^ Xz ";
// Print method.
Private void printtext (string Str)
{
V_barcode_printer .. printlabel (strprint. Replace ("$ P", STR );
}