Connecting Tech Pros Worldwide Help | Site Map

Print to USB Thermal Printer (brand Zebra 3842)

Newbie
 
Join Date: Oct 2009
Posts: 8
#1: Oct 1 '09
I have an application that prints to a Thermal Printer..These are the older printers (brand Zebra 3742) and uses the Serial Com Port 1 & 2. I have that working. We now have two new printers (brand Zebra 3842) but are USB. Now I have to write code to print to these USB printers but not sure where to start.

Using the system printing functions won't due because I had trouble sending the ELP Commands this way. I am still looking into this method to see if there is anything I can do different to make this work.

Any Help would be Appreciated!
Thanks
Newbie
 
Join Date: Oct 2009
Posts: 8
#2: Oct 1 '09

re: Print to USB Thermal Printer (brand Zebra 3842)


Here is a Class I created to handle the Printing so Far:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Printing;
  4. using System.IO;
  5. using System.IO.Ports;
  6. using System.Collections;
  7. using System.ComponentModel;
  8. using System.Windows.Forms;
  9. using System.Data;
  10. using System.Drawing.Text;
  11. using System.Drawing.Design;
  12. using System.Drawing.Imaging;
  13.  
  14. namespace ShippingStation_csharp
  15. {
  16.     class clsPrinter
  17.     {
  18.         public SerialPort ComPort1 = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
  19.         public SerialPort ComPort2 = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
  20.         ///
  21.  
  22.         [STAThread]
  23.         static void Main(string[] args)
  24.         {
  25.  
  26.         }
  27.  
  28.         public clsPrinter()
  29.         {
  30.  
  31.         }
  32.  
  33.         public void InitShippingPrinter(SerialPort m_pPortCom)
  34.         {
  35.             SendCommandToPrinter(m_pPortCom, "\nN");
  36.             SendCommandToPrinter(m_pPortCom, "D7");
  37.             SendCommandToPrinter(m_pPortCom, "S2");
  38.             SendCommandToPrinter(m_pPortCom, "ZT");
  39.             SendCommandToPrinter(m_pPortCom, "Q1800,36");
  40.             SendCommandToPrinter(m_pPortCom2, "q1200");
  41.         }
  42.  
  43.         public void InitSerialPrinter(SerialPort m_pPortCom)
  44.         {
  45.             SendCommandToPrinter(m_pPortCom, "\nN");
  46.             SendCommandToPrinter(m_pPortCom, "D7");
  47.             SendCommandToPrinter(m_pPortCom, "S1");
  48.             SendCommandToPrinter(m_pPortCom, "ZT");
  49.             SendCommandToPrinter(m_pPortCom, "Q450,36");
  50.             SendCommandToPrinter(m_pPortCom, "q900");
  51.         }
  52.  
  53.         public void PrintToPrinter(PrintPageEventHandler PagetoPrint)
  54.         {
  55.             PrintDocument tPrinter = new PrintDocument();
  56.             tPrinter.PrintPage += new PrintPageEventHandler(PagetoPrint);
  57.             tPrinter.Print();
  58.         }
  59.  
  60.         public void ComPortData(SerialPort port, string cmd)
  61.         {
  62.             SendCommandToPrinter(port, cmd);
  63.         }
  64.  
  65.         private static void SendTextFile(SerialPort port, string FileName)
  66.         {
  67.             port.Write(File.OpenText(FileName).ReadToEnd());
  68.         }
  69.  
  70.         private void SendCommandToPrinter(SerialPort port, string cmd)
  71.         {
  72.             string str = null;
  73.             str=cmd + "\n";
  74.             port.Write(str);
  75.         }
  76.  
  77.         ////////////////////////////////////////////////////////////
  78.         ////////////////////////////////////////////////////////////
  79.  
  80.     }
  81. }
Here is a Procedure I use to write a command using this class

