19 #if defined(_WIN32) || defined(_WIN64)
28 #define LATENCY_TIMER 16 // msec (USB latency timer)
41 : serial_handle_(INVALID_HANDLE_VALUE),
42 baudrate_(DEFAULT_BAUDRATE_),
43 packet_start_time_(0.0),
45 tx_time_per_byte_(0.0)
50 sprintf_s(buffer,
sizeof(buffer),
"\\\\.\\%s", port_name);
99 BOOL res = DeviceIoControl(
serial_handle_, GENERIC_READ | GENERIC_WRITE, NULL, 0, 0, 0, &retbyte, (LPOVERLAPPED)NULL);
101 printf(
"%d", (
int)res);
109 if (ReadFile(
serial_handle_, packet, (DWORD)length, &dwRead, NULL) == FALSE)
119 if (WriteFile(
serial_handle_, packet, (DWORD)length, &dwWrite, NULL) == FALSE)
150 QueryPerformanceFrequency(&
freq_);
151 return (
double)
counter_.QuadPart / (double)
freq_.QuadPart * 1000.0;
167 COMMTIMEOUTS timeouts;
172 serial_handle_ = CreateFileA(
port_name_, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
175 printf(
"[PortHandlerWindows::SetupPort] Error opening serial port!\n");
179 dcb.DCBlength =
sizeof(DCB);
181 goto DXL_HAL_OPEN_ERROR;
184 dcb.BaudRate = (DWORD)baudrate;
186 dcb.Parity = NOPARITY;
187 dcb.StopBits = ONESTOPBIT;
188 dcb.fParity = NOPARITY;
191 dcb.fAbortOnError = 0;
197 dcb.fDtrControl = DTR_CONTROL_DISABLE;
198 dcb.fRtsControl = RTS_CONTROL_DISABLE;
199 dcb.fDsrSensitivity = 0;
200 dcb.fOutxDsrFlow = 0;
201 dcb.fOutxCtsFlow = 0;
204 goto DXL_HAL_OPEN_ERROR;
207 goto DXL_HAL_OPEN_ERROR;
209 goto DXL_HAL_OPEN_ERROR;
210 if (PurgeComm(
serial_handle_, PURGE_TXABORT | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_RXCLEAR) == FALSE)
211 goto DXL_HAL_OPEN_ERROR;
213 goto DXL_HAL_OPEN_ERROR;
216 goto DXL_HAL_OPEN_ERROR;
219 timeouts.ReadIntervalTimeout = 0;
220 timeouts.ReadTotalTimeoutMultiplier = 0;
221 timeouts.ReadTotalTimeoutConstant = 1;
222 timeouts.WriteTotalTimeoutMultiplier = 0;
223 timeouts.WriteTotalTimeoutConstant = 0;
225 goto DXL_HAL_OPEN_ERROR;