Loading...
Searching...
No Matches
basicExperiment.cpp
#include "AisDeviceTracker.h"
#include "AisExperiment.h"
#include "AisInstrumentHandler.h"
#include "experiments/builder_elements/AisConstantPotElement.h"
#include <QCoreApplication>
#include <QDebug>
// Define relevant device information, for easy access
#define COMPORT "COM1"
#define CHANNEL 0
int main()
{
char** test = nullptr;
int args;
QCoreApplication a(args, test);
auto tracker = AisDeviceTracker::Instance();
// Voltage = 1V, Sampling Interval = 1s, Duration = 30s
AisConstantPotElement cvElement(1, 1, 30);
auto customExperiment = std::make_shared<AisExperiment>();
// Append the constant potential element, and tell it to execute that element 1 time
customExperiment->appendElement(cvElement, 1);
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::activeACDataReady, [=](uint8_t channel, const AisACData& data) {
qDebug() << "Timestamp: " << data.timestamp << " Frequency: " << data.frequency << "" << data.absoluteImpedance;
});
// Whenever a new node in the element starts, note: some Ais Elements contain multiple logical nodes
// i.e AisCyclicVoltammatryElement contains 4 nodes for each linear segment of each cycle plus a quiet time node if enabled
// So this lambda would be executed atleast 4 times for each cycle
QObject::connect(&handler, &AisInstrumentHandler::experimentNewElementStarting, [=](uint8_t channel, const AisExperimentNode& info) {
qDebug() << "New element starting: " << info.stepName;
});
// Whenever an experiment completes or is manually stopped, this will execute
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;
});
};
QObject::connect(tracker, &AisDeviceTracker::deviceDisconnected, [=](const QString& deviceName) {
qDebug() << "New Device Connected: " << deviceName;
});
QObject::connect(tracker, &AisDeviceTracker::newDeviceConnected, [=](const QString& deviceName) {
qDebug() << "New Device Connected: " << deviceName;
auto& handler = tracker->getInstrumentHandler(deviceName);
connectSignals(handler);
AisErrorCode error = handler.uploadExperimentToChannel(CHANNEL, customExperiment);
if (error) {
qDebug() << error.message();
return;
}
// Start the previously uploaded experiment on the same channel
error = handler.startUploadedExperiment(CHANNEL);
// Exit the application if there is any error starting the experiment
if (error) {
qDebug() << error.message();
return;
}
});
AisErrorCode error = tracker->connectToDeviceOnComPort(COMPORT);
if (error != error.Success) {
qDebug() << error.message();
return 0;
}
// Returning a.axec() executes the event loop, which continues running until the application is exited
return a.exec();
}
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 activeACDataReady(uint8_t channel, const AisACData &ACData)
a signal that is emitted whenever new AC data for an active experiment are ready.
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.
A structure containing AC data collected from the instrument.
Definition AisDataPoints.h:44
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