Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's in this pull request?
Adds an
usleep
invocation right after theread(fd, &buf, buf.count * MemoryLayout<CChar>.stride)
call onreadData
function on the UART.swift class in order to be able to fully read all the available data on the serial port before returning.Is there something you want to discuss?
For my SwiftyXBee library, I am checking whether there is available data on the serial port right before trying to read actual data from it; in order to avoid blocking my program in case there is no data available. Pretty often, I would be getting this crash:
Fatal error: Index out of range: file /home/buildSwiftOnARM/swift/stdlib/public/core/ContiguousArrayBuffer.swift, line 369
when callinguart.hasAvailableData()
immediately followed byuart.readData()
.By trial an error, I found out that adding a 100ms sleep call right after the actual
read
method, would allow all the data to be read, so thatArray(buf[0..<n])
at the return of thereadData
method wouldn't cause me a crash. I know it is not the most elegant solution, but it does its job.Pull Request Checklist