Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
TimeoutMultipleSerial.cpp
00001 #include "TimeoutMultipleSerial.h" 00002 00003 int TimeoutMultipleSerial::readMultChars (uint8_t* const dest, 00004 const size_t size) { 00005 00006 timer.reset(); 00007 timer.start(); 00008 00009 size_t counter = 0; 00010 while (counter < size 00011 && timer.read_ms() < timeout) { 00012 00013 while (!port.readable() 00014 && timer.read_ms() < timeout) wait_ms(1); 00015 00016 if (port.readable()) { 00017 *(dest + counter) = (uint8_t) (port.getc()); 00018 ++counter; 00019 } 00020 } 00021 00022 timer.stop(); 00023 00024 if (counter != size) { 00025 return -1; 00026 } 00027 00028 return 1; 00029 } 00030 00031 int TimeoutMultipleSerial::writeMultChars (const uint8_t* source, 00032 const size_t size) { 00033 00034 timer.reset(); 00035 timer.start(); 00036 00037 size_t counter = 0; 00038 while (counter < size 00039 && timer.read_ms() < timeout) { 00040 00041 while (!port.writeable() 00042 && timer.read_ms() < timeout) wait_ms(1); 00043 00044 if (port.writeable()) { 00045 port.putc((int) (*(source + counter))); 00046 ++counter; 00047 } 00048 } 00049 00050 timer.stop(); 00051 if (counter != size) { 00052 return -1; 00053 } 00054 00055 return 1; 00056 } 00057 00058 int TimeoutMultipleSerial::clearAll() { 00059 while (port.readable()) port.getc(); 00060 return 1; 00061 } 00062 00063 void TimeoutMultipleSerial::setTimeout (uint32_t tout) { 00064 timeout = tout; 00065 } 00066 00067 void TimeoutMultipleSerial::setBaud (uint32_t baud) { 00068 port.baud(baud); 00069 } 00070 00071 void TimeoutMultipleSerial::setFormat (int bits, 00072 SerialBase::Parity parity, 00073 int stop_bits) { 00074 00075 port.format(bits, parity, stop_bits); 00076 }
Generated on Wed Jul 13 2022 12:36:28 by
1.7.2