爱普生TM-U220 USB打印错误
本文关键字:错误 打印 USB TM-U220 爱普生 | 更新日期: 2023-09-27 17:52:13
我有一个爱普生POS打印机的情况。爱普生提供的示例工作如预期,但当我尝试在Xamarin BOOM!
我创建了一个Android Java绑定库,添加了一个文件夹"Jars",并将ePos-Prin.jar
文件复制到其中,将EmbeddedJar
选项设置为Build Action
。
在我的Android项目中,我将。o文件(本机库)放在"jni/armeabi"文件夹树中,并将Build Action选择为AndroidNativeLibrary
。同样在Android项目中,我有一个简单的MainActivity
类,它将尝试找到打印机,但不能抛出异常。
我使用以下代码行:
using System;
using Android.App;
using Android.Content;
using Android.Widget;
using Android.OS;
using Com.Epson.Epsonio; //Library from JBL
using Com.Epson.Eposprint; //Library from JBL
namespace EpsonPrint
{
[Activity(MainLauncher=true)]
public class MainActivity : Activity
{
const int SEND_TIMEOUT = 10 * 1000;
DeviceInfo[] mDeviceList;
Context mContext;
protected override void OnCreate(Bundle savedInstanceState)
{
//Java.Lang.JavaSystem.Load("$APP/jni/libeposprint.so"); //Doesn't work
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
var find = (Button)FindViewById(Resource.Id.find);
var print = (Button)FindViewById(Resource.Id.print);
mContext = this;
print.Click += delegate
{
try {
Print();
} catch (EpsonIoException e) {
e.PrintStackTrace();
Toast.MakeText(mContext, e.ToString(), ToastLength.Long).Show();
}
};
find.Click += delegate
{
try {
GetDevices(); //BOOM! here...
} catch (EpsonIoException e) {
e.PrintStackTrace();
Toast.MakeText(mContext, e.ToString(), ToastLength.Long).Show();
}
};
}
private void GetDevices() {
try {
Finder.Start(this, DevType.Usb, "null");
} catch (EpsonIoException e) {
if (e.Status == IoStatus.ErrIllegal) {
Toast.MakeText(this, "SEARCH ALREADY IN PROGRESS", ToastLength.Long).Show();
} else if (e.Status == IoStatus.ErrProcessing) {
Toast.MakeText(this, "COULD NOT EXECUTE PROCESS", ToastLength.Long).Show();
} else if (e.Status == IoStatus.ErrParam) {
Toast.MakeText(this, "INVALID PARAMETER PASSED", ToastLength.Long).Show();
} else if (e.Status == IoStatus.ErrMemory) {
Toast.MakeText(this, "COULD NOT ALLOCATE MEMORY", ToastLength.Long).Show();
} else if (e.Status == IoStatus.ErrFailure) {
Toast.MakeText(this, "UNSPECIFIED ERROR", ToastLength.Long).Show();
}
}
}
private void Print()
{
mDeviceList = Finder.GetDeviceInfoList(Finder.FilterNone);
var status = new int[1];
if (mDeviceList.Length > 0)
{
Finder.Stop();
}
else
{
Toast.MakeText(mContext, "List is null", ToastLength.Long).Show();
}
String deviceName = mDeviceList[0].DeviceName;
String printerName = mDeviceList[0].PrinterName;
int deviceType = mDeviceList[0].DeviceType;
String macAddress = mDeviceList[0].MacAddress;
Print printer = new Print(ApplicationContext);
//Log.("Device Name: " + deviceName +"'n" + "Printer Name: " + printerName + "'n" + "Device Type: " + String.valueOf(deviceType) + "'n" + "MAC: " +macAddress, "");
try
{
//Print Data Builder
var builder = new Builder("TM-U220", Builder.ModelAnk, ApplicationContext);
builder.AddText("ESPON PRINT TEST");
builder.AddCut(Builder.CutFeed);
// if(builder!=null) {
// Log.i("BUILDER NOT NULL", "");
// }
//Printer Test Builder
var confirmBuilder = new Builder("TM-U220", Builder.ModelAnk, ApplicationContext);
//Open printer
printer.OpenPrinter(DevType.Usb, deviceName);
//Send Test Builder
printer.SendData(confirmBuilder, SEND_TIMEOUT, status);
//Check printer Status
if ((status[0] & Com.Epson.Eposprint.Print.StOffLine) != Com.Epson.Eposprint.Print.StOffLine)
{
//If online send print data
//Log.i("PRINTER NOT OFFLINE", "");
printer.SendData(builder, SEND_TIMEOUT, status);
//Check if data sent successfully
if ((status[0] & Com.Epson.Eposprint.Print.StPrintSuccess) == Com.Epson.Eposprint.Print.StPrintSuccess)
{
builder.ClearCommandBuffer();
Toast.MakeText(this, "DATA SENT SUCCESSFULLY", ToastLength.Long).Show();
}
printer.ClosePrinter();
}
else if ((status[0] & Com.Epson.Eposprint.Print.StOffLine) == Com.Epson.Eposprint.Print.StOffLine)
{
Toast.MakeText(this, "PRINTER OFFLINE", ToastLength.Long).Show();
}
else
{
Toast.MakeText(this, "OTHER PRINTER ERROR", ToastLength.Long).Show();
}
}
catch (EposException e)
{
e.PrintStackTrace();
Toast.MakeText(mContext, e.ToString(), ToastLength.Long).Show();
}
}
}
}
有人能帮帮我吗?
我没有爱普生USB打印机,但我在各种打印机中尝试了以下简单的代码,我可以告诉你这是有效的。看看你是否可以创建一个你想要打印的文件,然后尝试下面这个简单的方法,也许它也可以在那个打印机上工作:
public void print () {
Desktop desktop = Desktop.getDesktop();
try {
desktop.print(new File("Docfile.pdf"));
} catch (IOException e) {
e.printStackTrace();
}
}