CsiTest.cpp
CSI API example.The following example shows how to use the CSI API from application code.
//============================================================================
// (c) Copyright 2013, CETONI GmbH
//
/// \file CsiTest.cpp
/// \author Uwe Kindler (UK)
/// \date 2010/05/27
/// \brief CSI example application
///
/// Example application that shows how to use the CSI API.
//===========================================================================
//===========================================================================
// INCLUDES
//===========================================================================
#include <iostream>
#include <stdint.h>
#include "csi_api.h"
using namespace std;
//===========================================================================
// LOCAL DATA
//===========================================================================
/**
* 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
}
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
// 38400 and a timeout value of 100 ms
//
showError(Result);
//
// If the port is open, we initialize the device object CsiDev. Normally
// this does not require any serial communication
//
showError(Result);
//
// Now read the value of the object dictionary entry with index 0x1000 and
// sub index 0 into the data buffer provided in Data parameter. Then print
// the read value for debugging purposes.
//
uint32_t Data;
showError(Result);
{
std::cout << "CsiDevReadObject(&CsiDev, 0x1000): "
<< std::hex << Data << std::dec << std::endl;
}
//
// Now read the value of the object dictionary entry with index 0x200C and
// sub index 1 into the data buffer provided in Data parameter. Then print
// the read value for debugging purposes.
//
Result = CsiDevReadObject(&CsiDev, 0x200C, 1, &Data);
showError(Result);
std::cout << "RxData: " << std::hex << Data << std::dec << std::endl;
//
// Now write defined data to the object dictionary entry we have just read
//
Data = 0x12345678;
showError(Result);
//
// Now read back the value of the object dictionary entry to check if value
// has been written successfully.
//
Result = CsiDevReadObject(&CsiDev, 0x200C, 1, &Data);
showError(Result);
std::cout << "RxData: " << std::hex << Data << std::dec << std::endl;
//
// Before we leave the application we call CsiClose() to close the serial
// connection an free any claimed resources.
//
showError(Result);
return 0;
}