Giter Club home page Giter Club logo

esc-pos-.net's Introduction

ESCPOS.NET - Easy to use, Cross-Platform, Fast and Efficient.


GitHub closed issues Nuget GitHub contributors

ESCPOS.NET is a super easy to use library that supports the most common functionality of the ESC/POS standard by Epson. It is highly compatible, and runs on full framework .NET as well as .NET Core.

It works with Serial, USB, Ethernet, and WiFi printers, and works great on Windows, Linux and OSX.

This library is used for thermal receipt printers, line displays, cash drawers, and more!

ESC/POS is a binary protocol that's a type of "raw" text, which means you do not need drivers to use it.

This library encompasses helper functions that assist in creating the binary command stream that is needed to control this hardware, as well as the underlying communications that are needed to interface with the hardware.

This means that Bluetooth, WiFi, Ethernet, USB, and Serial printers are all usable with just this software library and nothing else.

Get Started

Step 1: Create a Printer object

// Ethernet or WiFi (This uses an Immediate Printer, no live paper status events, but is easier to use)
var hostnameOrIp = "192.168.1.50";
var port = 9100;
var printer = new ImmediateNetworkPrinter(new ImmediateNetworkPrinterSettings() { ConnectionString = $"{hostnameOrIp}:{port}", PrinterName = "TestPrinter" });

// USB, Bluetooth, or Serial
var printer = new SerialPrinter(portName: "COM5", baudRate: 115200);

// Linux output to USB / Serial file
var printer = new FilePrinter(filePath: "/dev/usb/lp0");

// Samba
var printer = new SambaPrinter(tempFileBasePath: @"C:\Temp", filePath: "\\computer\printer");

Step 1a (optional): Monitor for Events - out of paper, cover open...

// Define a callback method.
static void StatusChanged(object sender, EventArgs ps)
{
    var status = (PrinterStatusEventArgs)ps;
    Console.WriteLine($"Status: {status.IsPrinterOnline}");
    Console.WriteLine($"Has Paper? {status.IsPaperOut}");
    Console.WriteLine($"Paper Running Low? {status.IsPaperLow}");
    Console.WriteLine($"Cash Drawer Open? {status.IsCashDrawerOpen}");
    Console.WriteLine($"Cover Open? {status.IsCoverOpen}");
}

... 

// In your program, register event handler to call the method when printer status changes:
printer.StatusChanged += StatusChanged;

// and start monitoring for changes.
printer.StartMonitoring();

Step 2: Write a receipt to the printer

var e = new EPSON();
printer.Write( // or, if using and immediate printer, use await printer.WriteAsync
  ByteSplicer.Combine(
    e.CenterAlign(),
    e.PrintImage(File.ReadAllBytes("images/pd-logo-300.png"), true),
    e.PrintLine(),
    e.SetBarcodeHeightInDots(360),
    e.SetBarWidth(BarWidth.Default),
    e.SetBarLabelPosition(BarLabelPrintPosition.None),
    e.PrintBarcode(BarcodeType.ITF, "0123456789"),
    e.PrintLine(),
    e.PrintLine("B&H PHOTO & VIDEO"),
    e.PrintLine("420 NINTH AVE."),
    e.PrintLine("NEW YORK, NY 10001"),
    e.PrintLine("(212) 502-6380 - (800)947-9975"),
    e.SetStyles(PrintStyle.Underline),
    e.PrintLine("www.bhphotovideo.com"),
    e.SetStyles(PrintStyle.None),
    e.PrintLine(),
    e.LeftAlign(),
    e.PrintLine("Order: 123456789        Date: 02/01/19"),
    e.PrintLine(),
    e.PrintLine(),
    e.SetStyles(PrintStyle.FontB),
    e.PrintLine("1   TRITON LOW-NOISE IN-LINE MICROPHONE PREAMP"),
    e.PrintLine("    TRFETHEAD/FETHEAD                        89.95         89.95"),
    e.PrintLine("----------------------------------------------------------------"),
    e.RightAlign(),
    e.PrintLine("SUBTOTAL         89.95"),
    e.PrintLine("Total Order:         89.95"),
    e.PrintLine("Total Payment:         89.95"),
    e.PrintLine(),
    e.LeftAlign(),
    e.SetStyles(PrintStyle.Bold | PrintStyle.FontB),
    e.PrintLine("SOLD TO:                        SHIP TO:"),
    e.SetStyles(PrintStyle.FontB),
    e.PrintLine("  FIRSTN LASTNAME                 FIRSTN LASTNAME"),
    e.PrintLine("  123 FAKE ST.                    123 FAKE ST."),
    e.PrintLine("  DECATUR, IL 12345               DECATUR, IL 12345"),
    e.PrintLine("  (123)456-7890                   (123)456-7890"),
    e.PrintLine("  CUST: 87654321"),
    e.PrintLine(),
    e.PrintLine()
  )
);