Expand|Select|Wrap|Line Numbers
  1.         private void PrintShippingLabel()
  2.         {
  3.             clsShippingStation ShipStation = new clsShippingStation();
  4.             clsPrinter tPrinter = new clsPrinter();
  5.  
  6.             string strStatus = null;
  7.             string tstring = null;
  8.             string str1 = null;
  9.             //
  10.             int pyadjust = 0;
  11.             int linespacing = 70;
  12.             //
  13.             int pagewidth = 288;
  14.             int pagecenter = pagewidth / 2;
  15.             int leftmargin = 40;        // left margin
  16.             int topmargin = 240;        // left margin
  17.             int px = leftmargin;                // left margin
  18.             int py = topmargin;               // first line location
  19.             //
  20.             string UserID = shplblUserID;
  21.             //
  22.             string SerialNumber = shplblMainIndexSerialNumber;
  23.             string MainItemIndexNumber = shplblMainIndexItemIndexNumber;
  24.             //
  25.             string IndexNumber = shplblIndexNumber;
  26.             string ItemIndexNumber = shplblItemIndexNumber;
  27.             string ItemNumber = shplblItemNumber;
  28.             string Location = shplblLocation;
  29.             string ModelCode = shplblModelCode;
  30.             string Length = shplblLength;
  31.             string AdjSide = shplblAdjSide;
  32.             string Shape = shplblShape;
  33.             string NumberProbes = shplblNumberProbes;
  34.             string UnitsOfMeasure = shplblUnitsOfMeasure;
  35.             //
  36.             string ShipTo1 = shplblShipTo1;
  37.             string ShipTo2 = shplblShipTo2;
  38.             string Attention = shplblAttention;
  39.             string Street1 = shplblStreet1;
  40.             string Street2 = shplblStreet2;
  41.             string City = shplblCity;
  42.             string StateProvince = shplblStateProvince;
  43.             string Country = shplblCountry;
  44.             string ZipCode = shplblZipCode;
  45.             string TagJob = shplblTagJob;
  46.             //
  47.             string ProjectName = shplblProjectName;
  48.             //
  49.             string ModelLabel = shplblModelLabel;
  50.             string FreeArea = Convert.ToString(shplblFreeArea);
  51.             string ItemNumberProbeLetter = shplblItemNumberProbeLetter;
  52.             //
  53.             int EbtronModelName = shplblModelName;
  54.  
  55.             tPrinter.ComPort2.Open();
  56.             tPrinter.InitShippingPrinter(tPrinter.ComPort2);
  57.  
  58.             //Barcode
  59.             if (shplblTriStatLabel == 1)
  60.             {
  61.                 str1 = IndexNumber;
  62.             }
  63.             else if (shplblTriStatLabel == 2)
  64.             {
  65.                 str1 = ItemIndexNumber;
  66.             }
  67.             else
  68.             { 
  69.                 str1 = MainItemIndexNumber;
  70.             }
  71.  
  72.             tstring = "B210,5,0,3,3,7,90,N,\"" + str1 + "\"";
  73.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  74.  
  75.             //Model Number
  76.             str1 = ModelLabel;
  77.             tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  78.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  79.  
  80.             py = py + linespacing;
  81.             //Ref# Item#
  82.             if (shplblTriStatLabel == 1)
  83.             {
  84.                 str1 = "Ref#: " + IndexNumber;
  85.             }
  86.             else
  87.             {
  88.                 str1 = "Ref#: " + IndexNumber + " Item#: " + ItemNumber + ItemNumberProbeLetter;
  89.             }
  90.             tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  91.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  92.  
  93.             py = py + linespacing;
  94.             //Location
  95.             str1 = "Location: " + Location;
  96.             tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  97.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  98.  
  99.             py = py + linespacing;
  100.             //Size
  101.             if (EbtronModelName == 1)
  102.             {
  103.                 float tintLength = float.Parse(Length);
  104.                 Length = tintLength.ToString("0.00");
  105.                 float tintWidth = float.Parse(AdjSide);
  106.                 AdjSide = tintWidth.ToString("0.00");
  107.                 str1 = "Size: " + Length + " " + UnitsOfMeasure + " x " + AdjSide + " " + UnitsOfMeasure;
  108.                 tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  109.                 tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  110.             }
  111.             else if (EbtronModelName == 2)
  112.             {
  113.                 float tintLength = float.Parse(Length);
  114.                 Length = tintLength.ToString("0.00");
  115.                 float tintWidth = float.Parse(AdjSide);
  116.                 AdjSide = tintWidth.ToString("0.00");
  117.                 str1 = "Size: " + Length + " " + UnitsOfMeasure + " x " + AdjSide + " " + UnitsOfMeasure;
  118.                 tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  119.                 tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  120.             }
  121.             else if (EbtronModelName == 3)
  122.             {
  123.                 float tintLength = float.Parse(Length);
  124.                 Length = tintLength.ToString("0.00");
  125.                 str1 = "Size: " + Length;
  126.                 tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  127.                 tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  128.             }
  129.             else if (EbtronModelName == 4)
  130.             {
  131.                 float tintLength = float.Parse(Length);
  132.                 Length = tintLength.ToString("0.00");
  133.                 str1 = "Size: N/A";
  134.                 tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  135.                 tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  136.             }
  137.  
  138.             py = py + linespacing;
  139.             if (EbtronModelName == 1 || EbtronModelName == 2)
  140.             {
  141.                 //Free Area & Shape
  142.                 string tMeasureSQ = null;
  143.                 double tintFreeArea = double.Parse(FreeArea);
  144.  
  145.                 switch (UnitsOfMeasure)
  146.                 {
  147.                     case "mm":
  148.                         tMeasureSQ = " Sq. m ";
  149.                         FreeArea = tintFreeArea.ToString("0.000");
  150.                         break;
  151.                     case "mm.":
  152.                         tMeasureSQ = " Sq. m ";
  153.                         FreeArea = tintFreeArea.ToString("0.000");
  154.                         break;
  155.                     case "in":
  156.                         tMeasureSQ = " Sq. Ft ";
  157.                         FreeArea = tintFreeArea.ToString("0.00");
  158.                         break;
  159.                     case "in.":
  160.                         tMeasureSQ = " Sq. Ft ";
  161.                         FreeArea = tintFreeArea.ToString("0.00");
  162.                         break;
  163.                 }
  164.  
  165.                 str1 = "Free Area: " + FreeArea + tMeasureSQ + " " + Shape;
  166.                 tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  167.                 tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  168.             }
  169.             else if (EbtronModelName == 3)
  170.             {
  171.                 str1 = "Free Area: N/A";
  172.                 tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  173.                 tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  174.             }
  175.             else if (EbtronModelName == 4)
  176.             {
  177.                 str1 = "Free Area: N/A";
  178.                 tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  179.                 tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  180.             }
  181.             py = py + linespacing;
  182.             //Probe Number
  183.             if (EbtronModelName == 1)
  184.             {
  185.                 str1 = MainItemIndexNumber.Substring(MainItemIndexNumber.Length - 1, 1);
  186.                 if (ItemNumberProbeLetter == "A")
  187.                 {
  188.                     str1 = "Probe 1 of " + NumberProbes;
  189.                 }
  190.                 else if (ItemNumberProbeLetter == "B")
  191.                 {
  192.                     str1 = "Probe 2 of " + NumberProbes;
  193.                 }
  194.                 else if (ItemNumberProbeLetter == "C")
  195.                 {
  196.                     str1 = "Probe 3 of " + NumberProbes;
  197.                 }
  198.                 else if (ItemNumberProbeLetter == "D")
  199.                 {
  200.                     str1 = "Probe 4 of " + NumberProbes;
  201.                 }
  202.  
  203.                 //
  204.             }
  205.             else if (EbtronModelName == 2)
  206.             {
  207.                 str1 = "Number of Probes: " + NumberProbes;
  208.             }
  209.             else if (EbtronModelName == 3)
  210.             {
  211.                 str1 = null;
  212.             }
  213.             else if (EbtronModelName == 4)
  214.             {
  215.                 if (shplblTriStatLabel == 1)
  216.                 {
  217.                     str1 = "Number of Tri-Stats: " + ShipStation.GetPrintTriStat();
  218.                 }
  219.                 else if (shplblTriStatLabel == 2)
  220.                 {
  221.                     str1 = ItemNumber + " of " + ShipStation.GetPrintTriStat() + " Tri-Stats";
  222.                 }
  223.             }
  224.             else
  225.             {
  226.                 str1 = null;
  227.             }
  228.             tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  229.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  230.  
  231.             py = py + linespacing + linespacing;
  232.             //Project Name
  233.             str1 = "Project: " + ProjectName;
  234.             tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  235.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  236.  
  237.             py = py + linespacing;
  238.             //Tag
  239.             str1 = "Tag: " + TagJob;
  240.             tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  241.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  242.  
  243.             py = py + linespacing + linespacing;
  244.             pyadjust = py + (linespacing / 3);
  245.             //Ebtron Address
  246.             str1 = "----";
  247.             tstring = "A" + px + "," + py + ",0,3,1,1,N,\"" + str1 + "\"";
  248.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  249.  
  250.             py = py + (linespacing / 2);
  251.             //
  252.             tstring = "LO" + px + "," + py + ",940,4";
  253.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  254.  
  255.             py = py + linespacing;
  256.             //SHIP TO
  257.             str1 = "SHIP TO:";
  258.             tstring = "A" + px + "," + py + ",0,3,2,2,N,\"" + str1 + "\"";
  259.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  260.  
  261.             py = py + linespacing + 25;
  262.             //SHIP TO 1
  263.             str1 = ShipTo1;
  264.             tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  265.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  266.  
  267.             py = py + linespacing;
  268.             //SHIP TO 2
  269.             str1 = ShipTo2;
  270.             tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  271.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  272.  
  273.             py = py + linespacing;
  274.             //SHIP TO Attention
  275.             str1 = Attention;
  276.             tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  277.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  278.  
  279.             py = py + linespacing;
  280.             //SHIP TO Street1
  281.             str1 = Street1;
  282.             tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  283.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  284.  
  285.             py = py + linespacing;
  286.             //SHIP TO Street2
  287.             str1 = Street2;
  288.             tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
  289.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  290.  
  291.             py = py + linespacing;
  292.             //SHIP TO City, State/Province, Country
  293.             str1 = City + ", " + StateProvince + " " + Country;
  294.             if(str1.Length>30)
  295.             {
  296.                 str1 = str1.Substring(0, 30);
  297.             }
  298.             tstring = "A" + px + "," + py + ",0,3,2,2,N,\"" + str1 + "\"";
  299.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  300.  
  301.             py = py + linespacing + 20;
  302.             //SHIP TO ZipCode
  303.             str1 = ZipCode;
  304.             tstring = "A" + px + "," + py + ",0,3,2,2,N,\"" + str1 + "\"";
  305.             tPrinter.ComPortData(tPrinter.ComPort2, tstring);
  306.  
  307.             //Command Printer to Print
  308.             tPrinter.ComPortData(tPrinter.ComPort2, "P1");
  309.  
  310.             tPrinter.ComPort2.Close();
  311.  
  312.             if (ShipStation.GetPrintTriStat() == 0)
  313.             {
  314.                 strStatus = "Shipping Tag Printed";
  315.                 ShipStation.SetHistoryStatus(SerialNumber, strStatus, UserID);
  316.             }
  317.         }
  318.  
