Hey folks,

I have an Epson POS printer which support printing via my COM port using ESC/POS. This all works well in my c# app. I have used Epson's BMP converter tool to convert a bmp file to a binary file which can be sent directly to the printer.

How would I get my c# app to send this binary file straight to COM1?

I am familiar with the basic sp.Write("lalala") and sp.Writeline("lalala") commands.

The binary file is only 4kb in size so do I really need a binarystreamer? Can I not just do something like fopen(logo.dat,br) ??

Your help is appreciated thanks

When you scrub off all the fluffy help methods like WriteLn etc, you see that all communications through the comport are actually in byte[] format. Your BMP can be placed into a byte array, and sent to the comport.

Most Epson Printers should have onboard memory.
You should ony have to place your image in this memory and call it from the code. Which printer is it?

Hi guys,

No, this printer doesn't have on-board memory. Its the TM-T88ii (One mark below the version which does have memory).

I don't think I can put the BMP into a byte array as this "binary file" is in special Epson ESC/POS code so need to be sent.

Now, could i put the binary file into a byte array?

Cheers

by the way, i think I'm using completly wrong terms when I say "binary file". I think what I'm suppoed to say it "file with ESC/POS codes that outputs a bitmap"

Maybe you can send the image data to the printer using the above but I don't know if the desired result can be achieved.. i.e positioning of the image etc..
I have never worked with the TM88II just the TM88III upwards.
Is there no option to get rid of the TM88II as its about 7 years old now and replace it with a nice new TM88III that can handle images nicely :)

Please, I need some example about sending a bitmap to a printer without using OPOS. I connect the printer via an USB/Pararel converter and I have to use Generic / Text Only driver because the driver only lets me assign USB, LPT or COM ports.

I think that I can only use ESC/POS commands to send it.

Maybe you can send the image data to the printer using the above but I don't know if the desired result can be achieved.. i.e positioning of the image etc..
I have never worked with the TM88II just the TM88III upwards.
Is there no option to get rid of the TM88II as its about 7 years old now and replace it with a nice new TM88III that can handle images nicely :)

You can create a named pipe for LPT1 or which ever port the printer is on and send it data:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Smo.RegisteredServers;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;


    [DllImport("kernel32.dll", SetLastError = true)]
    public static extern SafeFileHandle CreateNamedPipe(
       String pipeName,
       uint dwOpenMode,
       uint dwPipeMode,
       uint nMaxInstances,
       uint nOutBufferSize,
       uint nInBufferSize,
       uint nDefaultTimeOut,
       IntPtr lpSecurityAttributes);
    /* -------------------------------------------------------------------- */
    [DllImport("kernel32.dll", SetLastError = true)]
    public static extern int ConnectNamedPipe(
       SafeFileHandle hNamedPipe,
       IntPtr lpOverlapped);
    /* -------------------------------------------------------------------- */
    [DllImport("kernel32.dll", SetLastError = true)]
    public static extern SafeFileHandle CreateFile(
       String pipeName,
       uint dwDesiredAccess,
       uint dwShareMode,
       IntPtr lpSecurityAttributes,
       uint dwCreationDisposition,
       uint dwFlagsAndAttributes,
       IntPtr hTemplate);

//Inside a method:
      try
      {
        uint GENERIC_READ = (0x80000000);
        uint GENERIC_WRITE = (0x40000000);
        uint OPEN_EXISTING = 3;
        uint FILE_FLAG_OVERLAPPED = (0x40000000);

        SafeFileHandle pipeHandle =
           CreateFile(
              "LPT1",
              GENERIC_READ | GENERIC_WRITE,
              0,
              IntPtr.Zero,
              OPEN_EXISTING,
              FILE_FLAG_OVERLAPPED,
              IntPtr.Zero);

        //could not get a handle to the named pipe
        if (pipeHandle.IsInvalid)
          return;

        using (FileStream fStream = new FileStream(pipeHandle, FileAccess.Write))
        {
          char cOp = Convert.ToChar(7);
          byte bOp = Convert.ToByte(cOp);
          fStream.WriteByte(bOp);
          fStream.Flush();
          fStream.Close();
        }
      }
      catch { }
This article has been dead for over six months. Start a new discussion instead.