Loading...
Searching...
No Matches
advancedExperiment.cpp
#include "AisDeviceTracker.h"
#include "AisExperiment.h"
#include "AisInstrumentHandler.h"
#include "experiments/builder_elements/AisOpenCircuitElement.h"
#include "experiments/builder_elements/AisConstantPotElement.h"
#include "experiments/builder_elements/AisEISGalvanostaticElement.h"
#include "experiments/builder_elements/AisConstantCurrentElement.h"
#include <QCoreApplication>
#include <QDebug>
// Define relevant device information, for easy access
#define COMPORT "COM5"
#define CHANNEL 0
#define INSTRUMENT_NAME "PLus1366"
int main()
{
char** test = nullptr;
int args;
QCoreApplication a(args, test);
auto tracker = AisDeviceTracker::Instance();
bool success = true;
auto customExperiment = std::make_shared<AisExperiment>();
AisOpenCircuitElement ocpElement(1, 10);
success &= customExperiment->appendElement(ocpElement);
int voltage = 0;
for (int i = 0; i < 4; i++) {
AisConstantPotElement cvElement(voltage, 0.1, 5);
success &= customExperiment->appendElement(cvElement, 1);
voltage += 0.1; // Adding 100 mV
}
AisExperiment eisSubExperiment;
AisEISGalvanostaticElement galvEISElement(10, 10000, 10, 0.01, 0.1);
AisOpenCircuitElement ocpElement2(1, 5);
success &= eisSubExperiment.appendElement(galvEISElement, 1);
success &= eisSubExperiment.appendElement(ocpElement2, 1);
success &= customExperiment->appendSubExperiment(eisSubExperiment, 3);
AisConstantCurrentElement ccElement(0.1, 1, 10);
success &= customExperiment->appendElement(ccElement, 2);
if (!success) {
qDebug() << "Error building experiment";
return 0;
}
auto connectSignals = [=](const AisInstrumentHandler& handler) {
QObject::connect(&handler, &AisInstrumentHandler::activeDCDataReady, [=](uint8_t channel, const AisDCData& data) {
qDebug() << "Timestamp: " << data.timestamp << " Current: " << data.current << " Voltage: " << data.workingElectrodeVoltage << " CE Voltage : " << data.counterElectrodeVoltage;
});
QObject::connect(&handler, &AisInstrumentHandler::experimentNewElementStarting, [=](uint8_t channel, const AisExperimentNode& info) {
qDebug() << "New element starting: " << info.stepName;
});
QObject::connect(&handler, &AisInstrumentHandler::experimentStopped, [=](uint8_t channel, const QString& reason) {
qDebug() << "Experiment Stopped Signal " << channel << "Reason : " << reason;
});
QObject::connect(&handler, &AisInstrumentHandler::deviceError, [=](uint8_t channel, const QString& error) {
qDebug() << "Device Error: " << error;
});
};
// When device is connected, setup connections, and upload/start the experiment
QObject::connect(tracker, &AisDeviceTracker::newDeviceConnected, [=](const QString& deviceName) {
qDebug() << "New Device Connected: " << deviceName;
auto& handler = tracker->getInstrumentHandler(INSTRUMENT_NAME);
connectSignals(handler);
AisErrorCode error = handler.uploadExperimentToChannel(CHANNEL, customExperiment);
if (error) {
qDebug() << error.message();
return 0;
}
error = handler.startUploadedExperiment(CHANNEL);
if (error) {
qDebug() << error.message();
return 0;
}
});
AisErrorCode error = tracker->connectToDeviceOnComPort(COMPORT);
if (error != error.Success) {
qDebug() << error.message();
return 0;
}
return a.exec();
}
an experiment that simulates a constant current flow with more advance options for stopping the exper...
Definition AisConstantCurrentElement.h:18
an experiment that simulates a constant applied voltage.
Definition AisConstantPotElement.h:18
static AisDeviceTracker * Instance()
get the instance of the device tracker.
void newDeviceConnected(const QString &deviceName)
a signal to be emitted whenever a new connection has been successfully established with a device.
This experiment records the complex impedance of the experimental cell in galvanostatic mode,...
Definition AisEISGalvanostaticElement.h:23
This class contains the possible error codes returned to the user when working with the API....
Definition AisErrorCode.h:18
this class is used to create custom experiments. A custom experiment contains one or more elements....
Definition AisExperiment.h:22
this class provides control of the device including starting, pausing, resuming and stopping an exper...
Definition AisInstrumentHandler.h:27
void deviceError(uint8_t channel, const QString &error)
a signal that is emitted whenever device send any critical error.
void activeDCDataReady(uint8_t channel, const AisDCData &DCData)
a signal that is emitted whenever new DC data for an active experiment are ready.
void experimentNewElementStarting(uint8_t channel, const AisExperimentNode &stepInfo)
a signal that is emitted whenever a new elemental experiment has started.
void experimentStopped(uint8_t channel, const QString &reason)
a signal that is emitted whenever an experiment was stopped manually or has completed.
This experiment observes the open circuit potential of the working electrode for a specific period of...
Definition AisOpenCircuitElement.h:18
A structure containing DC data collected from the instrument.
Definition AisDataPoints.h:11
A structure containing some information regarding the running element.
Definition AisDataPoints.h:113
QString stepName
This is the name of the current element running.
Definition AisDataPoints.h:118