Newbie
 
Join Date: Oct 2009
Posts: 8
#3: Oct 1 '09

re: Print to USB Thermal Printer (brand Zebra 3842)


apologize for the long lines of code but i am desperate for help here, thanks!
codegecko's Avatar
Moderator
 
Join Date: May 2007
Location: United Kingdom
Posts: 395
#4: Oct 1 '09

re: Print to USB Thermal Printer (brand Zebra 3842)


Hey ThaSaltyDawg,

Looks like an extensive problem - I have investigated printing to thermal printers previously but never got round to obtaining hardware on which to test with.
I will ask around the experts and mods in C# to see if they have any experience cause it seems like you need some proper one-on-one debugging help.
In the meantime I have asked for your code to be removed from the post as per our Posting Guidelines (but keep a ZIP copy to hand just in case one of us can help you out).

codegecko
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#5: Oct 1 '09

re: Print to USB Thermal Printer (brand Zebra 3842)


Quote:

Originally Posted by CodeGeko

In the meantime I have asked for your code to be removed from the post as per our Posting Guidelines

I'm not sure what part of the guidelines would necesitate the code removal.

It has also come to my attention of just how hard it is to find our own posting guidelines. The only way to it is via the small 'help' link in the header. I might suggest it be more prominent on the "ask a question" page so that new posters are encouraged to read them before posting.
Newbie
 
