我正在尝试从我的ePOS UWP应用程序连接到爱普生t88V打印机,使用在这里找到的驱动程序和SDK:https://download.epson-biz.com/modules/pos/index.php?page=prod&pcat=3&pid=36。
我已经部署了正式的UWP示例应用程序(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.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task任务下的System.Exception: System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task任务下的异常)( System.Runtime.CompilerServices.TaskAwaiter.GetResult() ) 在PrinterTest1.MainPage.d__3.MoveNext()}
发布于 2018-07-11 19:00:02
这允许您连接到网络打印机。
发布于 2018-07-12 14:24:06
当然,在安装打印机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);
}
}发布于 2019-01-16 13:21:10
请检查Package.appxmanifest上启用了所需的设备功能。所需的功能取决于如何连接到打印机(几乎是"Internet (客户机和服务器)“或”蓝牙“)。https://learn.microsoft.com/ja-jp/windows/uwp/devices-sensors/enable-device-capabilities
https://stackoverflow.com/questions/47224273
复制相似问题