Step 3: Print special characters

Before you proceed, please make sure you understand the CodePages your printer supports, and if necessary use the CodePage command to change it accordingly to the wanted encoding.

The problem folks usually run into is that C# strings are Unicode, so you are able to declare a string with, for example, the value in C#, but unfortunately, that value does not correctly map to an ASCII 8-bit value that is printable using the standard 7-bit + extended codepages. See here for more information

So below an example of how to print

    // € is char 0xD5 at PC858_EURO CodePage
    var EURO = new byte[] { 0xD5 };
    printer.Write(ByteSplicer.Combine(e.CodePage(CodePage.PC858_EURO), EURO));

    //Optionally you can return to whatever default CodePage you had before. PC437 in this example
    printer.Write(e.CodePage(CodePage.PC437_USA_STANDARD_EUROPE_DEFAULT));

Refer to this code to test your current CodePage, and to this post for a full explanation.

Printing Chinese characters

Assuming your printer has its default CodePage to match GBK Enconding you could accomplish printing chinese characters in 2 ways:

1 - Defining the Encoding in the Emitter

var e = new EPSON { Encoding = System.Text.Encoding.GetEncoding("GBK") };
string chineseCharactersString = "汉字";

printer.Write( 
  ByteSplicer.Combine(
    e.CenterAlign(),
    e.Print("------------------------------------------"),
    e.PrintLine(),
    e.Print(chineseCharactersString),
    e.PrintLine(),
    e.Print("------------------------------------------"),
    e.RightAlign(),
    e.PrintLine()
  )
);

2 - Encoding all strings and directly using them in the Write() method

var encoding = System.Text.Encoding.GetEncoding("GBK");
var e = new EPSON();
string chineseCharactersString = "汉字";
printer.Write( 
  ByteSplicer.Combine(
    e.CenterAlign(),
    e.Print("------------------------------------------"),
    e.PrintLine(),
    encoding.GetBytes(chineseCharactersString),
    e.PrintLine(),
    e.Print("------------------------------------------"),
    e.RightAlign(),
    e.PrintLine()
  )
);

Important Note

If you are using this library with .NET and not .NET Framework, an extra step might be needed before you pass on the Enconding instance to the library

image

This means you need to register the provider once with the line below before you instantiate the Encoding with System.Text.Encoding.GetEncoding method.

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

More details about .NET and Encoding here.

Supported Platforms

Desktop support (WiFI, Ethernet, Bluetooth, USB, Serial):

  • Windows
    • Windows 7+ can support .NET Core or the .NET 471 runtime, and can use this library.
  • Linux
    • ARM platforms such as Raspberry Pi
    • x86/64 platform
  • Mac OSX
    • Tested from High Sierra to Monterrey, both Intel and M1 architectures

Mobile support (WiFi/Ethernet only): ImmediateNetworkPrinter is the recommended integration type for mobile usage, since mobile applications can background your application at any time

  • Xamarin.Forms
  • iOS
    • Xamarin.iOS
  • Android
    • Xamarin.Android
  • Windows
    • UWP

Supported Hardware

