PressureAPI
Example
using System;
using Cytosurge;
public class Program
{
public static void Main(string[] args)
{
// Create a new PressureAPI object
using (PressureAPI device = new PressureAPI())
{
/*
* Connect to the device
* Print information about runtime errors to console if encountered
*/
device.Connect(ex => Console.WriteLine("The device experienced a runtime error: " + ex.ToString()));
// Read the supported pressure range
double min, max;
device.ReadPressureRange(out min, out max);
Console.WriteLine("Allowed range: [" + min + ";" + max + "] mbar");
// Set a pressure setpoint
device.SetPressure(max);
/*
* Give the device time to reach the pressure
* Then, read the active pressure
*/
System.Threading.Thread.Sleep(100);
double currentPressure = device.GetPressure();
Console.WriteLine("Current pressure: " + currentPressure + " mbar");
}
Console.ReadLine();
}
}
How to include
Note
This API only works on 64-bit systems.
Add Cytosurge.PressureAPI.dll
as a reference to your .NET project.
Cytosurge.PressureAPI.dll
is dependent on other assemblies.
To avoid any runtime errors due to missing dependencies, your program must include the following assemblies in its working directory.
You can find all of these assemblies in the directory where the software was installed (usually “C:\Program Files\Cytosurge\CORA”).
Cytosurge.Drivers.CytosurgePressureController.dll
Cytosurge.PressureAPI.dll
Cytosurge.Shared.dll
log4net.dll
protobuf-net.dll
WinUsbDriver.dll
Please make sure to disable the option Prefer 32-bit
in your project settings. Otherwise, your program will crash with a BadImageFormatException
.
API Overview
Constructors
public PressureAPI()
Creates a new PressureAPI object. The constructor accepts no arguments.
Delegate Types
public delegate void AsyncErrorHandler(Exception runtimeException);
This delegate is used to specify how runtime errors of the device should be handled.
Methods
Connect
public void Connect(AsyncErrorHandler asyncHandler)
Initializes a connection to the pressure device.
Parameter | Description |
---|---|
asyncHandler |
Callback that will be invoked if the device encounters an unrecoverable error |
Exception | Cause |
---|---|
BadImageFormatException |
Missing assemblies or wrong platform target |
InvalidOperationException |
Pressure device was already initialized |
InitializationException |
Invalid firmware status or boot error of pressure device |
Read Pressure Range
public void ReadPressureRange(out double minPressure, out double maxPressure)
Reads the pressure range from the device.
Parameter | Description |
---|---|
minPressure |
The minimum pressure in [mbar] the connected pressure device can produce |
maxPressure |
The maximum pressure in [mbar] the connected pressure device can produce |
Exception | Cause |
---|---|
InvalidOperationException |
Pressure device has not been initialized |
Get Pressure
public double GetPressure()
Reads the current pressure from the device and returns it as [mbar].
Exception | Cause |
---|---|
InvalidOperationException |
Pressure device has not been initialized |
Set Pressure
public void SetPressure(double pressure)
Sets a new target pressure. The pressure device needs a moment to adjust the pressure, so it is advised to wait after the method call (e.g. System.Threading.Thread.Sleep(100)
).
Parameter | Description |
---|---|
pressure |
The new pressure applied to the pressure device in [mbar] |
Exception | Cause |
---|---|
InvalidOperationException |
Pressure device has not been initialized |
ArgumentOutOfRangeException |
pressure is out of range |
Get Flow
public double GetFlow()
Reads the current flow from the device and returns it as [mbar].
Exception | Cause |
---|---|
InvalidOperationException |
Pressure device has not been initialized |
InvalidOperationException |
Pressure device does not support flow sensor |
Dispose
public void Dispose()
Disconnects from the device and cleans up any resources.