Connecting reader devices

AgentCASH SDK for Windows supports following reader interfaces:

  • Bluetooth
  • Wi-Fi
  • USB

The reader needs to be specified during PgClient initialization:

var cfg = new Configuration
    ApiKey = API_KEY,
    Username = "<your username>", // optional
    Password = "<your password>", // optional
    Device = Devices.DefaultBluetoothReader // specify reader here

var device = await pgClient.Initialize(cfg); // this returns selected device

Configuration.Device property specifies which reader will be used. By default, it is set to Devices.LastUsed - the same reader which was used for previous session.

Bluetooth readers

This is the simplest approach. You need to pair the reader with your device (computer, tablet, etc) using standard Bluetooth device pairing procedure.

If you are using the AgentCASH reader, then you only need to specify:

cfg.Device = Devices.DefaultBluetoothReader;

This will automatically pick a Bluetooth device with name starting with “Agent”.

If you have other Bluetooth reader, you can list bluetooth devices and select the one you want:

var bt_devices = await Devices.FindBluetoothDevicesAsync();
cfg.Device = bt_devices.First(dev => dev.Name == "MyReader");

Wi-Fi readers

In order to connect a reader which uses your Wi-Fi network, you need to know the readers IP address and port. Then you select it like this:

cfg.Device = Devices.NetworkedDevice("", 8032);

USB readers

NOTE: USB connection is at the moment supported only on .NET framework and not on UWA/UWP.

When connecting a reader via USB port, you are actually using serial port emulation over USB. The reader will have a virtual COM port assigned (e.g. COM7). The information about the assigned port can be found inside Ports section of Windows Device Manager.

The AgentCASH reader will typically be listed as ‘PI over USB serial’ or something similar.

You can use the port name to connect the reader:

cfg.Device = Devices.SerialDevice("COM7");

Available serial ports can be enumerated like this:

var devices = await Devices.FindSerialDevicesAsync();

SerialDevice class provides some additional configuration parameters which might be useful, depending on your setup. However, default settings should work for most system.

var device =  Devices.SerialDevice("COM7");
device.BaudRate = 14400;
device.DataBits = 1;
device.StopBits = System.IO.Ports.StopBits.One;
device.Parity = System.IO.Ports.Parity.None;
device.Handshake = System.IO.Ports.Handshake.None;
cfg.Device = device;