IPAddress ip = IPAddress.Parse("192.168.0.10"); IPEndPoint iport = new IPEndPoint(ip, 9100);//9100为打印机指定端口 Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); soc.Connect(iport); string cmdLine = "\x1b%-12345X@PJL INFO ID \r\n\x1b%-12345X";//获取打印机id //cmdLine = "\x1b%-12345X@PJL INFO STATUS \r\n\x1b%-12345X";//获取打印机状态 soc.Send(Write(@cmdLine)); while (true)//定义一个循环接收返回数据 { byte[] data = new byte[1024]; soc.Receive(data);//接收返回数据 string stringData = Encoding.UTF8.GetString(data); if (!string.IsNullOrWhiteSpace(stringData)) { MessageBox.Show(stringData); break; } } soc.Close(); MessageBox.Show("ok");
版权声明:《 C# 发送PJL命令获取打印机状态 》为zhangkang原创文章,转载请注明出处!
最后编辑:2019-9-2 18:09:02