使用POS命令操作网口打印机的好处在于免驱动并且打印速度较快.
方法一使用TcpClient类
关键代码
Int32 port = 9100;
string bigFont =((char)27).ToString() + ((char)33).ToString() + ((char)213).ToString();//放大字体
TcpClient client = new TcpClient();
try
{
client.Connect("172.30.168.100", port);
Byte[] data = System.Text.Encoding.Default.GetBytes(bigFont);
NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
data = System.Text.Encoding.Default.GetBytes(bigFont);
stream.Write(data, 0, data.Length);
data = System.Text.Encoding.Default.GetBytes("打印机测试/n");
stream.Write(data, 0, data.Length);
data = System.Text.Encoding.Default.GetBytes("- -/n");