Skip to content

Commit 23e6f16

Browse files
SidLeungcalvinatintel
authored andcommitted
Jira-462: Call Available() after calling end() indicated data available.
Code Modifications: 1. Added checking of device open in these routines: available, read, peek. Will return 0 or -1 if device is not opened to indicate invalid operation.
1 parent 4651999 commit 23e6f16

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cores/arduino/CDCSerialClass.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ void CDCSerialClass::end( void )
8484
int CDCSerialClass::available( void )
8585
{
8686
#define SBS SERIAL_BUFFER_SIZE
87+
88+
if (!_shared_data->device_open)
89+
return (0);
90+
else
8791
return (int)(SBS + _rx_buffer->head - _rx_buffer->tail) % SBS;
8892
}
8993

@@ -102,15 +106,15 @@ int CDCSerialClass::availableForWrite(void)
102106

103107
int CDCSerialClass::peek(void)
104108
{
105-
if ( _rx_buffer->head == _rx_buffer->tail )
109+
if ((!_shared_data->device_open) || ( _rx_buffer->head == _rx_buffer->tail ))
106110
return -1;
107111

108112
return _rx_buffer->data[_rx_buffer->tail];
109113
}
110114

111115
int CDCSerialClass::read( void )
112116
{
113-
if ( _rx_buffer->head == _rx_buffer->tail )
117+
if ((!_shared_data->device_open) || ( _rx_buffer->head == _rx_buffer->tail ))
114118
return -1;
115119

116120
uint8_t uc = _rx_buffer->data[_rx_buffer->tail];

0 commit comments

Comments
 (0)