views:

435

answers:

4

I'm trying to print out raw ascii data to a thermal printer. I do this by using this code example: http://support.microsoft.com/kb/322091 but my printer prints always only one character and this not until I press the form feed button. If I print something with notepad the printer will do a form feed automatically but without printing any text.

The printer is connected via usb over a lpt2usb adapter and Windows 7 uses the "Generic -> Generic / Text Only" driver.

Anyone knows what is going wrong? How is it possible to print some words and do some form feeds? Are there some control characters I have to send? And if yes: How do I send them?

Edit 14.04.2010 21:51

My code (C#) looks like this:

PrinterSettings s =  new PrinterSettings();
s.PrinterName = "Generic / Text Only";

RawPrinterHelper.SendStringToPrinter(s.PrinterName, "Test");

This code will return a "T" after I pressed the form feed button (This litte black button here: swissmania.ch/images/935-151.jpg - sorry, not enough reputation for two hyperlinks)

Edit 15.04.2010 16:56

I'm using now the code form here: c-sharpcorner.com/UploadFile/johnodonell/PrintingDirectlytothePrinter11222005001207AM/PrintingDirectlytothePrinter.aspx

I modified it a bit that I can use the following code:

byte[] toSend;
// 10 = line feed
// 13 carriage return/form feed
toSend = new byte[1] { 13 };
PrintDirect.WritePrinter(lhPrinter, toSend, toSend.Length, ref pcWritten);

Running this code has the same effekt like pressing the form feed button, it works fine!

But code like this still does not work:

byte[] toSend;
// 10 = line feed
// 13 carriage return/form feed
toSend = new byte[2] { 66, 67 };
PrintDirect.WritePrinter(lhPrinter, toSend, toSend.Length, ref pcWritten);

This will print out just a "B" but I expect "BC" and after running any code I have to reconnect the USB cable to make it work agian. Any ideas?

A: 

Can you provide us with a sample code??

HiperiX
I updated my question and inserted my code
Blauesocke
+2  A: 

Okay, the reason for all that stuff is just the fact that I use an adapter because my computer does not has an old lpt port. I copied my application to an old computer running windows xp and everything works fine.

Now I have to hope that some other lpt2usb adaters I bought now do their work correctly.

Edit 20.04.2010

With another lpt2usb adapter everything works fine now. If anyone is intersted in all the code I am using now, please contact me or comment here.

Blauesocke
Ill love to see How You did print to LPT using C#, Thanks in advance
adopilot
+1  A: 

Hi,

I have developed application in C#.net. I am new to it. I also want to print my report just like a receipt through thermal printer. Can you provide me sample code. i'll be thankful to you.

Everything you need is the code from my post and the classes here: http://support.microsoft.com/kb/322091 (So far, this worked for me)If you want layout things like a receipt you have to work with tabs and spaces.
Blauesocke
A: 

Hello,

I already got that code & site. I just wanted to know, which Thermal printer you are using or have tested with. B'coz I learned that differnt companies have differnt style of giving text to print. I want to know this code works with which printer manufacturer. I don't have thermal printer so have to go outside in search of someone who uses it and try the sample app at their PC. I have to develop for Epson printers. Also how do you set your data based on Printer Paper Type & Size.

It would be great if you can help me know something more.

Thanks

If You inserted in Star Pos Printers here is my sample http://stackoverflow.com/questions/3108223/how-to-encode-strings-like-edit-does-in-c
adopilot