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

Commit

Permalink
epos external config
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-tushevg committed Jan 3, 2019
1 parent 343244a commit 5245f40
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 29 deletions.
43 changes: 21 additions & 22 deletions BrainATUMtome/epos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@
Epos::Epos(QObject *parent) : QObject(parent),
m_keyHandle_lower(nullptr),
m_keyHandle_upper(nullptr),
m_nodeId(0),
m_nodeId(1),
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);
}


Expand All @@ -25,28 +17,35 @@ Epos::~Epos()
}


HANDLE Epos::open(char *portName)
void Epos::open(int motorid,
const QString &deviceName,
const QString &protocolStackName,
const QString &interfaceName,
const QString &portName)
{
HANDLE keyHandle;

char deviceName[] = "EPOS2";
char protocolStackName[] = "MAXON SERIAL V2";
char interfaceName[] = "USB";
if (motorid == MOTORID_LOWER) {
keyHandle = m_keyHandle_lower;
}
else if (motorid == MOTORID_UPPER) {
keyHandle = m_keyHandle_upper;
}

HANDLE m_keyHandle = VCS_OpenDevice(deviceName,
protocolStackName,
interfaceName,
portName,
&m_errorCode);
keyHandle = VCS_OpenDevice(deviceName.toUtf8().data(),
protocolStackName.toUtf8().data(),
interfaceName.toUtf8().data(),
portName.toUtf8().data(),
&m_errorCode);

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

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

return m_keyHandle;
setVelocityMode(keyHandle);
}

void Epos::close(HANDLE m_keyHandle)
Expand Down
7 changes: 6 additions & 1 deletion BrainATUMtome/epos.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class Epos : public QObject
explicit Epos(QObject *parent = nullptr);
~Epos();

void open(int motorid,
const QString &deviceName,
const QString &protocolStackName,
const QString &interfaceName,
const QString &portName);

private:
HANDLE m_keyHandle_lower;
HANDLE m_keyHandle_upper;
Expand All @@ -22,7 +28,6 @@ class Epos : public QObject
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);
Expand Down
28 changes: 24 additions & 4 deletions BrainATUMtome/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ MainWindow::MainWindow(QWidget *parent) :
m_driverMicrotome(nullptr),
m_driverSyringe(nullptr),
m_timerEpos(new QTimer(this)),
m_settings(nullptr),
m_epos_ticks(0),
m_epos_direction(0),
m_epos_velocity(1000),
Expand All @@ -17,6 +18,12 @@ MainWindow::MainWindow(QWidget *parent) :
{
ui->setupUi(this);

// open settings
QString fileIni = "/Users/tushevg/Desktop/BrainATUMtome/config/settings.ini";
if (!(QFileInfo::exists(fileIni) && QFileInfo(fileIni).isFile()))
ui->widget_board->on_log(EventLogType::Warn, "MainWindow :: provided INI file " + fileIni + " is not valid.");
m_settings = new QSettings(fileIni, QSettings::IniFormat);

configure_epos();
configure_microtome();
configure_syringe();
Expand All @@ -33,7 +40,20 @@ MainWindow::~MainWindow()

void MainWindow::configure_epos()
{
if (m_settings->value("epos/deviceName").isNull()) {
ui->widget_board->on_log(EventLogType::Warn, "Settings :: failed to parse INI file " + m_settings->fileName());
return;
}
QString portLower = m_settings->value("epos/portLower", "USB0").toString();
QString portUpper = m_settings->value("epos/portUpper", "USB1").toString();
QString deviceName = m_settings->value("epos/deviceName", "EPOS2").toString();
QString protocolStackName = m_settings->value("epos/protocolStackName", "MAXON SERIAL V2").toString();
QString interfaceName = m_settings->value("epos/interfaceName", "USB").toString();

m_driverEpos = new Epos(this);
m_driverEpos->open(EPOS_MOTORID_LOWER, deviceName, protocolStackName, interfaceName, portLower);
m_driverEpos->open(EPOS_MOTORID_UPPER, deviceName, protocolStackName, interfaceName, portUpper);

connect(m_driverEpos, &Epos::log, ui->widget_board, &EventLog::on_log);
connect(this, &MainWindow::uirequest_epos_velocity, m_driverEpos, &Epos::on_uirequest_velocity);
connect(this, &MainWindow::uirequest_epos_tension, m_driverEpos, &Epos::on_uirequest_tension);
Expand Down Expand Up @@ -136,7 +156,7 @@ void MainWindow::on_radioButtonsEposLowerToggled(bool checked)

}

drive_epos_motor(EPOS_LOWER_MOTTOR, ui->spinBox_epos_lower_velocity->value());
drive_epos_motor(EPOS_MOTORID_LOWER, ui->spinBox_epos_lower_velocity->value());
}


Expand All @@ -161,7 +181,7 @@ void MainWindow::on_radioButtonsEposUpperToggled(bool checked)
m_epos_direction = -1;
}

drive_epos_motor(EPOS_UPPER_MOTTOR, ui->spinBox_epos_upper_velocity->value());
drive_epos_motor(EPOS_MOTORID_UPPER, ui->spinBox_epos_upper_velocity->value());
}


Expand Down Expand Up @@ -191,7 +211,7 @@ void MainWindow::on_spinBox_epos_lower_velocity_valueChanged(int value)
if (ui->radioButton_epos_lower_off->isChecked())
return;

drive_epos_motor(EPOS_LOWER_MOTTOR, value);
drive_epos_motor(EPOS_MOTORID_LOWER, value);
}


Expand All @@ -200,7 +220,7 @@ void MainWindow::on_spinBox_epos_upper_velocity_valueChanged(int value)
if (ui->radioButton_epos_upper_off->isChecked())
return;

drive_epos_motor(EPOS_UPPER_MOTTOR, value);
drive_epos_motor(EPOS_MOTORID_UPPER, value);
}


Expand Down
7 changes: 5 additions & 2 deletions BrainATUMtome/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <QMainWindow>
#include <QTimer>
#include <QFileInfo>
#include <QSettings>
#include <QDebug>

#include "eventlog.h"
Expand All @@ -29,6 +31,7 @@ class MainWindow : public QMainWindow
Microtome *m_driverMicrotome;
Syringe *m_driverSyringe;
QTimer *m_timerEpos;
QSettings *m_settings;

int m_epos_ticks;
int m_epos_direction;
Expand All @@ -42,8 +45,8 @@ class MainWindow : public QMainWindow
void configure_microtome();
void configure_syringe();

const int EPOS_LOWER_MOTTOR = 0;
const int EPOS_UPPER_MOTTOR = 1;
const int EPOS_MOTORID_LOWER = 0;
const int EPOS_MOTORID_UPPER = 1;

private slots:
void on_radioButtonsEposSyncToggled(bool checked);
Expand Down

0 comments on commit 5245f40

Please sign in to comment.