Medical Imaging Interaction Toolkit  2018.4.99-6a3ea89d
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 #include <mitkProgressBar.h>
16 #include <mitkNDITrackingDevice.h>
17 #include <mitkIGTException.h>
18 
20 
22 {
23  int Port = -1;
24  int PortType = -1;
25 
26  QString result = "<br>Found Devices:";
27  int resultSize = result.size(); //remember size of result: if it stays the same no device were found
28  mitk::TrackingDeviceType scannedPort;
29 #ifdef WIN32
31 
32  QString devName;
33  for (unsigned int i = 1; i < 20; ++i)
34  {
35  QString statusOutput = "Scanning Port #" + QString::number(i);
36  MITK_INFO << statusOutput.toStdString().c_str();
37  if (i < 10) devName = QString("COM%1").arg(i);
38  else devName = QString("\\\\.\\COM%1").arg(i); // prepend "\\.\ to COM ports >9, to be able to allow connection"
39  scannedPort = ScanPort(devName);
41  {
42  result += "<br>" + devName + ": " + QString::fromStdString(scannedPort);
43  Port = i;
44  }
46  }
47 #else //linux systems
48  for(unsigned int i = 1; i < 6; ++i)
49  {
50  QString devName = QString("/dev/ttyS%1").arg(i);
51  mitk::TrackingDeviceType scannedPort = ScanPort(devName);
53  {
54  result += "<br>" + devName + ": " + QString::fromStdString(scannedPort);
55  Port = i;
56  PortType = 1;
57  }
58  }
59 
60  for(unsigned int i = 0; i <7; ++i)
61  {
62  QString devName = QString("/dev/ttyUSB%1").arg(i);
63  mitk::TrackingDeviceType scannedPort = ScanPort(devName);
65  {
66  result += "<br>" + devName + ": " + QString::fromStdString(scannedPort);
67  Port = i;
68  PortType = 0;
69  }
70  }
71 #endif
72 
73  if (result.size() == resultSize) result += "<br>none";
74 
75  emit PortsScanned(Port, result, PortType);
76 }
77 
79 {
80  mitk::NDITrackingDevice::Pointer tracker = mitk::NDITrackingDevice::New();
81  tracker->SetDeviceName(port.toStdString());
83  try
84  {
85  returnValue = tracker->TestConnection();
86  }
87  catch (const mitk::IGTException&)
88  {
89  }//do nothing: there is simply no device on this port
90  return returnValue;
91 }
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
static Pointer New()
#define MITK_INFO
Definition: mitkLogMacros.h:18
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)