capi_nemesys4_test.cpp
This example shows and tests features of the new Nemesys 4 pumps.
//============================================================================
/// \file capi_nemesys_test.cpp
/// \author Uwe Kindler
/// \date 11.07.2012
/// \brief Test of labbCAN pump API
//============================================================================
//============================================================================
// INCLUDES
//============================================================================
#include <chrono>
#include <vector>
#include <labbcan/c_api/labbCAN_Bus_API.h>
#include <labbcan/c_api/labbCAN_Pump_API.h>
#include <labbcan/c_api/labbCAN_MotionControl_API.h>
#include <labbcan/c_api/labbCAN_Valve_API.h>
#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>
#include "capi_tests_common.h"
using namespace Usl;
#define BOOST_TEST_MODULE capi_nemesys4_test
#include <boost/test/unit_test.hpp>
using namespace boost::unit_test;
/**
* Make available program's arguments to all tests, recieving
* this fixture.
*/
struct ArgsFixture {
ArgsFixture(): argc(framework::master_test_suite().argc),
argv(framework::master_test_suite().argv){}
int argc;
char **argv;
};
BOOST_GLOBAL_FIXTURE( ArgsFixture );
//============================================================================
// DATA TYPES
//============================================================================
//============================================================================
// GLOBAL DATA
//============================================================================
dev_hdl Nemesys;
long Result;
//============================================================================
// Open the labbCAN bus api and connect to device
//============================================================================
BOOST_FIXTURE_TEST_CASE(testCapiOpen, ArgsFixture)
{
using namespace boost::unit_test;
const char* ConfigPath = "config/testconfig_qmixsdk";
if (argc > 1)
{
ConfigPath = argv[1];
}
Result = LCB_Open(ConfigPath, 0);
CAPI_REQUIRE_ERR_NOERR(Result);
}
//============================================================================
// Checks if retrieval of pump devices works properly
//============================================================================
BOOST_AUTO_TEST_CASE(testDeviceNameLookup)
{
CAPI_REQUIRE_ERR_NOERR(Result);
}
//============================================================================
// Checks if start of bus and logging works properly
//============================================================================
BOOST_AUTO_TEST_CASE(testBusStart)
{
Result = LCB_Start();
CAPI_CHECK_ERR_NOERR(Result);
CAPI_CHECK_ERR_NOERR(Result);
}
//============================================================================
// Checks if enabling pumps works properly
//============================================================================
BOOST_AUTO_TEST_CASE(testPumpEnable)
{
Result = LCP_IsInFaultState(Nemesys);
CAPI_CHECK_ERR_NOERR(Result);
BOOST_CHECK_GT(Result, -1);
if (Result)
{
Result = LCP_ClearFault(Nemesys);
CAPI_CHECK_ERR_NOERR(Result);
}
Result = LCP_Enable(Nemesys);
CAPI_CHECK_ERR_NOERR(Result);
CThread::sleep(500);// give pump some time to process enable request
Result = LCP_IsEnabled(Nemesys);
CAPI_CHECK_ERR_NOERR(Result);
BOOST_CHECK_GT(Result, 0);
}
//============================================================================
// Checks if calibration functions return the right values
//============================================================================
BOOST_AUTO_TEST_CASE(testCalibration)
{
//
// Nemesys 4 devices such as Nemesys M and Nemesys S have an absolute
// encoder and this function should always return true
//
Result = LCP_IsPositionSensingInitialized(Nemesys);
CAPI_REQUIRE_ERR_NOERR(Result);
BOOST_REQUIRE_EQUAL(1, Result);
//
// Because of the absolute encoder a calibration move is not required and
// not supported for Nemesys 4 devices.
//
Result = LCP_SyringePumpCalibrate(Nemesys);
BOOST_REQUIRE_EQUAL(-ERR_DEVNOSUPP, Result);
char ExtendedError[128];
BOOST_TEST_MESSAGE("Error: " << ExtendedError);
//
// Because of the absolute encoder a restoring position counter value is
// not required and not supported for Nemesys 4 devices.
//
Result = LCP_RestoreDrivePosCnt(Nemesys, 0);
BOOST_REQUIRE_EQUAL(-ERR_DEVNOSUPP, Result);
LCB_GetExtendedLastErrorString(ExtendedError, sizeof(ExtendedError));
BOOST_TEST_MESSAGE("Error: " << ExtendedError);
}
//============================================================================
// Tests valve switching
//============================================================================
BOOST_AUTO_TEST_CASE(testValve)
{
dev_hdl Valve;
Result = LCP_HasValve(Nemesys);
CAPI_REQUIRE_ERR_NOERR(Result);
BOOST_REQUIRE_EQUAL(1, Result);
Result = LCP_GetValveHandle(Nemesys, &Valve);
CAPI_REQUIRE_ERR_NOERR(Result);
BOOST_REQUIRE_EQUAL(NumberOfValvePositions, 4);// Nemesys continuous flow valve support up to 4 positions (closed, port1, port2, open)
BOOST_TEST_MESSAGE("Number of valve positions: " << NumberOfValvePositions);
// Backup current valver position
BOOST_REQUIRE_GE(CurrentValvePosition, 0);
// Now cycle through all valve positions
for (int i = 0; i < NumberOfValvePositions; ++i)
{
Result = LCV_SwitchValveToPosition(Valve, i);
CAPI_CHECK_ERR_NOERR(Result);
CThread::sleep(1000);
}
// Restore old valve position
Result = LCV_SwitchValveToPosition(Valve, CurrentValvePosition);
CAPI_CHECK_ERR_NOERR(Result);
}
//============================================================================
// Checks if C-API can get closed properly
//============================================================================
BOOST_AUTO_TEST_CASE(testCapiClose)
{
Result = LCB_Stop();
CAPI_CHECK_ERR_NOERR(Result);
Result = LCB_Close();
CAPI_CHECK_ERR_NOERR(Result);
}
//---------------------------------------------------------------------------
// EOF capi_test.cpp