views:

412

answers:

0

Hello!

I'm woking on a .net c# web app where I need to print on a zebra printer (TTP2030) text and barcodes. Using the RawPrinterHelper class from here http://support.microsoft.com/kb/322091 I pretty much got the commands to the printer, as a unicode string.

So, to print a barcode 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());

The mnemonic for that command is

< 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 is if I'm sending correctly things like < h 48>. From the manual, a leading h followed by a space indicates a hex value. In this case that value represents the X coordinate (the low order byte - I don't know what this is) of the barcode. If this value is in pixels (or mm), how do I convert to hex and then to the unicode I'm sending to the printer? Also, how do I convert the decimal values I have to send? For example for printing a ruler line I send < ESC>r<0><0><0><0><1><230><0><24><3>. All are decimal values, meaning position, start, stop etc. How do I convert this command so I can send to the printer? Another thing I cannot get to work is getting data from the printer. There are several commands available, like getting the paper status, the serial number, firmware etc. To try to achive this first 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 the RawPrinterHelper class. Then I tried to send the command using SendFileToPrinter and a .prn file I saved from a small app called kiosk printer toolbox I got from the zebra website (I chose to send a file instead of the SendStringToPrinter aproach I described above because, well, I don't trust I'm doing the right thing there, and also I tested sending a commands file to the printer with several different commands and it worked). Then called ReadPrinter(hPrinter, sb, 6, out dwWritten); but sb is empty. The method returns 0. Does anyone know how I can read data from the printer? Is there a totally different approach I should be considering for printing (text and barcodes) and getting the printer status?

Have a nice day!