I try to print to zebra printer. Zebra provided me a standard code sample in C# There they used port 9100 to connect to the printer
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
client.Connect("127.0.0.1", 9100);
However each time i run this code it crashes as there is no such port number available I also used telnet 127.0.01 9100 and that confirmed that there is nothing listening to 9100 I also tried port 6101 as used by some Zebra printers no success either.
I can run in a dos command
print /D:\\127.0.0.1\KR403 d:\print.txt
This does print, and proves it listens somehow to network Internally. This device is a USB printer, and that's making it complex to set a static port ID. Perhaps also strange the above command does print a barcode, but doesnt cut the paper; when i print using notepad (which i assume does not use the network to print) then it cuts paper but the paper is 40cm long (way to large).. so i am in driver battle it seams.
What i hope to do, is send a print command using C# and use ZPL commands to print Microsoft wrote an article about raw printing too, but it fails on this printer.
All i want to do is send ZPL instructions to this printer. Aslo tried generic txt driver, this works for notepad but not for C#
Code used :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
// print /D:\\127.0.0.1\KR403 d:\print.txt
namespace PrinterTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Printer IP Address and communication port
string ipAddress = @"192.168.2.109";
int port = 6101; // 9100;//
// ZPL Command(s)
string ZPLString =
"^XA" +
"^FO50,50" +
"^A0N50,50" +
"^FDHello, World!^FS" +
"^XZ";
try
{
// Open connection
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
//client.Connect(ipAddress, port);
client.Connect(ipAddress, port);
// string tmp = "\\127.0.0.1\KR403";
// client.Connect(@"\\localhost",9100);
// Write ZPL String to connection
System.IO.StreamWriter writer = new System.IO.StreamWriter(client.GetStream());
writer.Write(ZPLString);
writer.Flush();
// Close Connection
writer.Close();
client.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error");
}
}
}
}