2 Replies Latest reply on Dec 3, 2018 6:43 AM by Dmitry Prokhorov

    Direct Connection options in .NET

    Stuart Saxonberg

      I'm integrating a ZD420 to our point-of-sale system for printing labels; we really don't want to take a huge dependency tree and installer overhead on the Link-OS SDK (200+ megs, no thank you?) just to send a small packet of ZPL to a printer.

       

      Is there documentation showing how to connect directly via TCP/IP and do basic status and communication conversations with the printer?

       

      Thanks!

        • Re: Direct Connection options in .NET
          Robin West

          Hi Stuart, Sure.  It can use the most basic TCP socket to port 9100.  The code sample we posted before is quite old and I'm having a hard time finding it, so I will repost something that works here:

          Modified from TCP/IP Client Socket Program in C#.Net Using IP Address And Port Number - Stack Overflow

          This will print a small label and send back the firmware version of the printer to be printed on the console. Obviously change the IP address to your own.

           

          using System;
          using System.Net;
          using System.Net.Sockets;
          using System.Text;
          
          namespace ConsoleApp1
          {
              class Program
              {
                  private static void Main(String[] args)
                  {
                      byte[] data = new byte[10];
          
                      IPAddress ipAdress = IPAddress.Parse("10.80.127.53");
                      int port = 9100;
          
                      IPEndPoint ipEndpoint = new IPEndPoint(ipAdress, port);
          
                      Socket client = new Socket(ipAdress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
          
                      try
                      {
                          client.Connect(ipEndpoint);
          
                          Console.WriteLine("Socket created to {0}", client.RemoteEndPoint.ToString());
          
                          byte[] sendmsg = Encoding.ASCII.GetBytes("^XA^LL200^FO20,20^A0N50,50^FDHELLO^FS^XZ\r\n! U1 getvar \"appl.name\"\r\n");
          
                          int n = client.Send(sendmsg);
          
                          int m = client.Receive(data);
          
                          Console.WriteLine("" + Encoding.ASCII.GetString(data));
                          client.Shutdown(SocketShutdown.Both);
                          client.Close();
          
                      }
                      catch (Exception e)
                      {
                          Console.WriteLine(e.ToString());
                      }
          
                      Console.WriteLine("Transmission end.");
                      Console.ReadKey();
          
                  }
              }
          }
          

          The actual .NET SDK is smaller than 200Mb and comes as a Nuget package as well, but it does have a number of dependencies that you simply don't need for simple use cases such as yours, so I totally understand your concern.

          Hope this helps,

          Robin

          • Re: Direct Connection options in .NET
            Dmitry Prokhorov

            Hello Stuart,

             

            Also, by sending the ASCII character sequence "^XA~JD^XZ" you can enable printer diagnostic mode. You can use "^XA~JE^XZ" sequence to disable diagnostic mode.

            In diagnostic mode it should print out the label metrics are committed to the printers flash memory on every print request. This way you could be able to see label metrics sent to your printer from Link-OS SDK and then use captured metrics values in your direct communication with printer.

            You can find more details in ZPL II Programming Guide here https://www.zebra.com/content/dam/zebra/manuals/printers/common/programming/zpl-zbi2-pm-en.pdf

             

            Dmitry Prokhorov

            Software Engineer, Kutir Mobility

            Posted on behalf of Zebra Technologies