我正在尝试在单点触控应用程序中使用 Star Micronics TSP650II 打印机打印标签。
问题是session.OutputStream.HasSpaceAvailable()
总是返回false。我错过了什么?
我的 C# 代码是这样的(为了简单起见):
var manager = EAAccessoryManager.SharedAccessoryManager;
var starPrinter = manager.ConnectedAccessories.FirstOrDefault (p => p.Name.IndexOf ("Star") >= 0); // this does find the EAAccessory correctly
var session = new EASession (starPrinter, starPrinter.ProtocolStrings [0]); // the second parameter resolves to "jp.star-m.starpro"
session.OutputStream.Schedule (NSRunLoop.Current, "kCFRunLoopDefaultMode");
session.OutputStream.Open ();
byte[] toSend = GetInitData(); // this comes from another project where the same printer with ethernet cable was used in a windows environment and worked, not null for sure
if (session.OutputStream.HasSpaceAvailable()) {
int bytesWritten = session.OutputStream.Write (toSend, (uint)stillToSend.Length);
if (bytesWritten < 0) {
Debug.WriteLine ("ERROR WRITING DATA");
} else {
Debug.WriteLine("Some data written, ignoring the rest, just a test");
}
} else
Debug.WriteLine ("NO SPACE"); // THIS ALWAYS PRINTS, the output stream is never ready to take any output
更新:我能够通过将 Star Micronics iOS SDK 绑定到我的项目来解决这个问题,但这并不理想,因为它在包中添加了 700K 的内容,以便在没有该绑定的情况下工作。
更新 2:我收到了对绑定代码的请求。我仍然强烈建议您尝试弄清楚蓝牙连接并且不要使用绑定但是对于那些足够勇敢的人来说,这里是。