Join Date: Oct 2009
Posts: 8
#6: Oct 1 '09

re: Print to USB Thermal Printer (brand Zebra 3842)


Quote:

Originally Posted by codegecko View Post

Hey ThaSaltyDawg,

Looks like an extensive problem - I have investigated printing to thermal printers previously but never got round to obtaining hardware on which to test with.
I will ask around the experts and mods in C# to see if they have any experience cause it seems like you need some proper one-on-one debugging help.
In the meantime I have asked for your code to be removed from the post as per our Posting Guidelines (but keep a ZIP copy to hand just in case one of us can help you out).

codegecko

Thanks for your quick response. First time on the site and I enjoy it already because I hate posting on sites and a question not just goes unanswered but viewed for days. I was happy to see you respond to atleast tell me that it was being looked. I am a member at another paid site that I will remain nameless, "Ex...." and have this same question unviewed.

And I apologize if for breaking the posting guidelines just thought the code would be relevant.

Thanks.
Newbie
 
Join Date: Oct 2009
Posts: 8
#7: Oct 2 '09

re: Print to USB Thermal Printer (brand Zebra 3842)


If can get one thing answered i think I may be able to start form there.

For my serial ports I have:

Expand|Select|Wrap|Line Numbers
  1.         public SerialPort ComPort1 = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
  2.         public SerialPort ComPort2 = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
  3.  
