154
1.18.6.2.3.2 Example 2: Motor does move (return = true)
Status:
Hex: 380086
Dec: 3670150
Binary:
0011
1000
23-20 19-16 15-12 11-08 07-04 03-00 => bit 2 is 1
(status & motorRunning) = 4 => return true
1.18.6.2.3.3 Example 3: Something a little more complex This shows a more complex piece of code of how
the motor focus can be used.
#ifdef _MSC_VER
#
include <windows.h>
#else
#
include <time.h>
#endif
#include <apps/Common/exampleHelper.h>
#include <iostream>
#include <iomanip>
#include <mvIMPACT_CPP/mvIMPACT_acquire.h>
#include <typeinfo>
using namespace
std;
// This whole sample shows the low level access to the focus motor. For some
// of the functions presented here, there are also convenience functions in
// 'mvIMPACT::acquire::MotorFocusControl'
//-----------------------------------------------------------------------------
static
void
millisleep(
//-----------------------------------------------------------------------------
{
#ifdef _MSC_VER
Sleep( millisec );
#else
timespec requested;
requested.tv_sec = millisec / 1000;
requested.tv_nsec = ( millisec % 1000 ) * 1000000L;
nanosleep( &requested, NULL );
#endif
}
//-----------------------------------------------------------------------------
class
MotorControl
//-----------------------------------------------------------------------------
{
private:
const
MotorFocusControl mfc;
const
string
version;
// private, so as to hide the command strings from the outside world
TDMR_ERROR write(
const
{
mfc.motorFocusSendBuffer.writeS( command );
const
TDMR_ERROR retval = static_cast<TDMR_ERROR>( mfc.motorFocusSend.call() );
#if _DEBUG
if( retval != DMR_NO_ERROR )
{
cerr «
"Call to command '"
«
"'"
« endl;
}
#endif
return
retval;
}
void
waitForCommandReceipt(
{
const
size_t
length = expectedReply.length();
string
reply;
while( ( ( reply = getReply() ).length() < length ) ||
( reply.length() == length && reply != expectedReply ) ||
( reply.length() > length && reply.substr( 0, length ) != expectedReply ) )
{
cout «
"Waiting for confirmation of command "
reply «
")"
« endl;
}
}
TDMR_ERROR writeConfirmed(
{
const
TDMR_ERROR retval = write( command );
if( retval == DMR_NO_ERROR )
{
waitForCommandReceipt( command.substr( 0, 3 ) );
}
return
retval;
}
0000
0000
1000
0110
long
millisec )
string& command )
const
« command «
const
string& expectedReply )
const
string& command )
"' failed with error '"
const
« expectedReply.substr( 1, length - 1 ) «
const
« DMR_ErrorCodeToString( retval )
MATRIX VISION GmbH
" ("
«
Need help?
Do you have a question about the MATRIX VISION mvBlueFOX Series and is the answer not in the manual?