Skip to content
This repository has been archived by the owner on Jan 27, 2024. It is now read-only.

Commit

Permalink
handle removal of the serialdevice
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarnedevel0per committed Sep 11, 2018
1 parent 1b9591e commit db7a3b7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/SwiftSerial.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public enum PortError: Int32, Error {
case mustBeOpen
case stringsMustBeUTF8
case unableToConvertByteToCharacter
case deviceNotConnected
}

public class SerialPort {
Expand Down Expand Up @@ -371,7 +372,13 @@ extension SerialPort {
guard let fileDescriptor = fileDescriptor else {
throw PortError.mustBeOpen
}


var s: stat = stat()
fstat(fileDescriptor, &s)
if s.st_nlink != 1 {
throw PortError.deviceNotConnected
}

let bytesRead = read(fileDescriptor, buffer, size)
return bytesRead
}
Expand Down

0 comments on commit db7a3b7

Please sign in to comment.