我正在尝试使用此处的驱动程序和SDK连接到我的.NET UWP应用程序中的EPSON ePOS t88V打印机:https://download.epson-biz.com/modules/pos/index.php?page=prod&pcat=3&pid=36
我已将官方UWP示例应用程序(https://download.epson-biz.com/modules/pos/index.php?page=single_soft&cid=5592&pcat=3&pid=36)部署到POS,但应用程序无法发现打印机。
然后,我尝试构建一个最小的应用程序,遵循用户手册中的代码片段:
using System;
...
using Epson.Epos.Epos2;
using Epson.Epos.Epos2.Printer;
namespace PrinterTest1
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
Printer printer = null;
PrinterStatusInfo status = null;
public MainPage()
{
InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
try
{
printer = new Printer(Series.TM_T88, ModelLang.Ank);
printer.Received += Printer_Received;
printer.AddText("Deeeeerp.");
await printer.ConnectAsync("TCP:10.10.10.133", Printer.PARAM_DEFAULT); //this line throws an exception
await printer.BeginTransactionAsync();
await printer.SendDataAsync(Printer.PARAM_DEFAULT);
}
catch (Exception ex)
{
}
}
private void Printer_Received(Printer sender, ReceivedEventArgs args)
{
DoStuff();
}
private async void DoStuff()
{
try
{
status = printer.GetStatusAsync().GetResults();
if (status.Connection == Connection.True && status.Online == Online.True)
{
await printer.SendDataAsync(Printer.PARAM_DEFAULT);
}
}
catch (Exception ex)
{
}
}
}
}
但我仍然无法连接到打印机。我得到了这个例外:
{System.Exception:来自HRESULT的异常:0xA0048201 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在System.Runtime.CompilerServices.TaskAwaiter.GetResult()
在PrinterTest1.MainPage.d__3.MoveNext()}
答案 0 :(得分:0)
这使您可以连接到网络打印机。
答案 1 :(得分:0)
查看此代码 当然,在安装打印机SDK之后
Printer printer = null;
try
{
printer = new Printer(Series.TM_T82, ModelLang.Ank);
printer.Received += Printer_Received;
printer.Buffer(order);
// Connect to printer through wifi
// Find printer from MAC address
await printer.ConnectAsync("TCP:64:EB:8C:2C:5B:4F", Printer.PARAM_DEFAULT);
await printer.BeginTransactionAsync();
// Send data to the printer
PrinterStatusInfo status = await printer.GetStatusAsync();
if (status.Connection == Connection.True && status.Online == Online.True)
{
await printer.SendDataAsync(Printer.PARAM_DEFAULT);
}
// Haven't figure out issue:
// If not delayed an ERR_PROCESSING is caught
await Task.Delay(1500);
//
await printer.EndTransactionAsync();
await printer.DisconnectAsync();
}
catch (Exception ex)
{
foreach (PropertyInfo prop in typeof(ErrorStatus).GetProperties())
{
if((int)prop.GetValue(null) == ex.HResult)
{
throw new Exception(prop.Name);
}
}
throw new Exception(ex.Message);
}
printer.ClearCommandBuffer();
printer.Received -= Printer_Received;
printer = null;
// Form a receipt from given order to the printer data buffer
public static void Buffer(this Printer printer, Order order)
{
// Receipt header
printer.AddTextAlign(Alignment.Center);
printer.AddTextSize(2, 1);
printer.AddText("MALAY PARLOUR\n");
printer.AddTextSize(Printer.PARAM_DEFAULT, Printer.PARAM_DEFAULT);
printer.AddText("234 PONSONBY RD, AUCKLAND\n");
printer.AddText("GST No: 106-338-302\n\n");
// Order time e.g. 01-01-2017 15:15
printer.AddText(String.Format("{0:dd}-{0:MM}-{0:yyyy} {0:HH}:{0:mm}\n", order.OrderDate));
// Print order details
foreach (OrderDetail od in order.OrderDetails)
{
printer.AddTextAlign(Alignment.Left);
// e.g. 2 * Seafood Laksa $16.50
printer.AddText(String.Format("{0,6} * {1,-22} {2,10:C2}\n",
od.Quantity,
od.Product.ProductName,
od.UnitPrice * od.Quantity));
// If item has remarks, add remarks in a new line
if (!String.IsNullOrEmpty(od.Remarks))
{
printer.AddText("\t" + od.Remarks + "\n");
}
printer.AddText("\n");
}
printer.AddTextAlign(Alignment.Right);
// If order has discount, print subtotal and discount
if (order.Discount != 0)
{
printer.AddText(String.Format("Subtotal: ${0:f2}\n", order.Subtotal));
printer.AddText(String.Format("Discount: {0:P2}\n", order.Discount));
}
// Print total. e.g. EftPos: $38.00
printer.AddTextSize(2, 1);
printer.AddText(String.Format("{0}: ${1:f2}\n\n", order.Payment, order.Total));
// Order footer
printer.AddTextAlign(Alignment.Center);
printer.AddTextSize(Printer.PARAM_DEFAULT, Printer.PARAM_DEFAULT);
printer.AddText("www.malayparlour.co.nz\n\n\n");
// Add a cut
printer.AddCut(Cut.Default);
}
private static void Printer_Received(Printer sender, ReceivedEventArgs args)
{
string callbackCode = Enum.GetName(typeof(CallbackCode), args.Code);
if (callbackCode.Contains("Error"))
{
throw new Exception(callbackCode);
}
}
答案 2 :(得分:0)
请检查是否在Package.appxmanifest上启用了必需的设备功能。 所需的功能取决于如何连接到打印机(几乎是“ Internet(客户端和服务器)”或“蓝牙”)。 https://docs.microsoft.com/ja-jp/windows/uwp/devices-sensors/enable-device-capabilities