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
12 23121
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);
-
}
-
}
-
apologize for the long lines of code but i am desperate for help here, thanks!
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
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.
@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.
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?
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?
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.
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)
@tlhintoq
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Pete Petersen |
last post by:
We are trying to send the results page to a Zebra LP2844 Printer with 4" x 2"
Thermal Transfer Label loaded on the network. The share is \\server01\ups
and it is installed on the Web Server that...
|
by: Matt |
last post by:
Has anyone had the occasion to write an app to print to a Zebra barcode
printer? We have a Z4M I am working with. I have it working fine, in
sending ZPL commands to a text file then dumping it to...
|
by: Paolo matador |
last post by:
Hi All, i have a little problem with my web application.
I need to print a web page, shrinked on a thermal printer that not
supporting A4 format.
The printer is this:...
|
by: peng |
last post by:
Hi,
I am development a project using C#.Net. Inside application, it needs to
print labels on different Zebra label printers on the network. I used a shell
script, but it only worked on the...
|
by: ATJaguarX |
last post by:
I have a Zebra S500 and multiple S600 label printers.
http://www.zebra.com/id/zebra/na/en/index/products/printers/industrial_commercial/s600.html
They are currently being used in our legacy...
|
by: Tony Girgenti |
last post by:
Hello.
Developing a Windows Form program in VS.NET VB, .NET Framework 1.1.4322 on a
windows XP Pro, SP2.
Before printing a document, i want to set the font to a font that is only
available...
|
by: Flying Kite |
last post by:
Hi All,
I want to know how to print chinese characters on Zebra Printer, following code working fine with English string, but it's not working for Chinese string. It shows ASCII characters instead...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |