| 270 | } |
| 271 | |
| 272 | void Serial::readBytes( void *data, size_t numBytes ) |
| 273 | { |
| 274 | size_t totalBytesRead = 0; |
| 275 | while( totalBytesRead < numBytes ) { |
| 276 | #if defined( CINDER_MAC ) || defined( CINDER_LINUX ) |
| 277 | long bytesRead = ::read( mImpl->mFd, data, numBytes - totalBytesRead ); |
| 278 | if( ( bytesRead == -1 ) && ( errno != EAGAIN ) ) |
| 279 | throw SerialExcReadFailure(); |
| 280 | #elif defined( CINDER_MSW ) |
| 281 | ::DWORD bytesRead = 0; |
| 282 | if( ! ::ReadFile( mImpl->mDeviceHandle, data, static_cast<DWORD>( numBytes - totalBytesRead ), &bytesRead, 0 ) ) |
| 283 | throw SerialExcReadFailure(); |
| 284 | #endif |
| 285 | if( bytesRead != -1 ) |
| 286 | totalBytesRead += bytesRead; |
| 287 | |
| 288 | // yield thread time to the system |
| 289 | this_thread::yield(); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | size_t Serial::readAvailableBytes( void *data, size_t maximumBytes ) |
| 294 | { |