[gnoduino: 81/237] bugfix - Serial.write() would try to send even if no CDC connection was open.
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnoduino: 81/237] bugfix - Serial.write() would try to send even if no CDC connection was open.
- Date: Sat, 31 Mar 2012 20:21:37 +0000 (UTC)
commit 3687d35b9f231f80164715a9186841b50e7bdd85
Author: Zach Eveland <zeveland blacklabel-development com>
Date: Wed Aug 24 21:04:30 2011 -0400
bugfix - Serial.write() would try to send even if no CDC connection was open.
arduino/cores/arduino/CDC.cpp | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
---
diff --git a/arduino/cores/arduino/CDC.cpp b/arduino/cores/arduino/CDC.cpp
index 7d9d682..7da9077 100644
--- a/arduino/cores/arduino/CDC.cpp
+++ b/arduino/cores/arduino/CDC.cpp
@@ -155,7 +155,17 @@ void Serial_::flush(void)
void Serial_::write(uint8_t c)
{
- USB_Send(CDC_TX,&c,1);
+ /* only try to send bytes if the high-level CDC connection itself
+ is open (not just the pipe) - the OS should set lineState when the port
+ is opened and clear lineState when the port is closed.
+ bytes sent before the user opens the connection or after
+ the connection is closed are lost - just like with a UART. */
+
+ // TODO - ZE - check behavior on different OSes and test what happens if an
+ // open connection isn't broken cleanly (cable is yanked out, host dies
+ // or locks up, or host virtual serial port hangs)
+ if (_usbLineInfo.lineState > 0)
+ USB_Send(CDC_TX,&c,1);
}
Serial_ Serial;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]