Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
epos driver
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-tushevg committed Jan 2, 2019
1 parent 111f4b3 commit 9f9e63a
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 7 deletions.
8 changes: 8 additions & 0 deletions BrainATUMtome/BrainATUMtome.pro
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ FORMS += \
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

win32: LIBS += -L$$PWD/../libs/epos/lib/ -lEposCmd64

INCLUDEPATH += $$PWD/../libs/epos/include
DEPENDPATH += $$PWD/../libs/epos/include

macx: INCLUDEPATH += $$PWD/../libs/epos/macx
macx: LIBS += -L$$PWD/../libs/epos/macx -lepos
214 changes: 213 additions & 1 deletion BrainATUMtome/epos.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,220 @@
#include "epos.h"

Epos::Epos(QObject *parent) : QObject(parent)
Epos::Epos(QObject *parent) : QObject(parent),
m_keyHandle_lower(nullptr),
m_keyHandle_upper(nullptr),
m_nodeId(0),
m_errorCode(0)
{
// open motor interfaces
char portLower[] = "USB0";
char portUpper[] = "USB1";
m_keyHandle_lower = open(portLower);
m_keyHandle_upper = open(portUpper);

// set velocity mode
setVelocityMode(m_keyHandle_lower);
setVelocityMode(m_keyHandle_upper);
}


Epos::~Epos()
{
close(m_keyHandle_lower);
close(m_keyHandle_upper);
}


HANDLE Epos::open(char *portName)
{

char deviceName[] = "EPOS2";
char protocolStackName[] = "MAXON SERIAL V2";
char interfaceName[] = "USB";

HANDLE m_keyHandle = VCS_OpenDevice(deviceName,
protocolStackName,
interfaceName,
portName,
&m_errorCode);

if (!m_keyHandle)
{
throwError("failed to open device on port " + QString(portName));
return nullptr;
}

emit log(EventLogType::Notify, "Epos :: device is open on port " + QString(portName));

return m_keyHandle;
}

void Epos::close(HANDLE m_keyHandle)
{
if (m_keyHandle == nullptr)
return;

if (!VCS_CloseDevice(m_keyHandle, &m_errorCode))
{
throwError("failed to close device");
return;
}

m_keyHandle = nullptr;
}

void Epos::clear(HANDLE m_keyHandle)
{
BOOL isFaultState = FALSE;

if (!m_keyHandle)
return;

if (!VCS_GetFaultState(m_keyHandle, m_nodeId, &isFaultState, &m_errorCode))
{
throwError("VCS_GetFaultState");
return;
}

if (isFaultState)
{
if (!VCS_ClearFault(m_keyHandle, m_nodeId, &m_errorCode))
{
throwError("VCS_ClearFault");
}

// led indicator
setLedRed(FALSE);
setLedGreen(FALSE);
}
}

void Epos::enable(HANDLE m_keyHandle)
{
if (!m_keyHandle)
return;

clear(m_keyHandle);

if (!VCS_SetEnableState(m_keyHandle, m_nodeId, &m_errorCode))
{
throwError("VCS_SetEnableState");
}
}

void Epos::disable(HANDLE m_keyHandle)
{
if (!m_keyHandle)
return;

if (!VCS_SetDisableState(m_keyHandle, m_nodeId, &m_errorCode))
{
throwError("VCS_SetDisableState");
}
}


void Epos::setVelocityMode(HANDLE m_keyHandle)
{
if (!m_keyHandle)
return;

// set operation mode
if (!VCS_ActivateVelocityMode(m_keyHandle, m_nodeId, &m_errorCode))
{
throwError("VCS_ActivateVelocityMode");
}
}

void Epos::move(HANDLE m_keyHandle, qint16 velocityMust)
{
enable(m_keyHandle);

if (!VCS_SetVelocityMust(m_keyHandle, m_nodeId, velocityMust, &m_errorCode))
{
throwError("VCS_SetVelocityMust");
}
}

void Epos::stop(HANDLE m_keyHandle)
{
if (!VCS_SetQuickStopState(m_keyHandle, m_nodeId, &m_errorCode))
{
throwError("VCS_SetQuickStopState");
}

disable(m_keyHandle);
}

void Epos::setDOPin(HANDLE m_keyHandle, WORD digitalOutputNb, WORD configuration, BOOL state)
{
BOOL mask = state;
BOOL polarity = FALSE;

if (!m_keyHandle)
return;

if (!VCS_DigitalOutputConfiguration(m_keyHandle,
m_nodeId,
digitalOutputNb,
configuration,
state,
mask,
polarity,
&m_errorCode))
{
throwError("VCS_DigitalOutputConfiguration");
}
}


