Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkTrackingDeviceConfigurationWidgetScanPortsWorker.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include <mitkProgressBar.h>
20 #include <mitkNDITrackingDevice.h>
21 #include <mitkIGTException.h>
22 
24 
26 {
27  int Port = -1;
28  int PortType = -1;
29 
30  QString result = "<br>Found Devices:";
31  int resultSize = result.size(); //remember size of result: if it stays the same no device were found
32  mitk::TrackingDeviceType scannedPort;
33 #ifdef WIN32
35 
36  QString devName;
37  for (unsigned int i = 1; i < 20; ++i)
38  {
39  QString statusOutput = "Scanning Port #" + QString::number(i);
40  MITK_INFO << statusOutput.toStdString().c_str();
41  if (i < 10) devName = QString("COM%1").arg(i);
42  else devName = QString("\\\\.\\COM%1").arg(i); // prepend "\\.\ to COM ports >9, to be able to allow connection"
43  scannedPort = ScanPort(devName);
45  {
46  result += "<br>" + devName + ": " + QString::fromStdString(scannedPort);
47  Port = i;
48  }
50  }
51 #else //linux systems
52  for(unsigned int i = 1; i < 6; ++i)
53  {
54  QString devName = QString("/dev/ttyS%1").arg(i);
55  mitk::TrackingDeviceType scannedPort = ScanPort(devName);
57  {
58  result += "<br>" + devName + ": " + QString::fromStdString(scannedPort);
59  Port = i;
60  PortType = 1;
61  }
62  }
63 
64  for(unsigned int i = 0; i <7; ++i)
65  {
66  QString devName = QString("/dev/ttyUSB%1").arg(i);
67  mitk::TrackingDeviceType scannedPort = ScanPort(devName);
69  {
70  result += "<br>" + devName + ": " + QString::fromStdString(scannedPort);
71  Port = i;
72  PortType = 0;
73  }
74  }
75 #endif
76 
77  if (result.size() == resultSize) result += "<br>none";
78 
79  emit PortsScanned(Port, result, PortType);
80 }
81 
83 {
85  tracker->SetDeviceName(port.toStdString());
87  try
88  {
89  returnValue = tracker->TestConnection();
90  }
91  catch (mitk::IGTException)
92  {
93  }//do nothing: there is simply no device on this port
94  return returnValue;
95 }
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
static Pointer New()
itk::SmartPointer< Self > Pointer
#define MITK_INFO
Definition: mitkLogMacros.h:22
An object of this class represents an exception of the MITK-IGT module.
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
void AddStepsToDo(unsigned int steps)
Adds steps to totalSteps.
std::string TrackingDeviceType
mitk::TrackingDeviceType ScanPort(QString port)
Scans the given port for a NDI tracking device.
void PortsScanned(int Port, QString result, int PortType)