MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkTrackingDeviceConfigurationWidgetScanPortsWorker.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14
15#include <mitkProgressBar.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
30 mitk::ProgressBar::GetInstance()->AddStepsToDo(19);
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 }
45 mitk::ProgressBar::GetInstance()->Progress();
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 PortsScanned(int Port, QString result, int PortType)
mitk::TrackingDeviceType ScanPort(QString port)
Scans the given port for a NDI tracking device.
An object of this class represents an exception of the MITK-IGT module.
std::string TrackingDeviceType