斑马打印机打印条码问题
用C#写了一个WEB,功能:用斑马打印机(105SL)打印条码。代码如下:
public static void Print_PENO(string ZPLString, string ipAddress)
{//ZPLString是机器码,ipAddress是打印机IP
int port = 9100;
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)
{
throw ex;
}
}
调用后,执行到ter.Flush();出错:Unable to write data to the transport connection: 遠端主機已強制關閉一個現存的連線。
请大家帮我查到原因,非常感谢!