我尝试使用以下代码通过WiFi打印到HP打印机,来自Xamarin Android代码:
private async Task Print()
{
await Task.Run(() =>
{
try
{
//As you will see, all depends on your printer commands
Socket socket = new Socket("10.10.0.15", 9100);
PrintWriter pw = new PrintWriter(socket.OutputStream, false);
//here is the beginning of printing
pw.Write(0x1B); //Example of command to start a printer
pw.Print("THIS IS YOUR AWESOME TEXT FOR PRINT");
pw.Write(0x0C); //here you release the paper
pw.Write(0x40); //finish printing
pw.Flush();
pw.Close();
pw.Dispose();
socket.Close();
socket.Dispose();
}
catch (SocketException ex)
{
System.Console.WriteLine("SocketError: " + ex.Message);
}
});
}
但这不起作用。我的Android设备和这台打印机在同一个WiFi网络上。请在这里建议可能出现的问题?