473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Printer language & sending commands

Hello,

I can't find a way to send printer specific language codes to printer.

Part of my code :
String sString = "B50,0,0,3,1,2,50,B," + "12345678901234567890";
Font fFont = new Font("Arial", 16);
SolidBrush bBrush = new SolidBrush(Color.Black);
PointF pPoint = new PointF(150.0F, 150.0F);
ev.Graphics.DrawString(sString, fFont, bBrush, pPoint);

First part of the sString should tel my printer to print a barcode. But all
I get is the whole sString contens printed out as-it-is.
I assume the problem is that I send graphical representation of sString to
printer and not a sequence of characters.
Should I try Streams or ......?????

Printer is Eltron TLP2046 BarCode Printer

thx,
Damijan the Puzzled
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
Nov 16 '05 #1
3 29400
Hi !

You need to send the data raw to the printer, otherwise Windows will eat the control codes alive.

First of all read this article:
HOW TO: Send Raw Data to a Printer by Using Visual C# .NET
http://support.microsoft.com/?kbid=322091

Copy the article code into a classfile.
Then you'll have to do something like the code below. (sorry about the formating )

(Note: The SendDocTo Printer is my addon to the article, where I have added a few methods so I could
pass a memorystream, and stream from a embedded resource file etc.
I have a lot of experience with Eltron Orion/2443 and Zebra 2443/2444 and DataMax label printers,
but almost everything I've done is done in Delphi. I've jsut started porting this stuff to C#
myself. Anyway, if you're stucked - contact me and I can see if I can help you - no garantee though
:)
<snip>
private void btnPrint2_Click(object sender, System.EventArgs e)
{
PrintDialog pd = new PrintDialog();
pd.PrinterSettings = new PrinterSettings();
if (DialogResult.OK == pd.ShowDialog(this))
{
MemoryStream memStrm = new MemoryStream();
StreamWriter sw = new StreamWriter(memStrm);
sw.WriteLine("\x02L");
sw.WriteLine("H07");
sw.WriteLine("D11");
sw.WriteLine("19110080200002510K Ny linje");
sw.WriteLine("19110080100002510K OHM 1/4 WATT");
sw.Flush();
sw.WriteLine("1a6210000000050590PCS");
sw.WriteLine("E");
sw.WriteLine("");
sw.Flush();

memStrm.Position = 0;
LabelPrint.SendDocToPrinter(pd.PrinterSettings.Pri nterName,memStrm);
sw.Close();

</snip>

<snip2>
private void btn3_Click(object sender, System.EventArgs e)
{
PrintDialog pd = new PrintDialog();
pd.PrinterSettings = new PrinterSettings();
if (DialogResult.OK == pd.ShowDialog(this))
{
string p = pd.PrinterSettings.PrinterName;
LabelPrint.SendStringToPrinter(p,"\x02L"); // ^BL
LabelPrint.SendStringToPrinter(p,"H07");
LabelPrint.SendStringToPrinter(p,"D11");
LabelPrint.SendStringToPrinter(p,"1911008010000251 0K OHM 1/4 WATT");
LabelPrint.SendStringToPrinter(p,"1a62100000000505 90PCS");
LabelPrint.SendStringToPrinter(p,"E");
LabelPrint.SendStringToPrinter(p,"");
}
}
</snip2>
On Tue, 6 Jul 2004 14:38:31 +0200, "Vlki" <damijan.gradiser_at_neckermann_si> wrote:
Hello,

I can't find a way to send printer specific language codes to printer.

Part of my code :
String sString = "B50,0,0,3,1,2,50,B," + "12345678901234567890";
Font fFont = new Font("Arial", 16);
SolidBrush bBrush = new SolidBrush(Color.Black);
PointF pPoint = new PointF(150.0F, 150.0F);
ev.Graphics.DrawString(sString, fFont, bBrush, pPoint);

First part of the sString should tel my printer to print a barcode. But all
I get is the whole sString contens printed out as-it-is.
I assume the problem is that I send graphical representation of sString to
printer and not a sequence of characters.
Should I try Streams or ......?????

Printer is Eltron TLP2046 BarCode Printer

thx,
Damijan the Puzzled


Best wishes
Kai Bohli
ka***********@online.no
Norway
Nov 16 '05 #2
"Kai Bohli" <ka****@online.nospam> ha scritto nel messaggio
news:71********************************@4ax.com...
Hi !

You need to send the data raw to the printer, otherwise Windows will eat the control codes alive.
First of all read this article:
HOW TO: Send Raw Data to a Printer by Using Visual C# .NET
http://support.microsoft.com/?kbid=322091

Copy the article code into a classfile.
Then you'll have to do something like the code below. (sorry about the formating )
(Note: The SendDocTo Printer is my addon to the article, where I have added a few methods so I could pass a memorystream, and stream from a embedded resource file etc.
I have a lot of experience with Eltron Orion/2443 and Zebra 2443/2444 and DataMax label printers, but almost everything I've done is done in Delphi. I've jsut started porting this stuff to C# myself. Anyway, if you're stucked - contact me and I can see if I can help you - no garantee though :)


Hi,
I'm trying to print on an Eltron TLP2247. Using the example that you
suggest, nothing appen on the printer.
How can i sent EPL command do the printer?

Thnks
EMA
Nov 16 '05 #3
Hi Emanuele !

Sorry for the late answer. The sample that I posted was for a Datamax printer. So in Eltron/Zebra,
it should go something like this:

char sn = '"';
MemoryStream memStrm = new MemoryStream();
StreamWriter sw = new StreamWriter(memStrm);
sw.WriteLine("\n"); // new line to start command structure
sw.WriteLine("N"); // clear image memory from last printed label
sw.WriteLine("X0,0,4,752,584"); // draw a box
sw.WriteLine("LO0,144,752,4"); // draw a line
sw.WriteLine("A40,400,1,1,1,1,N," + sn + "Made in Norway" + sn);
sw.WriteLine("B280,440,0,1,2,3,96,B," + sn + "S 000001" + sn); // write a barcode
sw.Flush();
sw.WriteLine("P1"); // print 1 label
sw.WriteLine(""); // empty line
sw.Flush();

memStrm.Position = 0;
LabelPrint.SendDocToPrinter(pd.PrinterSettings.Pri nterName,memStrm);
sw.Close();

The sample above is simple, but it's all I had time to do now. Not that you should add a method to
the article file called SendDocToPrinter. I've posted the code below:
<code for the SendDocToPrinter function>
public static bool SendDocToPrinter( string szPrinterName, MemoryStream ms)
{
// Open the file.
//FileStream fs = new FileStream(szFileName, FileMode.Open);
// Create a BinaryReader on the file.
BinaryReader br = new BinaryReader(ms);
// Dim an array of bytes big enough to hold the file's contents.
Byte []bytes = new Byte[ms.Length];
bool bSuccess = false;
// Your unmanaged pointer.
IntPtr pUnmanagedBytes = new IntPtr(0);
int nLength;

nLength = Convert.ToInt32(ms.Length);
// Read the contents of the file into the array.
bytes = br.ReadBytes( nLength );
// Allocate some unmanaged memory for those bytes.
pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
// Copy the managed byte array into the unmanaged array.
Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
// Send the unmanaged bytes to the printer.
bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, nLength);
// Free the unmanaged memory that you allocated earlier.
Marshal.FreeCoTaskMem(pUnmanagedBytes);
return bSuccess;
}
</code for the SendDocToPrinter function>

I'm trying to print on an Eltron TLP2247. Using the example that you
suggest, nothing appen on the printer.
How can i sent EPL command do the printer?

Thnks
EMA

Best wishes
Kai Bohli
ka***********@online.no
Norway
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nis Sarup | last post by:
A customer of mine wants to make a newsletter for their website. The newsletter should be HTML with images and sent to a database of her subscribers. They would like a script where they can easily...
1
by: Zaidan | last post by:
I am running Excel2000 under WIN98 2nd edition, and I am writing a VBA code (I will consider using javascript if I have to) that does the following, at the user command: 1- Start MS Explorer and...
0
by: masterjuan | last post by:
Networks Hacking (hack C:/ drives, severs...)and security holes all on my website & hacking commands and I explain ways of erasing your tracks so you dont get caught doing "bad" things... What do...
1
by: trs204 | last post by:
For moving the files, planning to use like this..... find / -iname "*.txt" -type f -exec /bin/mv {} /mnt/bckup \; I want to do compressing before moving the files. Please suggest. I am not sure,...
2
by: hari | last post by:
Hi all, I need to automate printer command testing, prinetr supports parallel/ serial/USB.How can i send the commands from python to printer. I have got pyparallel, as am new to python, no...
0
by: Astan Chee | last post by:
Hi, Im trying to implement the logic from http://www.hypothetic.org/docs/msn/general/http_connections.php to a simple python code using urllib2 and some parts of urllib. Im behind a http proxy...
0
by: rhyspatto | last post by:
Hi, I have a problem but cannot figure out a good solution to it. I am trying to create a form that creates a bunch of panels during runtime, and I want to be able to send commands (such as false...
0
by: Kineta | last post by:
Hello all, I am attempting to send commands to the firmware on my PIC18F4550 (usb port) microcontroller using Pyserial. If I open Hyperterminal, I can send the following commands and it works...
0
by: mctadas | last post by:
Hello, for some time I'm struggling with Argox printer trying to print Cyrillic characters and some other non-ASCII characers. I believe this question is related to this one about sending...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.