Epson thermal receipt printers are supported, and most common functions such as test printing, styling, alignment, image printing, and barcode printing.

Generic thermal printers that implement ESC/POS typically work, for example the Royal PT-300, and BemaTech printers are also tested by some members of the community, @juliogamasso and @ivanmontilla.

Cash Drawers are supported, as are Line Displays.

Further Documentation and Usage

Check out the ESCPOS_NET.ConsoleTest for a comprehensive test suite that covers all implemented functions.

This package is available on NuGet @ https://www.nuget.org/packages/ESCPOS_NET/

Please comment / DM / open issues and let me know how the library is working for you!

Contributors

Thanks to all of our contributors working to make this the best .NET thermal printer library out there!!

USB Usage Guide

For cross-platform support and ease of maintenance, all USB printers are supported over Serial-USB interfaces. These are full-speed and work just as well as native USB as long as you have your port settings optimized.

On Linux and Mac, USB for Epson printers is exposed as a serial port directly by the os under /dev/ttyusb or something similar based on your platform, and doesn't require drivers.

On Windows, you must install some type of virtual COM port driver for native USB support, and then map your printer to a specific port, or use a USB-Serial cable and use a serial printer.

If you have an official Epson printer, the link to install it from Epson is here: https://download.epson-biz.com/modules/pos/index.php?page=single_soft&cid=6481&scat=36&pcat=5

If you do not have an official Epson printer, you will have to find a compatible way to expose the USB interface as a virtual Serial port.

NOTE: The cross platform .NET library we use from Microsoft only supports COM ports 8 and below on windows, so be sure not to use a very high # COM port.

Implemented Commands

Most common commands are implemented natively in the library's included emitter.