Is there an equivalent to this for the USB Port?
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#8: Oct 2 '09

re: Print to USB Thermal Printer (brand Zebra 3842)


Not really.

We work with receipt printers as well. Mostly the Epson TM88-TM90 series. Oddly the printer can come parallel or USB but does not ship with the USB drivers. Once you download the USB drivers it becomes just another printer visible to Windows and you print to it like an other.

Is your Zebra visible as a Windows printer?

I assume you've been through the programmers manual from the Zebra website?? Did it offer any help on your issues with sending ELP commands?
Newbie
 
Join Date: Oct 2009
Posts: 8
#9: Oct 2 '09

re: Print to USB Thermal Printer (brand Zebra 3842)


Thanks for the response,
Yes I can install the printers by disc but I do not get the same results when sending the ELP commands. It prints as plain text. That another thing I am looking into to. They had issues installing both of them on the same computer because both printers are the same. They both show up as separate plug and play devices but they do not show up separate attached computers. I guessing this will force me to print directly.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#10: Oct 2 '09

re: Print to USB Thermal Printer (brand Zebra 3842)


Quote:
They both show up as separate plug and play devices but they do not show up separate attached computers.
Are you saying that if you connect two of the same model printer to one computer, Windows does not see/list two printers? Zebra3842 Zebra3842(1)
Newbie
 
Join Date: Oct 2009
Posts: 8
#11: Oct 2 '09

re: Print to USB Thermal Printer (brand Zebra 3842)


Quote:

Originally Posted by tlhintoq View Post

Are you saying that if you connect two of the same model printer to one computer, Windows does not see/list two printers? Zebra3842 Zebra3842(1)

That's what I was recently told, but I am not sure what they did. Not sure if the admin understand what I am trying to do. I know that in the device manager it shows up but according to the admin when she try to install it by using the add printer in windows she can't. Though I am not sure if that is the way I need to do it anyway. I have one installed on my own PC (that I code on) so that I can test it and can't get it to print the way I need it. It always come out as plain text.

The New USB printers also have a serial port connection so I have just added them to the system using COM1 and COM2. But I would still like to know how to use the USB because we have some other printers that do not have the Serial Port Options.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#12: Oct 2 '09

re: Print to USB Thermal Printer (brand Zebra 3842)


It sure sounds like something is screwy in the Windows driver. It won't accept the same commands as in serial... It won't let two of the same type be installed on one PC...

Is there a difference in the ELP and ELP-2 commands or protocol? Maybe the new printer only speaks the newer language? It wouldn't be the first piece of hardware that thru out backwards compatibility for no good reason
Newbie
 
Join Date: Oct 2009
Posts: 8
#13: Oct 2 '09

re: Print to USB Thermal Printer (brand Zebra 3842)


Quote:

Originally Posted by tlhintoq View Post

It sure sounds like something is screwy in the Windows driver. It won't accept the same commands as in serial... It won't let two of the same type be installed on one PC...

Is there a difference in the ELP and ELP-2 commands or protocol? Maybe the new printer only speaks the newer language? It wouldn't be the first piece of hardware that thru out backwards compatibility for no good reason

I will check on that, thanks
Reply

Tags
(c#) c sharp, com port, elp, usb, zebra thermal printer