gpt4 book ai didi

c# - Epson TM-U220 USB 打印错误

转载 作者:太空宇宙 更新时间:2023-11-03 15:40:02 36 4
gpt4 key购买 nike

我遇到了爱普生 POS 打印机的问题。 Epson 提供的示例按预期工作,但是当我尝试在 Xamarin 中使用时 BOOM!

我创建了一个 Android Java 绑定(bind)库,添加了一个文件夹“Jars”,并将 ePos-Prin.jar 文件复制到其中,选项 EmbeddedJar构建操作

在我的 Android 项目中,我将 .so 文件( native 库)放在“jni/armeabi”文件夹树中,并将构建操作选择为 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();
}
}
}
}

有人可以帮助我吗?

最佳答案

我没有 Epson USB 打印机,但我在各种打印机上尝试了以下简单代码,我可以告诉你它是有效的。看看您是否可以以某种方式创建一个您想要打印的文件,然后尝试下面这个简单的方法,也许它也适用于该打印机:

public void print () {
Desktop desktop = Desktop.getDesktop();
try {
desktop.print(new File("Docfile.pdf"));
} catch (IOException e) {
e.printStackTrace();
}
}

关于c# - Epson TM-U220 USB 打印错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30575144/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com