I'm trying to cut the paper pragmatically by sending paper cut command to the printer (Epson TM U220 with USB port). I used the printer with Generic/Text Only Driver and Epson printer port which I found after installing Epson advanced printer driver. Printer command code is (GS V m), where m = 0,1,48 or 49 which I found on the device manual. I would like to know how to send these command to printer by StringWriter. I use Generic/Text Only printer because it's much faster than using Epson driver.
I'm really new to C# windows and please anyone kindly provide me some lines of code to achieve this. I've been surfing the web for several days and still not found the answer yet. I think I need to send printer command as byte but I don't know how to do :(
ESC/POS usage Most modern printers support ESC/POS. All commands start with the ESC character (ASCII 27, HEX 1B) or GS (ASCII 29, HEX 1D), followed by another character that specifies the command. Normal text is simply sent to the printer, separated by line breaks.
✧ ESC/POS printing command is a simplified version of ESC printing control commands. ESC/POS instruction set is a major practice applied in voucher printing. ✧ The notable characteristic of this command is most of the instructions are a group of codes beginning with ESC control characters.
For those printing with netcat
(really easy way to print something without installing any driver), to cut the paper:
echo -e "\x1B@\x1DV1" | nc printer.ip 9100
Same string like in the c# version, but mapped to hex: \x1B = ESC
and \x1D = GS
.
Thank you very much Hans. Now I can send Paper cut command by using Microsoft RawPrinterHelper class. I've been seeking this solution for six days. Here is what I've done.
string GS = Convert.ToString((char)29);
string ESC = Convert.ToString((char)27);
string COMMAND = "";
COMMAND = ESC + "@";
COMMAND += GS + "V" + (char)1;
PrintDialog pd = new PrintDialog();
pd.PrinterSettings = new PrinterSettings();
if (DialogResult.OK == pd.ShowDialog(this))
{
RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, COMMAND);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With