MercurySDK
Software development kit for Mercury digital servos
port_handler_windows.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2021 <Robot Articulation/code@robotarticulation.com>
3 *
4 * Source files modified to support the Mercury range of digital servo motors from Robot Articulation
5 *******************************************************************************/
6 
7 /*******************************************************************************
8 * Copyright 2017 ROBOTIS CO., LTD.
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *******************************************************************************/
22 
23 /* Original author: Zerom, Leon (RyuWoon Jung) */
24 
25 #ifndef MERCURY_SDK_INCLUDE_MERCURY_SDK_WINDOWS_PORTHANDLERWINDOWS_H_
26 #define MERCURY_SDK_INCLUDE_MERCURY_SDK_WINDOWS_PORTHANDLERWINDOWS_H_
27 
28 #include <Windows.h>
29 
30 #include "port_handler.h"
31 
32 namespace mercury
33 {
34 
38 class WINDECLSPEC PortHandlerWindows : public PortHandler
39 {
40  private:
41  HANDLE serial_handle_;
42  LARGE_INTEGER freq_, counter_;
43 
44  int baudrate_;
45  char port_name_[100];
46 
47  double packet_start_time_;
48  double packet_timeout_;
49  double tx_time_per_byte_;
50 
51  bool setupPort(const int baudrate);
52 
53  double getCurrentTime();
54  double getTimeSinceStart();
55 
56  public:
61  PortHandlerWindows(const char *port_name);
62 
67  virtual ~PortHandlerWindows() { closePort(); }
68 
74  bool openPort();
75 
80  void closePort();
81 
86  void clearPort();
87 
93  void setPortName(const char *port_name);
94 
100  char *getPortName();
101 
110  bool setBaudRate(const int baudrate);
111 
117  int getBaudRate();
118 
126 
137  int readPort(uint8_t *packet, int length);
138 
149  int writePort(uint8_t *packet, int length);
150 
156  void setPacketTimeout(uint16_t packet_length);
157 
163  void setPacketTimeout(double msec);
164 
170 };
171 
172 }
173 
174 
175 #endif /* MERCURY_SDK_INCLUDE_MERCURY_SDK_WINDOWS_PORTHANDLERWINDOWS_H_ */
The class for port control that inherits PortHandlerLinux, PortHandlerWindows, PortHandlerMac,...
Definition: port_handler.h:56
The class for control port in Windows.
void clearPort()
The function that clears the port @description The function clears the port.
virtual ~PortHandlerWindows()
The function that closes the port @description The function calls PortHandlerWindows::closePort() to ...
bool setBaudRate(const int baudrate)
The function that sets baudrate into the port handler @description The function sets baudrate into th...
int getBaudRate()
The function that returns current baudrate set into the port handler @description The function return...
int writePort(uint8_t *packet, int length)
The function that writes bytes on the port buffer @description The function writes bytes on the port ...
void closePort()
The function that closes the port @description The function closes the port.
int getBytesAvailable()
The function that checks how much bytes are able to be read from the port buffer @description The fun...
PortHandlerWindows(const char *port_name)
The function that initializes instance of PortHandler and gets port_name @description The function in...
void setPacketTimeout(uint16_t packet_length)
The function that sets and starts stopwatch for watching packet timeout @description The function set...
void setPortName(const char *port_name)
The function that sets port name into the port handler @description The function sets port name into ...
bool isPacketTimeout()
The function that checks whether packet timeout is occurred @description The function checks whether ...
void setPacketTimeout(double msec)
The function that sets and starts stopwatch for watching packet timeout @description The function set...
char * getPortName()
The function that returns port name set into the port handler @description The function returns curre...
bool openPort()
The function that opens the port @description The function calls PortHandlerWindows::setBaudRate() to...
int readPort(uint8_t *packet, int length)
The function that reads bytes from the port buffer @description The function gets bytes from the port...