void Serial::config(uint32_t speed, Serial::Parity parity, Serial::WordLength dataBits, Serial::StopBits stopBits, HardwareFlowControl hardwareFlow) { disable(Device::Part::All); setSpeed(speed); setParity(parity); setWordLength(dataBits); setStopBits(stopBits); setHardwareFlowControl(hardwareFlow); }
// Open the serial port and initialize its flags. void SerialPortImplWin32::open() { COMMTIMEOUTS gct; mHandle = CreateFile( mName.c_str(), mOpenFlag, 0, // comm devices must be opened w/exclusive-access NULL, // no security attributes OPEN_EXISTING, // comm devices must use OPEN_EXISTING mBlocking, NULL // hTemplate must be NULL for comm devices ); if ( mHandle == INVALID_HANDLE_VALUE ) { // Report the error. std::stringstream msg_stream; msg_stream << "CreateFile() failed for " << mName << ": " << getErrorMessageWithCode(GetLastError()); vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL) << clrOutBOLD(clrRED, "ERROR") << ": " << msg_stream.str() << std::endl << std::endl << vprDEBUG_FLUSH; throw IOException(msg_stream.str(), VPR_LOCATION); } gct.ReadIntervalTimeout = 0; gct.ReadTotalTimeoutConstant = 0; gct.ReadTotalTimeoutMultiplier = 0; gct.WriteTotalTimeoutConstant = 5000; gct.WriteTotalTimeoutMultiplier = 0; if ( ! SetCommTimeouts(mHandle, &gct) ) { std::stringstream msg_stream; msg_stream << "Timeout initialization for " << mName << " failed: " << getErrorMessageWithCode(GetLastError()); vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL) << clrOutBOLD(clrRED, "ERROR") << ": " << msg_stream.str() << std::endl << vprDEBUG_FLUSH; throw IOException(msg_stream.str(), VPR_LOCATION); } DCB dcb; GetCommState(mHandle, &dcb); SetCommState(mHandle, &dcb); setHardwareFlowControl(false); mOpen = true; }