条码打印四 – 4.C#Zebra斑马便携式打印机Wifi TCP打印

 1 // Printer IP Address and communication port
 2 string ipAddress = "10.3.14.42";
 3 int port = 9100;
 4  
 5 // ZPL Command(s)
 6 string ZPLString =
 7     "^XA" +
 8     "^FO50,50" +
 9     "^A0N50,50" +
10     "^FDHello, World!^FS" +
11     "^XZ";
12  
13 try
14 {
15     // Open connection
16     System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
17     client.Connect(ipAddress, port);
18  
19     // Write ZPL String to connection
20     System.IO.StreamWriter writer =
21 new System.IO.StreamWriter(client.GetStream());
22     writer.Write(ZPLString);
23     writer.Flush();
24  
25     // Close Connection
26     writer.Close();
27     client.Close();
28 }
29 catch (Exception ex)
30 {
31     // Catch Exception
32 }