| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/serial/serial_connection.h" | 5 #include "chrome/browser/extensions/api/serial/serial_connection.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <windows.h> |
| 8 | 9 |
| 9 namespace extensions { | 10 namespace extensions { |
| 10 | 11 |
| 11 SerialConnection::SerialConnection(const std::string& port, | 12 bool SerialConnection::PostOpen() { |
| 12 APIResourceEventNotifier* event_notifier) | 13 // Set timeouts so that reads return immediately with whatever could be read |
| 13 : APIResource(APIResource::SerialConnectionResource, event_notifier), | 14 // without blocking. |
| 14 port_(port), fd_(0) { | 15 COMMTIMEOUTS timeouts = { 0 }; |
| 15 } | 16 timeouts.ReadIntervalTimeout = MAXDWORD; |
| 17 if (!::SetCommTimeouts(file_, &timeouts)) |
| 18 return false; |
| 16 | 19 |
| 17 SerialConnection::~SerialConnection() { | 20 DCB dcb = { 0 }; |
| 18 } | 21 dcb.DCBlength = sizeof(dcb); |
| 22 if (!GetCommState(file_, &dcb)) |
| 23 return false; |
| 19 | 24 |
| 20 bool SerialConnection::Open() { | 25 // TODO(miket): when we have a bit rate API, use it. |
| 21 // TODO(miket): implement | 26 dcb.BaudRate = CBR_57600; |
| 22 return false; | 27 dcb.ByteSize = 8; |
| 23 } | 28 dcb.StopBits = ONESTOPBIT; |
| 29 dcb.Parity = NOPARITY; |
| 30 if (!SetCommState(file_, &dcb)) |
| 31 return false; |
| 24 | 32 |
| 25 void SerialConnection::Close() { | 33 return true; |
| 26 // TODO(miket): implement | |
| 27 } | |
| 28 | |
| 29 int SerialConnection::Read(uint8* byte) { | |
| 30 // TODO(miket): implement | |
| 31 return -1; | |
| 32 } | |
| 33 | |
| 34 int SerialConnection::Write(scoped_refptr<net::IOBuffer> io_buffer, | |
| 35 int byte_count) { | |
| 36 // TODO(miket): implement | |
| 37 return -1; | |
| 38 } | 34 } |
| 39 | 35 |
| 40 } // namespace extensions | 36 } // namespace extensions |
| OLD | NEW |