Connecting

The following chapter details how to connect, read data, set the potential, and properly close a connection to a device.

Connecting to a device

The following example shows how to get a list of all available devices and available serial com ports, and how to connect to one of the discovered devices that.

Add this namespace at the top of the document.

using PalmSens.Devices;

The first line returns an array of all the connected devices, and the second connects to the first device in the array of connected devices. When Bluetooth devices should also be discovered set psCommSimple.EnableBluetooth = true first.

Device[] devices = psCommSimple.ConnectedDevices;
psCommSimple.Connect(devices[0]);

Async functionality

When using the async commands without the simplified core wrappers you will need to initiate the synchronization context remover. We recommended to set the argument one lower than the amount of logical processor cores the CPU has unless it has a single core, for example:

var nCores = Environment.ProcessorCount;
SynchronizationContextRemover.Init(nCores > 1 ? nCores - 1 : 1);

Bluetooth

Discovery of Bluetooth devices is disabled by default, it can be enabled by setting the EnableBluetooth proprety to true.

psCommSimple.EnableBluetooth = true;

To be able to use Bluetooth in your project you should reference the 32.Feet.NET NuGet package in your project (https://www.nuget.org/packages/32feet.NET/). Bluetooth Classic works on all supported platforms (Windows 10+). Bluetooth Low Energy (BLE) only works on Windows 10+.

To enable BLE you should add references to the PalmSens.Core.Windows.BLE.dll library (included in the PSLibraries folder) in your project and the PalmSens.Core.Simplified project.

Finally, you will also need to respectively uncomment the following lines in the ScanDevices and the ScanDevicesAsync methods of the DeviceHandler class in the PalmSens.Core.Simplified project.

discFuncs.Add(BLEDevice.DiscoverDevices);
discFuncs.Add(BLEDevice.DiscoverDevicesAsync());

Receive idle status readings

The readings of PalmSens can be monitored continuously using the ReceiveStatus event. The status object that is received using this event contains the following information:

  • AuxInput: auxiliary input in V (Status.GetExtraValueAsAuxVoltage())

  • Current: in μA, (Status.CurrentReading.Value or Status.CurrentReading.ValueInRange)

  • Current2: in μA, in case a BiPot is used (Status.GetExtraValueAsBiPotCurrent())

  • Noise: Status.Noise

  • CurrentRange: the current range in use at the moment, Status.CurrentReading.CurrentRange

  • CurrentStatus: as PalmSens.Comm.ReadingStatus is OK, UNDERLOAD or OVERLOAD ( Status.CurrentReading.ReadingStatus)

  • Potential: measured potential, Status.PotentialReading.Value

  • ReverseCurrent: the reverse current for SquareWave (Status.ExtraValue)

  • PretreatmentPhaseStatus: None, Conditioning, Depositing or Equilibrating ( Status.PretreatmentPhase)

  • VoltageStatus: as PalmSens.Comm.ReadingStatus is OK, Underload or Overload (Status.PotentialReading.ReadingStatus) To get the device’s status updates subscribe to the ReceiveStatus event after connecting to a device.

psCommSimple.ReceiveStatus += PsCommSimple_ReceiveStatus;

The status is obtained from the event’s StatusEventArgs, e.g:.

private void psCommSimple_ReceiveStatus(object sender,
PalmSens.Comm.StatusEventArgs e) {
    Status status = e.GetStatus();
}

Manually controlling the device

Depending on your device’s capabilities it can be used to set a potential/current and to switch current ranges. The potential can be set manually in potentiostatic mode and the current can be set in galvanostatic mode. The following examples show how to manually set a potential.

The psCommSimple component must be connected to a device before you can set its potential and control the cell. To turn the cell off call psCommSimple.TurnCellOff().

psCommSimple.SetCellPotential(1f);
psCommSimple.TurnCellOn();

Device Capabilities

The capabilities of a connected device can either accessed via the CommManager.Capabilities or the psCommSimple.Capabilities property.

The DeviceCapabilities contains properties such as its maximum potential, supported current ranges and support for specific features (galvanostat/impedance/bipot).

The DeviceCapabilities can also be used to determine whether a certain method is compatible with a device using either method.Validate(DeviceCapabilities) or psCommSimple.ValidateMethod(method).