斑馬條碼打印機(ZPL打印機:110Xi4 , 140Xi4 , 170Xi4 , 220Xi4 , R110Xi , R110Xi HF , R170Xi , 110XiIIIPlus , 140XiIIIPlus , 170XiIIIPlus , 220XiIIIPlus , 105SL , S4M , ZM400 , ZM600 , RZ400 , RZ600 , GX420t , GX420d , GX430t , GK420t , GK420d , RW 220 , RW 420 , RW 420 Print Station , 110PAX4 , 170PAX4 , R110PAX4 , C# , R110Xi4 , QLn 220 , QLn 320 )如何通過以太網接口TCP/IP發送ZPL指令到條碼打印機呢? 下面通過C#與VB.net中的例子來進行說明: 1、C#中的例子 // Printer IP Address and communication port string ipAddress = "10.3.14.42"; int port = 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); // 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) { // Catch Exception } 2、VB.net中的例子: Dim ipAddress As String = "10.3.14.59" Dim port As Integer = 9100 Dim ZPLString As String = _ "^XA" & _ "^FO50,50" & _ "^A0N,50,50" & _ "^FDHello, World!^FS" & _ "^XZ" Try 'Open Connection Dim client As New System.Net.Sockets.TcpClient client.Connect(ipAddress, port) 'Write ZPL String to Connection Dim writer As New System.IO.StreamWriter(client.GetStream()) writer.Write(ZPLString) writer.Flush() 'Close Connection writer.Close() client.Close() Catch ex As Exception 'Catch Exception Here End Try
|