This example shows how we can setup an advanced control flow for a sequence of experiments. For simplicity we will be using an incremented integer as an external condition to control the workflow. This logic can be replaced with any sort of logic pertaining to external instruments, sensors, or any other conditions.
#include "AisExperiment.h"
#include "AisDeviceTracker.h"
#include "AisInstrumentHandler.h"
#include "experiments/builder_elements/AisConstantCurrentElement.h"
#include "experiments/builder_elements/AisConstantPotElement.h"
#include <QCoreApplication>
#include <QTimer>
#include <qdebug.h>
int main()
{
char** test = nullptr;
int args;
QCoreApplication a(args, test);
5,
1,
10
);
0.002,
1,
10
);
auto experimentA = std::make_shared<AisExperiment>();
experimentA->appendElement(cvElement, 1);
auto experimentB = std::make_shared<AisExperiment>();
experimentB->appendElement(ccElement, 1);
auto experimentC = std::make_shared<AisExperiment>();
experimentC->appendElement(cvElement, 2);
QTimer* timer1 = new QTimer();
timer1->setSingleShot(true);
timer1->start(1000);
QObject::connect(timer1, &QTimer::timeout, [=]() {
qDebug() << "Initial condition met. Starting Experiment A ";
handler->uploadExperimentToChannel(0, experimentA);
handler->startUploadedExperiment(0);
static int experimentStep = 0;
qDebug() << "Experiment Step " << experimentStep << " Completed";
experimentStep++;
if (experimentStep == 1) {
QTimer* timer = new QTimer();
timer->setSingleShot(true);
timer->start(10000);
QTimer* StopEarlyTimer = new QTimer();
StopEarlyTimer->setSingleShot(true);
QObject::connect(StopEarlyTimer, &QTimer::timeout, [&]() {
qDebug() << "External early stop condition met";
handler->stopExperiment(0);
});
QObject::connect(timer, &QTimer::timeout, [&, StopEarlyTimer]() {
qDebug() << "External condition met, starting experiment B";
handler->uploadExperimentToChannel(0, experimentB);
handler->startUploadedExperiment(0);
StopEarlyTimer->start(2000);
});
} else if (experimentStep == 2) {
QTimer* timer = new QTimer();
timer->setSingleShot(true);
timer->start(10000);
QObject::connect(timer, &QTimer::timeout, [&]() {
qDebug() << "External condition met, starting Experiment C ";
handler->uploadExperimentToChannel(0, experimentC);
handler->startUploadedExperiment(0);
});
} else if (experimentStep == 3) {
QTimer* timer = new QTimer();
timer->setSingleShot(true);
timer->start(10000);
QObject::connect(timer, &QTimer::timeout, [&]() {
qDebug() << "External condition met, starting Experiment B ";
handler->uploadExperimentToChannel(0, experimentB);
handler->startUploadedExperiment(0);
});
}
});
});
};
auto& handler = tracker->getInstrumentHandler(deviceName);
createLogic(&handler);
});
qDebug() << deviceName << "is disconnected ";
});
AisErrorCode error = tracker->connectToDeviceOnComPort(
"COM18");
if (error != error.Success) {
qDebug() << error.message();
}
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
void deviceDisconnected(const QString &deviceName)
a signal to be emitted whenever a device has been disconnected.
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 class contains the possible error codes returned to the user when working with the API....
Definition AisErrorCode.h:18
this class provides control of the device including starting, pausing, resuming and stopping an exper...
Definition AisInstrumentHandler.h:27
void experimentStopped(uint8_t channel, const QString &reason)
a signal that is emitted whenever an experiment was stopped manually or has completed.