| Index: device/serial/serial_io_handler_win.cc
|
| diff --git a/device/serial/serial_io_handler_win.cc b/device/serial/serial_io_handler_win.cc
|
| index 17d7db1970a78a17b439208a394f871efed04c1f..40f50236af79ad8ca2f8d1249d5d03486b3a0882 100644
|
| --- a/device/serial/serial_io_handler_win.cc
|
| +++ b/device/serial/serial_io_handler_win.cc
|
| @@ -167,26 +167,11 @@ bool SerialIoHandlerWin::PostOpen() {
|
| COMMTIMEOUTS timeouts = {0};
|
| timeouts.ReadIntervalTimeout = MAXDWORD;
|
| if (!::SetCommTimeouts(file().GetPlatformFile(), &timeouts)) {
|
| + VPLOG(1) << "Failed to set serial timeouts";
|
| return false;
|
| }
|
|
|
| - DCB config = {0};
|
| - config.DCBlength = sizeof(config);
|
| - if (!GetCommState(file().GetPlatformFile(), &config)) {
|
| - return false;
|
| - }
|
| - // Setup some sane default state.
|
| - config.fBinary = TRUE;
|
| - config.fParity = FALSE;
|
| - config.fAbortOnError = TRUE;
|
| - config.fOutxCtsFlow = FALSE;
|
| - config.fOutxDsrFlow = FALSE;
|
| - config.fRtsControl = RTS_CONTROL_ENABLE;
|
| - config.fDtrControl = DTR_CONTROL_ENABLE;
|
| - config.fDsrSensitivity = FALSE;
|
| - config.fOutX = FALSE;
|
| - config.fInX = FALSE;
|
| - return SetCommState(file().GetPlatformFile(), &config) != 0;
|
| + return true;
|
| }
|
|
|
| void SerialIoHandlerWin::ReadImpl() {
|
| @@ -202,12 +187,15 @@ void SerialIoHandlerWin::ReadImpl() {
|
| return;
|
| }
|
|
|
| - SetCommMask(file().GetPlatformFile(), EV_RXCHAR);
|
| + if (!SetCommMask(file().GetPlatformFile(), EV_RXCHAR)) {
|
| + VPLOG(1) << "Failed to set serial event flags";
|
| + }
|
|
|
| event_mask_ = 0;
|
| BOOL ok = ::WaitCommEvent(
|
| file().GetPlatformFile(), &event_mask_, &comm_context_->overlapped);
|
| if (!ok && GetLastError() != ERROR_IO_PENDING) {
|
| + VPLOG(1) << "Failed to receive serial event";
|
| QueueReadCompleted(0, serial::RECEIVE_ERROR_SYSTEM_ERROR);
|
| }
|
| is_comm_pending_ = true;
|
| @@ -240,6 +228,52 @@ void SerialIoHandlerWin::CancelWriteImpl() {
|
| ::CancelIo(file().GetPlatformFile());
|
| }
|
|
|
| +bool SerialIoHandlerWin::ConfigurePortImpl() {
|
| + DCB config = {0};
|
| + config.DCBlength = sizeof(config);
|
| + if (!GetCommState(file().GetPlatformFile(), &config)) {
|
| + VPLOG(1) << "Failed to get serial port info";
|
| + return false;
|
| + }
|
| +
|
| + // Set up some sane default options that are not configurable.
|
| + config.fBinary = TRUE;
|
| + config.fParity = FALSE;
|
| + config.fAbortOnError = TRUE;
|
| + config.fOutxDsrFlow = FALSE;
|
| + config.fDtrControl = DTR_CONTROL_ENABLE;
|
| + config.fDsrSensitivity = FALSE;
|
| + config.fOutX = FALSE;
|
| + config.fInX = FALSE;
|
| +
|
| + DCHECK(options().bitrate);
|
| + config.BaudRate = BitrateToSpeedConstant(options().bitrate);
|
| +
|
| + DCHECK(options().data_bits != serial::DATA_BITS_NONE);
|
| + config.ByteSize = DataBitsEnumToConstant(options().data_bits);
|
| +
|
| + DCHECK(options().parity_bit != serial::PARITY_BIT_NONE);
|
| + config.Parity = ParityBitEnumToConstant(options().parity_bit);
|
| +
|
| + DCHECK(options().stop_bits != serial::STOP_BITS_NONE);
|
| + config.StopBits = StopBitsEnumToConstant(options().stop_bits);
|
| +
|
| + DCHECK(options().has_cts_flow_control);
|
| + if (options().cts_flow_control) {
|
| + config.fOutxCtsFlow = TRUE;
|
| + config.fRtsControl = RTS_CONTROL_HANDSHAKE;
|
| + } else {
|
| + config.fOutxCtsFlow = FALSE;
|
| + config.fRtsControl = RTS_CONTROL_ENABLE;
|
| + }
|
| +
|
| + if (!SetCommState(file().GetPlatformFile(), &config)) {
|
| + VPLOG(1) << "Failed to set serial port info";
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| SerialIoHandlerWin::SerialIoHandlerWin(
|
| scoped_refptr<base::MessageLoopProxy> file_thread_message_loop,
|
| scoped_refptr<base::MessageLoopProxy> ui_thread_message_loop)
|
| @@ -298,41 +332,18 @@ void SerialIoHandlerWin::OnIOCompleted(
|
| }
|
| }
|
|
|
| -bool SerialIoHandlerWin::ConfigurePort(
|
| - const serial::ConnectionOptions& options) {
|
| - DCB config = {0};
|
| - config.DCBlength = sizeof(config);
|
| - if (!GetCommState(file().GetPlatformFile(), &config)) {
|
| +bool SerialIoHandlerWin::Flush() const {
|
| + if (!PurgeComm(file().GetPlatformFile(), PURGE_RXCLEAR | PURGE_TXCLEAR)) {
|
| + VPLOG(1) << "Failed to flush serial port";
|
| return false;
|
| }
|
| - if (options.bitrate)
|
| - config.BaudRate = BitrateToSpeedConstant(options.bitrate);
|
| - if (options.data_bits != serial::DATA_BITS_NONE)
|
| - config.ByteSize = DataBitsEnumToConstant(options.data_bits);
|
| - if (options.parity_bit != serial::PARITY_BIT_NONE)
|
| - config.Parity = ParityBitEnumToConstant(options.parity_bit);
|
| - if (options.stop_bits != serial::STOP_BITS_NONE)
|
| - config.StopBits = StopBitsEnumToConstant(options.stop_bits);
|
| - if (options.has_cts_flow_control) {
|
| - if (options.cts_flow_control) {
|
| - config.fOutxCtsFlow = TRUE;
|
| - config.fRtsControl = RTS_CONTROL_HANDSHAKE;
|
| - } else {
|
| - config.fOutxCtsFlow = FALSE;
|
| - config.fRtsControl = RTS_CONTROL_ENABLE;
|
| - }
|
| - }
|
| - return SetCommState(file().GetPlatformFile(), &config) != 0;
|
| -}
|
| -
|
| -bool SerialIoHandlerWin::Flush() const {
|
| - return PurgeComm(file().GetPlatformFile(), PURGE_RXCLEAR | PURGE_TXCLEAR) !=
|
| - 0;
|
| + return true;
|
| }
|
|
|
| serial::DeviceControlSignalsPtr SerialIoHandlerWin::GetControlSignals() const {
|
| DWORD status;
|
| if (!GetCommModemStatus(file().GetPlatformFile(), &status)) {
|
| + VPLOG(1) << "Failed to get port control signals";
|
| return serial::DeviceControlSignalsPtr();
|
| }
|
|
|
| @@ -349,12 +360,14 @@ bool SerialIoHandlerWin::SetControlSignals(
|
| if (signals.has_dtr) {
|
| if (!EscapeCommFunction(file().GetPlatformFile(),
|
| signals.dtr ? SETDTR : CLRDTR)) {
|
| + VPLOG(1) << "Failed to configure DTR signal";
|
| return false;
|
| }
|
| }
|
| if (signals.has_rts) {
|
| if (!EscapeCommFunction(file().GetPlatformFile(),
|
| signals.rts ? SETRTS : CLRRTS)) {
|
| + VPLOG(1) << "Failed to configure RTS signal";
|
| return false;
|
| }
|
| }
|
| @@ -365,6 +378,7 @@ serial::ConnectionInfoPtr SerialIoHandlerWin::GetPortInfo() const {
|
| DCB config = {0};
|
| config.DCBlength = sizeof(config);
|
| if (!GetCommState(file().GetPlatformFile(), &config)) {
|
| + VPLOG(1) << "Failed to get serial port info";
|
| return serial::ConnectionInfoPtr();
|
| }
|
| serial::ConnectionInfoPtr info(serial::ConnectionInfo::New());
|
|
|