MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkSerialCommunication.h
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
13#ifndef mitkSerialCommunication_h
14#define mitkSerialCommunication_h
15
16#include <MitkIGTExports.h>
17#include "mitkCommon.h"
18#include <itkObject.h>
19#include <itkObjectFactory.h>
20
21#ifdef WIN32
22#include <windows.h>
23#else // Posix
24#include <termios.h>
25#endif
26
27namespace mitk
28{
43 class MITKIGT_EXPORT SerialCommunication : public itk::Object
44 {
45 public:
49
51 {
52 COM1 = 1,
53 COM2 = 2,
54 COM3 = 3,
55 COM4 = 4,
56 COM5 = 5,
57 COM6 = 6,
58 COM7 = 7,
59 COM8 = 8,
60 COM9 = 9,
61 COM10 = 10,
62 COM11 = 11,
63 COM12 = 12,
64 COM13 = 13
65 };
66
68 {
69 BaudRate9600 = 9600,
70 BaudRate14400 = 14400,
71 BaudRate19200 = 19200,
72 BaudRate38400 = 38400,
73 BaudRate57600 = 57600,
74 BaudRate115200 = 115200, // Highest supported rate for NDI Aurora
75 BaudRate230400 = 230400,
76 BaudRate460800 = 460800,
77 BaudRate500000 = 500000,
78 BaudRate576000 = 576000,
79 BaudRate921600 = 921600,
80 BaudRate1000000 = 1000000,
81 BaudRate1152000 = 1152000,
82 // BaudRate1228739 = 1228739, // Highest supported rate for NDI Polaris According to handbook, unknown value to most compilers though
83 BaudRate1500000 = 1500000,
84 BaudRate2000000 = 2000000,
85 BaudRate2500000 = 2500000,
86 BaudRate3000000 = 3000000,
87 BaudRate3500000 = 3500000,
88 BaudRate4000000 = 4000000
89 };
90
92 {
93 DataBits8 = 8,
94 DataBits7 = 7
95 };
96
97 enum Parity
98 {
99 None = 'N',
100 Odd = 'O',
101 Even = 'E'
102 };
103
105 {
106 StopBits1 = 1,
107 StopBits2 = 2
108 };
109
111 {
112 HardwareHandshakeOn = 1,
113 HardwareHandshakeOff = 0
114 };
115
120 bool IsConnected();
126 int OpenConnection();
131 void CloseConnection();
132
152 int Receive(std::string& answer, unsigned int numberOfBytes, const char *eol=nullptr);
153
163 int Send(const std::string& input, bool block = false);
164
168 void SendBreak(unsigned int ms = 400);
169
173 void ClearReceiveBuffer();
174
178 void ClearSendBuffer();
179
187
200
209 itkGetStringMacro(DeviceName);
210
219 itkSetStringMacro(DeviceName);
220
225
230
235
240
245
250
255
260
265
270
274 itkGetConstMacro(SendTimeout, unsigned int);
275
281 itkSetMacro(SendTimeout, unsigned int);
282
286 itkGetConstMacro(ReceiveTimeout, unsigned int);
287
295 itkSetMacro(ReceiveTimeout, unsigned int);
296
297 protected:
299 ~SerialCommunication() override;
300
306 int ApplyConfiguration();
307
308
309 #ifdef WIN32
313 int ApplyConfigurationWin();
314
315 #else
319 int ApplyConfigurationUnix();
320
321
322 #endif
323
324
325 std::string m_DeviceName;
332 unsigned int m_ReceiveTimeout;
333 unsigned int m_SendTimeout;
334
336
337#ifdef WIN32
338 HANDLE m_ComPortHandle;
339 DWORD m_PreviousMask;
340 COMMTIMEOUTS m_PreviousTimeout;
341 DCB m_PreviousDeviceControlBlock;
342#else
344#endif
345 };
346} // namespace mitk
347#endif
serial communication interface
itkSetMacro(StopBits, StopBits)
Set number of stop bits of the serial interface.
HardwareHandshake m_HardwareHandshake
whether to use hardware handshake for the connection
BaudRate m_BaudRate
baud rate of the serial interface connection
itkGetConstMacro(StopBits, StopBits)
Get number of stop bits of the serial interface.
unsigned int m_SendTimeout
timeout for sending data to the serial interface in milliseconds
itkSetMacro(PortNumber, PortNumber)
Set the port number of the serial interface.
itkGetConstMacro(PortNumber, PortNumber)
Get the port number of the serial interface.
itkGetConstMacro(SendTimeout, unsigned int)
returns the send timeout in milliseconds
itkSetStringMacro(DeviceName)
Set the device name.
itkSetMacro(SendTimeout, unsigned int)
set the send timeout in milliseconds
PortNumber m_PortNumber
port number of the device
itkGetConstMacro(BaudRate, BaudRate)
Get the baud rate of the serial interface.
unsigned int m_ReceiveTimeout
timeout for receiving data from the serial interface in milliseconds
mitkClassMacroItkParent(SerialCommunication, itk::Object)
itkSetMacro(DataBits, DataBits)
Set the number of data bits of the serial interface.
StopBits m_StopBits
number of stop bits per symbol
itkGetStringMacro(DeviceName)
Get the device name.
itkSetMacro(BaudRate, BaudRate)
Set the baud rate of the serial interface.
itkGetConstMacro(DataBits, DataBits)
Get the number of data bits of the serial interface.
itkGetConstMacro(ReceiveTimeout, unsigned int)
returns the receive timeout in milliseconds
itkSetMacro(HardwareHandshake, HardwareHandshake)
Set if hardware handshake should be used.
DataBits m_DataBits
number of data bits per symbol
itkSetMacro(Parity, Parity)
Set the parity mode of the serial interface.
bool m_Connected
is set to true if a connection currently established
std::string m_DeviceName
device name that is used to connect to the serial interface (will be used if != "")
itkGetConstMacro(HardwareHandshake, HardwareHandshake)
returns true if hardware handshake should is used
itkGetConstMacro(Parity, Parity)
Get the parity mode of the serial interface.
itkSetMacro(ReceiveTimeout, unsigned int)
set the send timeout in milliseconds
IGT Exceptions.