I am tied in a .net c# web application where I need to print on text and barcodes of a zebra printer ( TTP2030 ). Using the RawPrinterHelper class from here . I pretty much got commands for the printer, like a Unicode string.
So, for barcode printing, I do:
string enq = Convert.ToChar(5).ToString(); string esc = Convert.ToChar(27).ToString(); string nul = Convert.ToChar(0).ToString(); string rs = Convert.ToChar(30).ToString(); string lf = Convert.ToChar(10).ToString(); string cr = Convert.ToChar(13).ToString(); StringBuilder sb = new StringBuilder(); sb.Append(esc + "BS" + nul + nul + Convert.ToChar(72).ToString() + nul + nul); sb.Append(nul + nul + Convert.ToChar(64).ToString() + nul + Convert.ToChar(2).ToString() + Convert.ToChar(2).ToString()); sb.Append(esc + "BW" + nul + "733104000099" + nul); sb.Append(lf + rs); RawPrinterHelper.SendStringToPrinter(printerName, sb.ToString());
Mnemonics for this team
< ESC>BS<0><0>< h 48><0><0> <00><0>< h 40><0><2><2> < ESC>BW<00>733104000099<00> < LF>< RS>
What I donโt know if I send things like <h 48> correctly. From the manual, leading h followed by a space indicates the hexadecimal value. In this case, this value represents the X coordinate (low byte - I don't know what it is) of the barcode.
If this value is in pixels (or mm), how do I convert to hex and then to unicode, which I send to the printer?
Also , how do I convert the decimal values โโI need to send ?
For example, to print a ruler, I send:
< ESC>r<0><0><0><0><1><230><0><24><3>
All are decimal values, which means position, start, stop, etc.
How do I convert this command so that I can send it to the printer ?
Another thing I canโt work with is getting data from the printer. Several commands are available, such as obtaining paper status, serial number, firmware, etc. To try to achieve this, I added
[DllImport("winspool.drv", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] public static extern int ReadPrinter(IntPtr hPrinter, StringBuilder data, int buf, out int pcRead);
in class RawPrinterHelper . Then I tried to send the command using SendFileToPrinter and the SendFileToPrinter file that I saved from a small application called kiosk printer toolbox , which I got from the zebra website
(I decided to send the file instead of the SendStringToPrinter method described above, because, I do not believe that I am doing the right thing there, I also checked sending the command file to the printer using several different commands, and it worked).
Then called ReadPrinter(hPrinter, sb, 6, out dwWritten); but sb empty. The method returns 0. Does anyone know how I can read data from the printer ? Is there a completely different approach that I should consider for printing (text and barcodes) and getting printer status?