Bit Image Commands

  • ESC ✻ Select bit-image mode
  • GS ( L OR GS 8 L Set graphics data
    • Set the reference dot density for graphics.
    • Print the graphics data in the print buffer.
    • Store the graphics data in the print buffer (raster format).

Character Commands

  • ESC ! Select print mode(s)
  • GS B Turn white/black reverse print mode on/off - Thanks @juliogamasso!

Print Commands

  • LF Print and line feed
  • CR Print and carriage return
  • ESC J Print and feed paper
  • ESC K Print and reverse feed
  • ESC d Print and feed n lines
  • ESC e Print and reverse feed n lines

Bar Code Commands

  • GS H Select print position of HRI characters
  • GS f Select font for HRI characters
  • GS h Set bar code height
  • GS k Print bar code
  • GS w Set bar code width
  • GS ( k Print 2D bar codes (QRCode and PDF417)

Status Commands

  • GS a Enable/disable Automatic Status Back (ASB)

Open Cash Drawer Commands

  • ESC p 0 Open cash drawer pin 2
  • ESC p 1 Open cash drawer pin 5

Miscellaneous Commands

  • ESC @ Initialize printer

esc-pos-.net's People

Contributors

altie-webefinity avatar borissundic avatar dilucide avatar hollandar avatar igorocampos avatar jksware avatar juliogamasso avatar kodejack avatar lewisvive avatar lukevp avatar msangtarash avatar neon-dev avatar nickcharlton avatar oachkatzalschwoaf avatar panot-hong avatar paul-turner-github avatar swedish-zorro avatar yzahringer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esc-pos-.net's Issues

is it supported for older .net version?

i searched through out some docs and found out that it's only for .NET 4.7.2 is that true?

What about the older version of .NET do you support it as well?
Here we're still using 3.5, 4.0, and 4.5 .NET version.

regards,

TCP-connection/Timout

When connecting over TCP, the printer closes the connection after 90 seconds inactivity with the reset flag. (Observed with Wireshark on my EPSON TM20II i use for my tests).

this cause that in BasePrinter -> Read() -> ReadByte(); throws an System.IO,IOException each 100ms (as you catch the exception with Thread.Sleep(100))
also Write() will throw the same exception.

here some logic is needed to check if the connection is lost.
I have done some tests in my forked branch bug/connection :
e.g. the connection can be checked as described here: https://stackoverflow.com/a/14925438/12648992
with a method for the network-Printer e.g.:

public override bool IsConnected()
        {
            return !((_socket.Poll(1000, SelectMode.SelectRead) && (_socket.Available == 0)) || !_socket.Connected);
        }

also the System.IO.IOException exception of BasePrinters Read() might be handled as lost connection.

however with my changes i can only handle the dropped connection by the printer.
handle issues with the network like unplug eth-cable on the printer or restart raises additional issues (TCP-connection stayes open while the printer is gone)

Problem printing Japanese text

Hi, this is a great library thanks, but I am having issues printing Japanese characters. My POS printer does support Katakana on code page 1.

This is what I have tried so far but it all ends up wrong. See attachment for the result. Any help with this would be greatly appreciated. Thanks a lot!

`var printer = new NetworkPrinter(ipAddress: Settings.PrinterIP, port: Settings.PrinterPort, reconnectOnTimeout: true);

        Encoding encodingKatakana = Encoding.GetEncoding(932); //Japanese encoding (I also tried Shift-JIS)
        Encoding unicode = Encoding.Unicode;

        byte[] utfBytes = Encoding.Unicode.GetBytes("こうという 気持 きも");
        byte[] convertedBytes = Encoding.Convert(unicode, encodingKatakana, utfBytes);

        printer.Write(utfBytes); //Attempt straight from Unicode

        var e = new EPSON();
        printer.Write(
          ByteSplicer.Combine(
            e.CodePage(CodePage.JAPAN) 
          )
        );

        printer.Write(convertedBytes);  //Attempt from Japan codepage

        printer.Write(
            ByteSplicer.Combine(
            e.CodePage(CodePage.KATAKANA) 
            )
        );
        printer.Write(convertedBytes); //Attempt from Katakana codepage`

IMG_6453

Native USB POS printing

Are you planning on supporting native USB printing? I am looking to print, and receive events back (such as low paper, failed to cut, failed to print. etc) via USB without using a virtual COM port. Having looked through this code it is very thorough and would be amazing if it also supported USB! 🤞

How to save and reuse print buffer?

Hi, I am able to write a receipt to the printer as shown in the wiki page (Step 2). I would like to save the print buffer and reprint the print buffer again. Can you please let me know if this is possible through your library. If yes, can you please give a small illustration.

Usecase for this requirement:

  1. Reprint the receipt if the customer comes back with a request for duplicate copy
  2. Incase of returns print two copies of the receipt. Second copy with signature lines so that customer can sign.

Support for Scanning check

Hi, I am using EPSON TM-T88V and i want to create a sample .NET core console application for scanning the check. are you supporting check scanning.

Does not print accents

I have Encoding "IBM865"

Á Í Ó Ú upper case => does not print

á é í ó ú => print ok

Encoding = Encoding.GetEncoding("IBM865")

byte[] IPrinterTemplate.Receipt(ICommandEmitter e) =>
ByteSplicer.Combine(
e.CenterAlign(),
e.SetBarWidth(BarWidth.Default),
Encoding.GetBytes(PrintHeader(PrintSaleModel.Header.Company))
}

Print pdf file

Hello @lukevp, did you get to read something about PDF printing using ESC POS? I could not figure out how to do it using the commands. Thank you!

Where do I find definitions such as Ops.PaperCut?

Hi I was looking for some sort of .h file for these definitions but couldn't find any? I program in C/C++, not C# but found it useful to compare my code with your for correctness. You have a very good list of commands by functions, better than epson official docs in my opinion. Thanks.

Support additional commands

Hello,
I would like to know if it is possible to use commands for :

  • customers display
  • Drawer kick out

If so, how ?

Thank you

add dithering support for images

Add support for dithering algorithms to image printing library to enable higher quality printing of non-black-and-white images.

EPSON Printer

I have a question on how to connect a usb device.
I have an official epson printer, but I have no idea how to connect it to the code...

Can't be installed

Severity Code Description Project File Line Suppression State
Error Unable to resolve dependency 'SixLabors.ImageSharp'. Source(s) used: 'nuget.org', 'Microsoft Visual Studio Offline Packages'.

Paper status whith ESCPOS

good night lukevp, please do you have forecast or could you help me implement return status printer using ESCPOS, I am trying to implement but without success. Thank you!

QRCode support

I took a look at your classes and couldn't find a command to print QRCodes, is this not implemented yet, or did I miss it?

If not, want me to do a PR about it? Just tell me where would be a good place to do so in the code :)

Nuget Issue

I got your software to download and then I went to go test it and I noticed then when I was trying to identify a new namespace to use. In your directions you said to use: using ESC_POS_USB_NET.Printer; but this does not exist in the Nuget package I downloaded.

image

Invalid argument when creating SerialPrinter object on Linux (Ubuntu 14.04)

Hi, I am trying to leverage you library in Ubuntu 14.04.

I have printer connected via USB. To communicate with it I try to use SerialPrinter class. According to the documentation I pass "/dev/ttyUSB0" file and 9600 baud rate. This file and baud rate are for my printer, I rechecked it. However, when I try to create SerialPrinter object I have exception: Unhandled exception. System.IO.IOException: Invalid argument. I use code from the documentation steps.

image

Why does it happen and how can I fix it?

Thanks in advance!

Implementing polling for printer status

For printers that do not automatically return status', could we implement a method for polling printer status'? currently the printer status for my TG2460H III is always null as no automatic data is received.

printing from blazor webassembly

Hi Luke,

excuse me for perhaps a nonsense question: Is it possible to implement your library in a blazor webassembly application and print to a network printer ?

Regards,
Fabianus

Question network and USB print

Hi! Thanks for this excellent library. I was trying to implement it and make it work with an OCOM Thermal Printer. The network approach is not working since I don´t know the port (tried port 80 and 8080 with no sucess).
USB driver installs the printer on USB001 and when I try to configure it as defined in the documentacion I get an exception:
The given port name does not start with COM/com or does not resolve to a valid serial port.
Parameter name: portName

Can you please point me in the right direction to make it work through USB?
Thanks in advance!

Suggestion about ByteSplicer

Hi Luke,
May I suggest the ByteSplicer Combine method accept only byte[] instead of object[] as a parameter?

public static byte[] Combine(params object[] byteArrays)
{
ByteArrayBuilder builder = new ByteArrayBuilder();
foreach (var byteArray in byteArrays)
{
if (!(byteArray is byte[]))
{
throw new ArgumentException("All passed in objects must be byte arrays.");
}
builder.Append((byte[])byteArray);
}
return builder.ToArray();
}

I mention it, because it looks like this method is not ready to use other type of params. That would simplify a little bit your code and avoid potential exception to be thrown

public static byte[] Combine(params byte[] byteArrays)
{
    var builder = new ByteArrayBuilder();
    foreach (var byteArray in byteArrays)
        builder.Append(byteArray);

    return builder.ToArray();
}

Image print support

Hello @lukevp , some prediction of when image printing will be implemented, I have an implementation but its simpler and with .net standart, I tried to adapt mine using its package but I did not succeed. I can not use BitmapImage type in .net standart. Thank you!

Code128 Type C incorrect encoding

Just for your information: The TM-T88x models of EPSON printers (and probably others, too) do not automatically encode CODE128 type C. With your library, a Type C barcode would be encoded as 48495051 instead of 1234.

The quick-and-dirty solution for this would probably look something like this (in ESCPOS_NET/Emitters/BarcodeCommands.cs):

if (type == BarcodeType.CODE128) {
  if (code == BarcodeCode.CODE_C) {
    // Type C must have a length divisible by two.
    if (barcode.Length % 2 != 0)
      throw new ArgumentException(nameof(barcode));

    // Convert the input string to bytes and validate it to contain numerals only.
    // The input validation could be integrated into the BCD encoding loop; this was omitted for clarity.
    byte[] b = Encoding.ASCII.GetBytes(barcode);
    for (int i = 0; i < b.Length; i++)
      if (b[i] < '0' || b[i] > '9')
        throw new ArgumentException(nameof(barcode));

    // Convert the input string to BCD
    byte[] ob = new byte[b.Length / 2]; int obc = 0;
    for (int i = 0; i < b.Length; i += 2)
      ob[obc++] = (byte)(((b[i] - '0') * 10) + (b[i + 1] - '0'));

    // Replace the original input string with the BCD encoded variant
    barcode = Encoding.ASCII.GetString(ob);
  }

  barcode = barcode.Replace("{", "{{");
  barcode = $"{(char)0x7B}{(char)code}" + barcode;
}

How to print logo from a Xamarin Forms Application

Hi, I am trying to print logo using this nuget package. Could not figure out how to print the logo yet. I have tried getting image byte code using the webclient.downloadData("ImageURL"). But it only prints gibberish instead of the logo itself. Could you be kind enough to share how to print a logo from Xamarin forms application. Thanks.

Exception Printing 2D-Code

Hi,

if i want to print a 2D-Code with more than 254 characters i get an exception:

System.ArgumentException: "Code '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345' is longer than maximum length 254."

Thanks

QR Code Model 1 vs Model 2 Incorrect Printing

I've noticed that QRCode Model 1 is not readable. And Model 2 looks to be Model 1 when visually comparing the printed code with a Model 1 code printed via this pre ESC-POS implementation:

String text = "test";

printerBuffer[0] = 0x1d;
printerBuffer[1] = 0x28;
printerBuffer[2] = 0x6b;
printerBuffer[3] = 4;
printerBuffer[4] = 0;
printerBuffer[5] = 0x31;
printerBuffer[6] = 0x41;
printerBuffer[7] = 0x49; // 0x49 - model 1 / 0x50 - model 2
printerBuffer[8] = 0x00;
serialPort.Write(printerBuffer, 0, 9);

printerBuffer[0] = 0x1d;
printerBuffer[1] = 0x28;
printerBuffer[2] = 0x6b;
printerBuffer[3] = 3;
printerBuffer[4] = 0;
printerBuffer[5] = 0x31;
printerBuffer[6] = 0x45;
printerBuffer[7] = 0x33; // 0x33 - Error correction level H (30% recovery capacity)
serialPort.Write(printerBuffer, 0, 8);

int len = 3 + text.Length;

printerBuffer[0] = 0x1d;
printerBuffer[1] = 0x28;
printerBuffer[2] = 0x6b;
printerBuffer[3] = (byte)(len % 256);
printerBuffer[4] = (byte)(len / 256);
printerBuffer[5] = 0x31;
printerBuffer[6] = 0x50;
printerBuffer[7] = 0x30;

char[] strChars = text.ToCharArray();
for (int i = 0; i < text.Length; i++) {
    printerBuffer[8 + i] = (byte)strChars[i];
}
serialPort.Write(printerBuffer, 0, 8 + text.Length);

printerBuffer[0] = 0x1d;
printerBuffer[1] = 0x28;
printerBuffer[2] = 0x6b;
printerBuffer[3] = 3;
printerBuffer[4] = 0;
printerBuffer[5] = 0x31;
printerBuffer[6] = 0x51;
printerBuffer[7] = 0x30;
serialPort.Write(printerBuffer, 0, 8);

This is the equivalent ESC-POS call:

printer.Write(E.Print2DCode(TwoDimensionCodeType.QRCODE_MODEL2, text, Size2DCode.SMALL, CorrectionLevel2DCode.PERCENT_30));

Dot Matrix Printer, unable to print short message

Hello!
So far everything works great beside one thing. When I try to print single character I am unable to do this.

           printer.Write(new []{(byte) 97, (byte) 10}); // Works
           var e = new EPSON();
           printer.Write(
               ByteSplicer.Combine(
                   e.PrintLine("a") // Does not work
               )
           );

I inspect your code a little bit and it seems that there is problem with flushing, but I am not sure. You need around 150 characters to be able to print sth.
I do not see any more errors. With this I should be able to make sth like EPSON, but called DotMatrix.

Code Page?

Hi,
How to set code page?
For example Windows-1255 for Hebrew characters (POS code page set to 26)

Thanks,
Asaf

Printing code128 barcode

Hi,
can anyone tell me how to print code128 barcode ? always I get blank paper!
Thanks in advance

Dispose pattern not implemented properly

Hi there,

first of, thank you very much for your project !!

Regarding the Dispose pattern. NetworkPrinter doesn't implement a safe disposable pattern.

When using the simple following code, things go kaboum

using (var p = new NetworkPrinter())
{
   // [....]
}

That's because you also call Dispose() in the finalizer without checking if resource has already been disposed.

EDIT: I had to use a GC.SuppressFinalize(p); to prevent GC disposing twice the resource


EDIT2 : An even worst offender

In the case an printer address is invalid or unreachable

public class NetworkPrinter : BasePrinter, IDisposable
{
        // ...

        private void Connect()
        {
            _socket = new Socket(_endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

           // What if the line below cannot connect properly ?
            _socket.Connect(_endPoint);

           // Then what's below never gets initialized and is still set to null
            _sockStream = new NetworkStream(_socket);
            _writer = new BinaryWriter(_sockStream);
            _reader = new BinaryReader(_sockStream);
        }

        public void Dispose()
        {
            _writer.Close(); // <-- Crash with NullReferenceException
            _reader.Close(); // <-- Crash with NullReferenceException
            _socket.Close();
            _socket.Dispose();
        }
}

Replace external libraries by .NET standard libraries

Both the .NET Framework and .NET Core now contain methods for image processing and serial port connection.
I replaced SixLabors.ImageSharp by System.Drawing.Common and SerialPortStream by System.IO.Ports.
If you are interested to get rid of the external dependencies, have a look at my commits on https://github.com/Xenoage/ESC-POS-.NET
These libraries are also available for Linux, so you can use the SerialPrinter there instead only the FilePrinter.

Printing area

Hello!
Thank you for great project.
I am using this project with OKI m3320 printer. All things works great beside one, right alignment. When I print sth with right alignment it cut portion of text (does not fit). Is there any way to set line length ?

---Edit---
After reading several pdf I tried to set printing area but the result was much worst.

printer.Write(new []{(byte) 27, (byte) 64}); //ESC @
printer.Write(new []{(byte) 27, (byte) 77}); // ESC M
printer.Write(new []{(byte) 27, (byte) 108,(byte) 49, (byte) 48}); // ESC l 10
printer.Write(new []{(byte) 27, (byte) 81,(byte) 55, (byte) 53}); // ESC Q 75

Can you give me any suggestion how to Change this printing area or how to fix right alignment ?

Add support for virtual port

Hello,

I have a printer TSP100 link to a computer by USB and Windows create a virtual port.

As I don't know if it's possible to have an internal redirection, it will be nice is your package is able to communicate with this kind of port.

I try to force the value like comPort = "USB001"; but I have an exeception because it's awaiting a COMX value.

Regards

USB POS Printing

Hello,

I might have overlooked it;

Is there a way to print when the printer is nor on the network, nor using a Serial Connection?
I currently have my thermal printer attached through USB, can I still use this library?

Thanks!

QRCODE Implementation

Hey Guys

I have implemented Qr-code printing functionality. I'm a beginner in programming so I'm not sure how to submit the code here. Is there a way way I could submit my code here for you guys to review.

Cheers!!

QRCODE

Question: QR Code

Please let me know if your nuget supports adding QRCode to the receipt? Thanks.

Nuget Download Error

I tried to download your code from Nuget and I got this error

Unable to resolve dependency 'SixLabors.ImageSharp'. Source(s) used: 'nuget.org', 'Microsoft Visual Studio Offline Packages'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.