Print to USB Thermal Printer (brand Zebra 3842) | Newbie | | Join Date: Oct 2009
Posts: 8
| | |
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
| | | re: Print to USB Thermal Printer (brand Zebra 3842)
Here is a Class I created to handle the Printing so Far: -
using System;
-
using System.Drawing;
-
using System.Drawing.Printing;
-
using System.IO;
-
using System.IO.Ports;
-
using System.Collections;
-
using System.ComponentModel;
-
using System.Windows.Forms;
-
using System.Data;
-
using System.Drawing.Text;
-
using System.Drawing.Design;
-
using System.Drawing.Imaging;
-
-
namespace ShippingStation_csharp
-
{
-
class clsPrinter
-
{
-
public SerialPort ComPort1 = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
-
public SerialPort ComPort2 = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
-
///
-
-
[STAThread]
-
static void Main(string[] args)
-
{
-
-
}
-
-
public clsPrinter()
-
{
-
-
}
-
-
public void InitShippingPrinter(SerialPort m_pPortCom)
-
{
-
SendCommandToPrinter(m_pPortCom, "\nN");
-
SendCommandToPrinter(m_pPortCom, "D7");
-
SendCommandToPrinter(m_pPortCom, "S2");
-
SendCommandToPrinter(m_pPortCom, "ZT");
-
SendCommandToPrinter(m_pPortCom, "Q1800,36");
-
SendCommandToPrinter(m_pPortCom2, "q1200");
-
}
-
-
public void InitSerialPrinter(SerialPort m_pPortCom)
-
{
-
SendCommandToPrinter(m_pPortCom, "\nN");
-
SendCommandToPrinter(m_pPortCom, "D7");
-
SendCommandToPrinter(m_pPortCom, "S1");
-
SendCommandToPrinter(m_pPortCom, "ZT");
-
SendCommandToPrinter(m_pPortCom, "Q450,36");
-
SendCommandToPrinter(m_pPortCom, "q900");
-
}
-
-
public void PrintToPrinter(PrintPageEventHandler PagetoPrint)
-
{
-
PrintDocument tPrinter = new PrintDocument();
-
tPrinter.PrintPage += new PrintPageEventHandler(PagetoPrint);
-
tPrinter.Print();
-
}
-
-
public void ComPortData(SerialPort port, string cmd)
-
{
-
SendCommandToPrinter(port, cmd);
-
}
-
-
private static void SendTextFile(SerialPort port, string FileName)
-
{
-
port.Write(File.OpenText(FileName).ReadToEnd());
-
}
-
-
private void SendCommandToPrinter(SerialPort port, string cmd)
-
{
-
string str = null;
-
str=cmd + "\n";
-
port.Write(str);
-
}
-
-
////////////////////////////////////////////////////////////
-
////////////////////////////////////////////////////////////
-
-
}
-
}
Here is a Procedure I use to write a command using this class - private void PrintShippingLabel()
-
{
-
clsShippingStation ShipStation = new clsShippingStation();
-
clsPrinter tPrinter = new clsPrinter();
-
-
string strStatus = null;
-
string tstring = null;
-
string str1 = null;
-
//
-
int pyadjust = 0;
-
int linespacing = 70;
-
//
-
int pagewidth = 288;
-
int pagecenter = pagewidth / 2;
-
int leftmargin = 40; // left margin
-
int topmargin = 240; // left margin
-
int px = leftmargin; // left margin
-
int py = topmargin; // first line location
-
//
-
string UserID = shplblUserID;
-
//
-
string SerialNumber = shplblMainIndexSerialNumber;
-
string MainItemIndexNumber = shplblMainIndexItemIndexNumber;
-
//
-
string IndexNumber = shplblIndexNumber;
-
string ItemIndexNumber = shplblItemIndexNumber;
-
string ItemNumber = shplblItemNumber;
-
string Location = shplblLocation;
-
string ModelCode = shplblModelCode;
-
string Length = shplblLength;
-
string AdjSide = shplblAdjSide;
-
string Shape = shplblShape;
-
string NumberProbes = shplblNumberProbes;
-
string UnitsOfMeasure = shplblUnitsOfMeasure;
-
//
-
string ShipTo1 = shplblShipTo1;
-
string ShipTo2 = shplblShipTo2;
-
string Attention = shplblAttention;
-
string Street1 = shplblStreet1;
-
string Street2 = shplblStreet2;
-
string City = shplblCity;
-
string StateProvince = shplblStateProvince;
-
string Country = shplblCountry;
-
string ZipCode = shplblZipCode;
-
string TagJob = shplblTagJob;
-
//
-
string ProjectName = shplblProjectName;
-
//
-
string ModelLabel = shplblModelLabel;
-
string FreeArea = Convert.ToString(shplblFreeArea);
-
string ItemNumberProbeLetter = shplblItemNumberProbeLetter;
-
//
-
int EbtronModelName = shplblModelName;
-
-
tPrinter.ComPort2.Open();
-
tPrinter.InitShippingPrinter(tPrinter.ComPort2);
-
-
//Barcode
-
if (shplblTriStatLabel == 1)
-
{
-
str1 = IndexNumber;
-
}
-
else if (shplblTriStatLabel == 2)
-
{
-
str1 = ItemIndexNumber;
-
}
-
else
-
{
-
str1 = MainItemIndexNumber;
-
}
-
-
tstring = "B210,5,0,3,3,7,90,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
//Model Number
-
str1 = ModelLabel;
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing;
-
//Ref# Item#
-
if (shplblTriStatLabel == 1)
-
{
-
str1 = "Ref#: " + IndexNumber;
-
}
-
else
-
{
-
str1 = "Ref#: " + IndexNumber + " Item#: " + ItemNumber + ItemNumberProbeLetter;
-
}
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing;
-
//Location
-
str1 = "Location: " + Location;
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing;
-
//Size
-
if (EbtronModelName == 1)
-
{
-
float tintLength = float.Parse(Length);
-
Length = tintLength.ToString("0.00");
-
float tintWidth = float.Parse(AdjSide);
-
AdjSide = tintWidth.ToString("0.00");
-
str1 = "Size: " + Length + " " + UnitsOfMeasure + " x " + AdjSide + " " + UnitsOfMeasure;
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
}
-
else if (EbtronModelName == 2)
-
{
-
float tintLength = float.Parse(Length);
-
Length = tintLength.ToString("0.00");
-
float tintWidth = float.Parse(AdjSide);
-
AdjSide = tintWidth.ToString("0.00");
-
str1 = "Size: " + Length + " " + UnitsOfMeasure + " x " + AdjSide + " " + UnitsOfMeasure;
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
}
-
else if (EbtronModelName == 3)
-
{
-
float tintLength = float.Parse(Length);
-
Length = tintLength.ToString("0.00");
-
str1 = "Size: " + Length;
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
}
-
else if (EbtronModelName == 4)
-
{
-
float tintLength = float.Parse(Length);
-
Length = tintLength.ToString("0.00");
-
str1 = "Size: N/A";
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
}
-
-
py = py + linespacing;
-
if (EbtronModelName == 1 || EbtronModelName == 2)
-
{
-
//Free Area & Shape
-
string tMeasureSQ = null;
-
double tintFreeArea = double.Parse(FreeArea);
-
-
switch (UnitsOfMeasure)
-
{
-
case "mm":
-
tMeasureSQ = " Sq. m ";
-
FreeArea = tintFreeArea.ToString("0.000");
-
break;
-
case "mm.":
-
tMeasureSQ = " Sq. m ";
-
FreeArea = tintFreeArea.ToString("0.000");
-
break;
-
case "in":
-
tMeasureSQ = " Sq. Ft ";
-
FreeArea = tintFreeArea.ToString("0.00");
-
break;
-
case "in.":
-
tMeasureSQ = " Sq. Ft ";
-
FreeArea = tintFreeArea.ToString("0.00");
-
break;
-
}
-
-
str1 = "Free Area: " + FreeArea + tMeasureSQ + " " + Shape;
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
}
-
else if (EbtronModelName == 3)
-
{
-
str1 = "Free Area: N/A";
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
}
-
else if (EbtronModelName == 4)
-
{
-
str1 = "Free Area: N/A";
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
}
-
py = py + linespacing;
-
//Probe Number
-
if (EbtronModelName == 1)
-
{
-
str1 = MainItemIndexNumber.Substring(MainItemIndexNumber.Length - 1, 1);
-
if (ItemNumberProbeLetter == "A")
-
{
-
str1 = "Probe 1 of " + NumberProbes;
-
}
-
else if (ItemNumberProbeLetter == "B")
-
{
-
str1 = "Probe 2 of " + NumberProbes;
-
}
-
else if (ItemNumberProbeLetter == "C")
-
{
-
str1 = "Probe 3 of " + NumberProbes;
-
}
-
else if (ItemNumberProbeLetter == "D")
-
{
-
str1 = "Probe 4 of " + NumberProbes;
-
}
-
-
//
-
}
-
else if (EbtronModelName == 2)
-
{
-
str1 = "Number of Probes: " + NumberProbes;
-
}
-
else if (EbtronModelName == 3)
-
{
-
str1 = null;
-
}
-
else if (EbtronModelName == 4)
-
{
-
if (shplblTriStatLabel == 1)
-
{
-
str1 = "Number of Tri-Stats: " + ShipStation.GetPrintTriStat();
-
}
-
else if (shplblTriStatLabel == 2)
-
{
-
str1 = ItemNumber + " of " + ShipStation.GetPrintTriStat() + " Tri-Stats";
-
}
-
}
-
else
-
{
-
str1 = null;
-
}
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing + linespacing;
-
//Project Name
-
str1 = "Project: " + ProjectName;
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing;
-
//Tag
-
str1 = "Tag: " + TagJob;
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing + linespacing;
-
pyadjust = py + (linespacing / 3);
-
//Ebtron Address
-
str1 = "----";
-
tstring = "A" + px + "," + py + ",0,3,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + (linespacing / 2);
-
//
-
tstring = "LO" + px + "," + py + ",940,4";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing;
-
//SHIP TO
-
str1 = "SHIP TO:";
-
tstring = "A" + px + "," + py + ",0,3,2,2,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing + 25;
-
//SHIP TO 1
-
str1 = ShipTo1;
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing;
-
//SHIP TO 2
-
str1 = ShipTo2;
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing;
-
//SHIP TO Attention
-
str1 = Attention;
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing;
-
//SHIP TO Street1
-
str1 = Street1;
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing;
-
//SHIP TO Street2
-
str1 = Street2;
-
tstring = "A" + px + "," + py + ",0,4,1,1,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing;
-
//SHIP TO City, State/Province, Country
-
str1 = City + ", " + StateProvince + " " + Country;
-
if(str1.Length>30)
-
{
-
str1 = str1.Substring(0, 30);
-
}
-
tstring = "A" + px + "," + py + ",0,3,2,2,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
py = py + linespacing + 20;
-
//SHIP TO ZipCode
-
str1 = ZipCode;
-
tstring = "A" + px + "," + py + ",0,3,2,2,N,\"" + str1 + "\"";
-
tPrinter.ComPortData(tPrinter.ComPort2, tstring);
-
-
//Command Printer to Print
-
tPrinter.ComPortData(tPrinter.ComPort2, "P1");
-
-
tPrinter.ComPort2.Close();
-
-
if (ShipStation.GetPrintTriStat() == 0)
-
{
-
strStatus = "Shipping Tag Printed";
-
ShipStation.SetHistoryStatus(SerialNumber, strStatus, UserID);
-
}
-
}
-
| | Newbie | | Join Date: Oct 2009
Posts: 8
| | | re: Print to USB Thermal Printer (brand Zebra 3842)
apologize for the long lines of code but i am desperate for help here, thanks!
|  | Moderator | | Join Date: May 2007 Location: United Kingdom
Posts: 395
| | | 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
|  | Moderator | | Join Date: Mar 2008 Location: Arizona, USA
Posts: 1,745
| | | 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
| | | re: Print to USB Thermal Printer (brand Zebra 3842) Quote:
Originally Posted by codegecko 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
| | | 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: -
public SerialPort ComPort1 = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
-
public SerialPort ComPort2 = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
-
Is there an equivalent to this for the USB Port?
|  | Moderator | | Join Date: Mar 2008 Location: Arizona, USA
Posts: 1,745
| | | 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
| | | 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.
|  | Moderator | | Join Date: Mar 2008 Location: Arizona, USA
Posts: 1,745
| | | 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
| | | re: Print to USB Thermal Printer (brand Zebra 3842) Quote:
Originally Posted by tlhintoq 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.
|  | Moderator | | Join Date: Mar 2008 Location: Arizona, USA
Posts: 1,745
| | | 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
| | | re: Print to USB Thermal Printer (brand Zebra 3842) Quote:
Originally Posted by tlhintoq 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
|  | Similar C# / C Sharp bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,272 network members.
|