Printer language & sending commands

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vlki

    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," + "12345678901234 567890";
    Font fFont = new Font("Arial", 16);
    SolidBrush bBrush = new SolidBrush(Colo r.Black);
    PointF pPoint = new PointF(150.0F, 150.0F);
    ev.Graphics.Dra wString(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.


  • Kai Bohli

    #2
    Re: Printer language & sending commands

    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
    Microsoft Support is here to help you with Microsoft products. Find how-to articles, videos, and training for Microsoft Copilot, Microsoft 365, Windows 11, Surface, and more.


    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.EventArg s e)
    {
    PrintDialog pd = new PrintDialog();
    pd.PrinterSetti ngs = new PrinterSettings ();
    if (DialogResult.O K == pd.ShowDialog(t his))
    {
    MemoryStream memStrm = new MemoryStream();
    StreamWriter sw = new StreamWriter(me mStrm);
    sw.WriteLine("\ x02L");
    sw.WriteLine("H 07");
    sw.WriteLine("D 11");
    sw.WriteLine("1 911008020000251 0K Ny linje");
    sw.WriteLine("1 911008010000251 0K OHM 1/4 WATT");
    sw.Flush();
    sw.WriteLine("1 a62100000000505 90PCS");
    sw.WriteLine("E ");
    sw.WriteLine("" );
    sw.Flush();

    memStrm.Positio n = 0;
    LabelPrint.Send DocToPrinter(pd .PrinterSetting s.PrinterName,m emStrm);
    sw.Close();

    </snip>

    <snip2>
    private void btn3_Click(obje ct sender, System.EventArg s e)
    {
    PrintDialog pd = new PrintDialog();
    pd.PrinterSetti ngs = new PrinterSettings ();
    if (DialogResult.O K == pd.ShowDialog(t his))
    {
    string p = pd.PrinterSetti ngs.PrinterName ;
    LabelPrint.Send StringToPrinter (p,"\x02L"); // ^BL
    LabelPrint.Send StringToPrinter (p,"H07");
    LabelPrint.Send StringToPrinter (p,"D11");
    LabelPrint.Send StringToPrinter (p,"19110080100 002510K OHM 1/4 WATT");
    LabelPrint.Send StringToPrinter (p,"1a621000000 0050590PCS");
    LabelPrint.Send StringToPrinter (p,"E");
    LabelPrint.Send StringToPrinter (p,"");
    }
    }
    </snip2>


    On Tue, 6 Jul 2004 14:38:31 +0200, "Vlki" <damijan.gradis er_at_neckerman n_si> wrote:
    [color=blue]
    >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," + "12345678901234 567890";
    >Font fFont = new Font("Arial", 16);
    >SolidBrush bBrush = new SolidBrush(Colo r.Black);
    >PointF pPoint = new PointF(150.0F, 150.0F);
    >ev.Graphics.Dr awString(sStrin g, 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[/color]

    Best wishes
    Kai Bohli
    kaiboeNO_SPAM@o nline.no
    Norway

    Comment

    • Emanuele Baglini

      #3
      Re: Printer language &amp; sending commands

      "Kai Bohli" <kaiboe@online. nospam> ha scritto nel messaggio
      news:710me0ds20 tp2orabr7cq9lap cdefabt4p@4ax.c om...[color=blue]
      > Hi !
      >
      > You need to send the data raw to the printer, otherwise Windows will eat[/color]
      the control codes alive.[color=blue]
      >
      > 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[/color]
      formating )[color=blue]
      >
      > (Note: The SendDocTo Printer is my addon to the article, where I have[/color]
      added a few methods so I could[color=blue]
      > 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[/color]
      DataMax label printers,[color=blue]
      > but almost everything I've done is done in Delphi. I've jsut started[/color]
      porting this stuff to C#[color=blue]
      > myself. Anyway, if you're stucked - contact me and I can see if I can help[/color]
      you - no garantee though[color=blue]
      > :)[/color]

      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


      Comment

      • Kai Bohli

        #4
        Re: Printer language &amp; sending commands

        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(me mStrm);
        sw.WriteLine("\ n"); // new line to start command structure
        sw.WriteLine("N "); // clear image memory from last printed label
        sw.WriteLine("X 0,0,4,752,584") ; // draw a box
        sw.WriteLine("L O0,144,752,4"); // draw a line
        sw.WriteLine("A 40,400,1,1,1,1, N," + sn + "Made in Norway" + sn);
        sw.WriteLine("B 280,440,0,1,2,3 ,96,B," + sn + "S 000001" + sn); // write a barcode
        sw.Flush();
        sw.WriteLine("P 1"); // print 1 label
        sw.WriteLine("" ); // empty line
        sw.Flush();

        memStrm.Positio n = 0;
        LabelPrint.Send DocToPrinter(pd .PrinterSetting s.PrinterName,m emStrm);
        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 SendDocToPrinte r. I've posted the code below:
        <code for the SendDocToPrinte r function>
        public static bool SendDocToPrinte r( string szPrinterName, MemoryStream ms)
        {
        // Open the file.
        //FileStream fs = new FileStream(szFi leName, 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.AllocCo TaskMem(nLength );
        // Copy the managed byte array into the unmanaged array.
        Marshal.Copy(by tes, 0, pUnmanagedBytes , nLength);
        // Send the unmanaged bytes to the printer.
        bSuccess = SendBytesToPrin ter(szPrinterNa me, pUnmanagedBytes , nLength);
        // Free the unmanaged memory that you allocated earlier.
        Marshal.FreeCoT askMem(pUnmanag edBytes);
        return bSuccess;
        }
        </code for the SendDocToPrinte r function>

        [color=blue]
        >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[/color]


        Best wishes
        Kai Bohli
        kaiboeNO_SPAM@o nline.no
        Norway

        Comment

        Working...