question

david avatar image
david asked blake answered

Why does remote-pay-windows CloverConnector.Sale() return -1?

I have to add a delay to get this simple program to work:

class Program : CloverConnectorListener
{
    CloverDeviceConfiguration cloverDeviceConfiguration;
    CloverConnector cloverConnector;

    Program()
    {
        cloverDeviceConfiguration = new TestCloverDeviceConfiguration();
        cloverConnector = new CloverConnector(cloverDeviceConfiguration);
        cloverConnector.AddCloverConnectorListener(this);
        **Thread.Sleep(5000);**
    }

    public int Sale(long amount) {
        SaleRequest saleRequest = new SaleRequest();
        saleRequest.Amount = amount;
        return cloverConnector.Sale(saleRequest);
    }

    static void Main(string[] args)
    {
        Console.WriteLine(new Program().Sale(7500));
        Console.ReadKey();
    }

See the bolded Thread.Sleep() for 5 seconds after creating the Connector and adding myself as a listener? If I take that out, calling Sale() simply returns -1 and nothing happens: no call to OnSaleResponse() in my listener. But nothing else is being called in the listener as far as I can tell. What do I need to do to get properly set up so that Sale() works without the delay?

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

blake avatar image
blake answered

it returns -1 because it hasn't initialized the device connection yet. You should get an OnDeviceReady(...) callback when it is ready to communicate. The sleep is giving it time to initialize the connection on both sides.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community