The source code shows the implementation of the neMESYS contiflow C-API test. The test uses all continuous flow specific functions and shows how to create a continuous flow pump, how to parameterize it and how to use it.
#include <chrono>
#include <vector>
#include <labbcan/common/labbcan_test_helpers.h>
#include <usl/core/Thread.h>
#include <usl/core/PollingTimer.h>
#include <usl/math/uslmath.h>
#include <log4cplus/logger.h>
#include <diag/diag.h>
using namespace Usl;
#define BOOST_TEST_MODULE capi_contiflow_test
#include <boost/test/unit_test.hpp>
long Result;
BOOST_AUTO_TEST_CASE(testCapiOpen)
{
Result =
LCB_Open(
"config/contiflow", 0);
}
BOOST_AUTO_TEST_CASE(testBusStart)
{
}
BOOST_AUTO_TEST_CASE(testContiFlowPumpConstruction)
{
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
}
BOOST_AUTO_TEST_CASE(testContiFlowPumpConfiguraion)
{
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
}
void setupContiFlowParameters(
dev_hdl ContiFlowPump,
double CrossFlowSecs)
{
REQUIRE_ERR_NOERR(Result);
double MaxRefillFlow;
REQUIRE_ERR_NOERR(Result);
BOOST_TEST_MESSAGE("MaxRefilFlow: " << MaxRefillFlow);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
double MaxContiFlowRate;
REQUIRE_ERR_NOERR(Result);
BOOST_TEST_MESSAGE("MaxContiFlowRate: " << MaxContiFlowRate);
}
BOOST_AUTO_TEST_CASE(testContiFlowParameters)
{
setupContiFlowParameters(ContiFlowPump1, 2);
}
bool waitCalibrationFinished(
dev_hdl hPump, uint32_t TimeoutSeconds)
{
CPollingTimer Timer(TimeoutSeconds * 1000);
do
{
CThread::sleep(100);
}
while ((0 == Result) && !Timer.isExpired());
return (Result > 0);
}
bool waitInitializationFinished(
dev_hdl hPump, uint32_t TimeoutSeconds)
{
CPollingTimer Timer(TimeoutSeconds * 1000);
do
{
CThread::sleep(100);
}
while ((1 == Result) && !Timer.isExpired());
return (Result > 0);
}
BOOST_AUTO_TEST_CASE(testContiFlowEnable)
{
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
}
BOOST_AUTO_TEST_CASE(testContiFlowInit)
{
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
bool CalibrationFinished = waitCalibrationFinished(SyringePump0, 30);
BOOST_CHECK(CalibrationFinished);
CalibrationFinished = waitCalibrationFinished(SyringePump1, 30);
BOOST_CHECK(CalibrationFinished);
REQUIRE_ERR_NOERR(Result);
bool InitializationFinished = waitInitializationFinished(ContiFlowPump1, 30);
BOOST_REQUIRE(InitializationFinished);
}
BOOST_AUTO_TEST_CASE(testContiFlow)
{
double MaxContiFlowRate;
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
BOOST_TEST_MESSAGE("Starting flow with flow rate: " << MaxContiFlowRate);
CPollingTimer Timer(30 * 1000);
do
{
CThread::sleep(1000);
double CurrentFlow;
BOOST_TEST_MESSAGE("Current flow rate: " << CurrentFlow
<< " Remaining seconds: " << Timer.msecsToExpiration() / 1000);
}
while (!Timer.isExpired());
BOOST_TEST_MESSAGE("Starting flow with flow rate: " << MaxContiFlowRate / 2);
Timer.setPeriod(34 * 1000);
Timer.restart();
REQUIRE_ERR_NOERR(Result);
do
{
CThread::sleep(1000);
double CurrentFlow;
BOOST_TEST_MESSAGE("Current flow rate: " << CurrentFlow
<< " Remaining seconds: " << Timer.msecsToExpiration() / 1000);
}
while (!Timer.isExpired());
REQUIRE_ERR_NOERR(Result);
CThread::sleep(1000);
}
BOOST_AUTO_TEST_CASE(testDeviceLookup)
{
REQUIRE_ERR_NOERR(Result);
setupContiFlowParameters(ContiFlowPump2, 1);
REQUIRE_ERR_NOERR(Result);
if (0 == Result)
{
REQUIRE_ERR_NOERR(Result);
}
}
BOOST_AUTO_TEST_CASE(testContiFlowVolumeDosing)
{
dev_hdl ContiFlowPump = ContiFlowPump2;
REQUIRE_ERR_NOERR(Result);
double MaxSyringeLevel;
REQUIRE_ERR_NOERR(Result);
double MaxContiFlowRate;
REQUIRE_ERR_NOERR(Result);
double TargetVolume = MaxSyringeLevel * 1.5;
Result =
LCP_PumpVolume(ContiFlowPump, TargetVolume, MaxContiFlowRate);
REQUIRE_ERR_NOERR(Result);
CPollingTimer Timer(60 * 1000);
do
{
CThread::sleep(1000);
double DosedVolume;
BOOST_TEST_MESSAGE("Dosed volume: " << DosedVolume << " Target volume: " << TargetVolume);
}
while (1 == Result && !Timer.isExpired());
}
BOOST_AUTO_TEST_CASE(testCapiClose)
{
}