void Epos::setLedGreen(BOOL state)
{
WORD digitalOutputNb = 0x0003;
WORD configuration = DIC_GENERAL_PURPOSE_C;
setDOPin(m_keyHandle_lower, digitalOutputNb, configuration, state);
}


void Epos::setSound(BOOL state)
{
WORD digitalOutputNb = 0x0004;
WORD configuration = DIC_GENERAL_PURPOSE_D;
setDOPin(m_keyHandle_lower, digitalOutputNb, configuration, state);
}


void Epos::setTension(BOOL state)
{
WORD digitalOutputNb = 0x0003;
WORD configuration = DIC_GENERAL_PURPOSE_C;
setDOPin(m_keyHandle_upper, digitalOutputNb, configuration, state);
}


void Epos::setLedRed(BOOL state)
{
WORD digitalOutputNb = 0x0004;
WORD configuration = DIC_GENERAL_PURPOSE_D;
setDOPin(m_keyHandle_upper, digitalOutputNb, configuration, state);
}


void Epos::throwError(const QString &errorMessage)
{
const WORD errorInfoSize = 256;
char errorInfo[errorInfoSize];

if (!VCS_GetErrorInfo(m_errorCode, errorInfo, errorInfoSize))
{
//std::copy(errorInfo, "failed to read error information", errorInfoSize);
}

emit log(EventLogType::Warn, "EPOS :: Error, " + errorMessage + "\n" + QString(errorInfo) + ", errorCode: " + QString::number(m_errorCode, 16));

// led indicator
setLedGreen(FALSE);
setLedRed(TRUE);
}


Expand Down
24 changes: 24 additions & 0 deletions BrainATUMtome/epos.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,42 @@

#include <QObject>

#include "Definitions.h"
#include "eventlog.h"

class Epos : public QObject
{
Q_OBJECT
public:
explicit Epos(QObject *parent = nullptr);
~Epos();

private:
HANDLE m_keyHandle_lower;
HANDLE m_keyHandle_upper;
WORD m_nodeId;
DWORD m_errorCode;

const int MOTORID_LOWER = 0;
const int MOTORID_UPPER = 1;

HANDLE open(char *portName);
void close(HANDLE m_keyHandle);
void clear(HANDLE m_keyHandle);
void enable(HANDLE m_keyHandle);
void disable(HANDLE m_keyHandle);
void setVelocityMode(HANDLE m_keyHandle);
void move(HANDLE m_keyHandle, qint16 velocityMust);
void stop(HANDLE m_keyHandle);
void setDOPin(HANDLE m_keyHandle, WORD digitalOutputNb, WORD configuration, BOOL state);

void setLedRed(BOOL state);
void setLedGreen(BOOL state);
void setSound(BOOL state);
void setTension(BOOL state);

void throwError(const QString &message);

public slots:
void on_uirequest_velocity(int motorid, int velocity);
void on_uirequest_tension(bool state);
Expand Down
4 changes: 2 additions & 2 deletions BrainATUMtome/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class MainWindow : public QMainWindow
void configure_microtome();
void configure_syringe();

static const int EPOS_LOWER_MOTTOR = 0;
static const int EPOS_UPPER_MOTTOR = 1;
const int EPOS_LOWER_MOTTOR = 0;
const int EPOS_UPPER_MOTTOR = 1;

private slots:
void on_radioButtonsEposSyncToggled(bool checked);
Expand Down
14 changes: 10 additions & 4 deletions BrainATUMtome/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1000</width>
<height>753</height>
<height>769</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -64,7 +64,7 @@
<number>15000</number>
</property>
<property name="singleStep">
<number>1</number>
<number>10</number>
</property>
<property name="value">
<number>1000</number>
Expand Down Expand Up @@ -120,7 +120,7 @@
<number>15000</number>
</property>
<property name="singleStep">
<number>1</number>
<number>10</number>
</property>
<property name="value">
<number>1000</number>
Expand Down Expand Up @@ -176,7 +176,7 @@
<number>15000</number>
</property>
<property name="singleStep">
<number>1</number>
<number>10</number>
</property>
<property name="value">
<number>1000</number>
Expand Down Expand Up @@ -270,6 +270,9 @@
<property name="maximum">
<number>100000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="value">
<number>100</number>
</property>
Expand Down Expand Up @@ -319,6 +322,9 @@
<property name="maximum">
<number>15000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="value">
<number>30</number>
</property>
Expand Down

0 comments on commit 9f9e63a

Please sign in to comment.