1
votes

I am trying to connect to an EPSON ePOS t88V printer from my .NET UWP application, using the drivers and SDK found here: https://download.epson-biz.com/modules/pos/index.php?page=prod&pcat=3&pid=36

I have deployed the official UWP sample app (https://download.epson-biz.com/modules/pos/index.php?page=single_soft&cid=5592&pcat=3&pid=36) to the POS, but the application wasn't able to discover the printer.

Then, I tried to build a minimal app, following the code snippets from the user manual:

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)
            {

            }
        }
    }
}

but I am still not being able to connect to the printer. I am getting this exception:

{System.Exception: Exception from HRESULT: 0xA0048201 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at PrinterTest1.MainPage.d__3.MoveNext()}

3
What is the exception you mentioned?kennyzx
@kennyzx I edited the question.Eutherpy
Your address looks ill formatted: “TCP://...”kennyzx
TCP:10.10.10.133 isn't valid. You're missing //user47589

3 Answers

0
votes

Take a look at the Universal Windows apps SDK

This allows you to connect to network printers.

0
votes

See this code Of course after installing the printer 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);
        }  
    }
0
votes

Please check required device capabilities are enabled on Package.appxmanifest. Required capabilities depend on how to connect to your printer (almost "Internet (Client & Server)" or "Bluetooth"). https://docs.microsoft.com/ja-jp/windows/uwp/devices-sensors/enable-device-capabilities