خرید بک لینک

Vote count: 0

I'm writing an application that uses Pos for .Net, and I'm noticing that if you call WaitForDrawerClose, then you won't be able to print receipts until it has retued.

This is not desirable behavior. Is there another way to wait for the cash drawer to close without blocking the printer?

I've looked into the OnDrawerStateChanged Event, but that is a protected member of CashDrawerBase, and I'm not entirely sure how to access it.

Here is my SSCCE:

static void Main(string[] args)
{
    var posExplorer = new PosExplorer();
    var waitTask = WaitForCloseAsync(posExplorer);
    System.Threading.Thread.Sleep(500);
    PrintText(posExplorer);
    waitTask.Wait();
}

public static Task WaitForCloseAsync(PosExplorer posExplorer)
{
    var result = Task.Factory.StartNew(() =>
    {
        Console.WriteLine("waiting");
        var cashDrawer = GetCashDrawer(posExplorer);
        cashDrawer.Open();
        cashDrawer.Claim(1000);
        cashDrawer.DeviceEnabled = true;
        cashDrawer.WaitForDrawerClose(10000, 4000, 500, 5000);
        cashDrawer.Release();
        cashDrawer.Close();
        Console.WriteLine("waited");
    });
    retu result;
}

public static void PrintText(PosExplorer posExplorer)
{
    Console.WriteLine("printing");
    var printer = GetPosPrinter(posExplorer);
    printer.Open();
    printer.Claim(1000);
    printer.DeviceEnabled = true;
    var text = "abcx1B|1lF";
    printer.PrintNormal(PrinterStation.Receipt, text);
    printer.Release();
    printer.Close();
    Console.WriteLine("printed");
}

public static CashDrawer GetCashDrawer(PosExplorer posExplorer)
{
    var deviceInfo = posExplorer.GetDevices(DeviceCompatibilities.Opos)
        .Cast<DeviceInfo>()
        .Where(d => d.Type == "CashDrawer")
        .ToList();

    var device = deviceInfo.FirstOrDefault(d => d.Compatibility == DeviceCompatibilities.Opos);

    if (device == null)
    {
        retu null;
    }
    else
        retu (CashDrawer)posExplorer.CreateInstance(device);
}

private static PosPrinter GetPosPrinter(PosExplorer posExplorer)
{
    var deviceInfo = posExplorer.GetDevices(DeviceCompatibilities.Opos)
        .Cast<DeviceInfo>()
        .Where(d => d.Type == "PosPrinter")
        .ToList();

    var device = deviceInfo.FirstOrDefault(d => d.Compatibility == DeviceCompatibilities.Opos);

    if (device == null)
    {
        retu null;
    }
    else
    {
        retu (PosPrinter)posExplorer.CreateInstance(device);
    }
}

asked 5 mins ago

برچسب: نویسنده: استخدام کار تاريخ: جمعه 7 خرداد 1395 ساعت: 0:01

صفحه بندی