我开发了 windows mobile 6.1 应用程序,可以搜索附近的蓝牙设备并发送文件。我还实现了在蓝牙打印机上打印文档的打印功能。
第一次打印功能运行良好,但当我再次打印文档时,我需要重新启动打印机,然后才能打印。
有什么解决方案可以避免重启打印机吗??
下面是我引用的打印代码 https://32feet.codeplex.com/discussions/355451
private void btPrint_Click(object sender, EventArgs e)
{
// Activate BT
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
System.Threading.Thread.Sleep(1000);
// Connect
BluetoothAddress btAddress;
btAddress = BluetoothAddress.Parse("0022583165F7");
BluetoothClient btClient = new BluetoothClient();
try
{
btClient.Connect(new BluetoothEndPoint(btAddress, BluetoothService.SerialPort));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
// Send data
string CPCLStr1 =
"! 0 200 200 210 1" + Environment.NewLine +
"ML 25" + Environment.NewLine +
"TEXT 7 0 10 20" + Environment.NewLine +
"Just" + Environment.NewLine +
"Testing" + Environment.NewLine +
"ENDML" + Environment.NewLine +
"FORM" + Environment.NewLine +
"PRINT" + Environment.NewLine;
// Convert CPCL String to byte array
byte[] CPCLbytes1 = ASCIIEncoding.ASCII.GetBytes(CPCLStr1);
NetworkStream ns = btClient.GetStream();
ns.Write(CPCLbytes1, 0, CPCLbytes1.Length);
btClient.Close();
}
最佳答案
虽然您关闭了客户端流,但打印机似乎在重置其 session 之前等待了一段时间。
尝试在末尾发送一个
根据 CPCL 引用指南,没有简单的重置命令,例如 ESC/p ({esc}@)。
在每次打印后重置设备似乎有点矫枉过正。
编辑:sendFile 的 SDK 示例:
Byte[] cpclLabel = Encoding.Default.GetBytes("! 0 200 200 406 1\r\n" + "ON-FEED IGNORE\r\n"
+ "BOX 20 20 380 380 8\r\n"
+ "T 0 6 137 177 TEST\r\n"
+ "PRINT\r\n");
以上在我的 RW420 上运行良好,无需在打印之间重置。
关于printing - 如何避免打印后重启蓝牙打印机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24007391/