NemTest.cpp

The example shows how to use the Nemesys V1 API from application code.

//============================================================================
/// \file main.cpp
/// \author Uwe Kindler
/// \date 25.06.2013
/// \brief Test of neMESYS RS232 API
//============================================================================
//============================================================================
// INCLUDES
//============================================================================
#include <iostream>
#include "nem_rs232_api.h"
using namespace std;
//===========================================================================
// LOCAL DATA
//===========================================================================
static TNemesys Nemesys1;
static struct CsiBus CsiBus;
/**
* Print error code and error description via CsiErrorToString() to std::out
*/
long showError(long ErrCode)
{
if (ErrCode < 0)
{
std::cout << "Error code: " << std::hex << (0 - ErrCode) << std::dec
<< " - " << CsiErrorToString(ErrCode) << std::endl;
}
return ErrCode;
}
/**
* Application main entry point
*/
int main(int argc, char *argv[])
{
//
// First open the serial port 1 (on Windows COM1) with a baudrate of
// 115200 and a timeout value of 100 ms
//
long Result = CsiOpen(&CsiBus, "COM1", CSI_BAUD_115200, 100);
showError(Result);
//
// If the port is open, we initialize the device object Nemesys1.
//
Result = NemDevInit(&CsiBus, 2, &Nemesys1);
showError(Result);
/**
* Ensure that device is not in fault state after power up
*/
Result = NemClearFault(&Nemesys1);
showError(Result);
/**
* Set neMESYS device into enabled state - power is applied to power
* stage
*/
Result = NemSetEnabled(&Nemesys1);
showError(Result);
/**
* Execute calibration move with 1.000.000 mrpm
*/
Result = NemCalibrate(&Nemesys1, 1000000);
showError(Result);
CSI_SLEEP_MS(100);// give drive some time to start
/**
* Poll the device until calibration has been finished
*/
do
{
Result = NemIsCalibrationFinished(&Nemesys1);
CSI_SLEEP_MS(100);// do not block CPU
} while (0 == Result);
showError(Result);
/**
* Dose a certain volume with a certain flow. See manual to read how to
* convert between flow / volume and speed / position values
*/
Result = NemDoseVolume(&Nemesys1, -204800, 1000000);
showError(Result);
CSI_SLEEP_MS(100);// give drive some time to start
/**
* Poll the device until dosing has been finished
*/
do
{
Result = NemIsDosingFinished(&Nemesys1);
CSI_SLEEP_MS(100);// do not block CPU
} while (0 == Result);
showError(Result);
Result = CsiClose(&CsiBus);
showError(Result);
return 0;
}
//---------------------------------------------------------------------------
// EOF main.c