11
11
import Darwin. C
12
12
#endif
13
13
14
+ import Foundation
14
15
import SwiftyGPIO
15
16
16
17
public class SwiftyXBee {
@@ -53,22 +54,24 @@ public class SwiftyXBee {
53
54
54
55
/// Reads and process an RF data packet.
55
56
///
57
+ /// - Parameter maxTimeout: The maximum time to wait before checking the serial port for data
56
58
/// - Returns: A Receive Packet API Frame
57
59
/// - Throws: Any error while reading the RF data packet
58
- public func readRFDataPacket( ) throws -> APIFrame < ZigBeeReceivePacketData > {
59
- let rawData = try readSerialData ( )
60
+ public func readRFDataPacket( maxTimeout : TimeInterval = Constant . defaultReadDataTimeout ) throws -> APIFrame < ZigBeeReceivePacketData > {
61
+ let rawData = try readSerialData ( maxTimeout : maxTimeout )
60
62
let frameData = ZigBeeReceivePacketData ( rawData: rawData)
61
63
return try APIFrame ( rawData: rawData, frameData: frameData)
62
64
}
63
65
64
66
/// Reads the transmission status after issuing a Transmit Request API Frame.
65
67
///
68
+ /// - Parameter maxTimeout: The maximum time to wait before checking the serial port for data
66
69
/// - Returns: A Transmit Status API Frame
67
70
/// - Throws: Any error while reading the transmit status packet
68
71
/// - Note: If delivery status is 0x00, the transmission was successfully delivered to the destination address.
69
72
/// Otherwise, the number received in this byte will indicate the kind of issue that prevented the delivery.
70
- public func readTransmitStatus( ) throws -> APIFrame < ZigBeeTransmitStatusData > {
71
- let rawData = try readSerialData ( )
73
+ public func readTransmitStatus( maxTimeout : TimeInterval = Constant . defaultReadDataTimeout ) throws -> APIFrame < ZigBeeTransmitStatusData > {
74
+ let rawData = try readSerialData ( maxTimeout : maxTimeout )
72
75
let frameData = ZigBeeTransmitStatusData ( rawData: rawData)
73
76
return try APIFrame ( rawData: rawData, frameData: frameData)
74
77
}
@@ -88,20 +91,22 @@ public class SwiftyXBee {
88
91
89
92
/// Reads and process an AT Command response
90
93
///
94
+ /// - Parameter maxTimeout: The maximum time to wait before checking the serial port for data
91
95
/// - Returns: An AT Command Response Frame
92
96
/// - Throws: Any error while reading the RF data packet
93
- public func readATCommandResponse( ) throws -> APIFrame < ATCommandResponseData > {
94
- let rawData = try readSerialData ( )
97
+ public func readATCommandResponse( maxTimeout : TimeInterval = Constant . defaultReadDataTimeout ) throws -> APIFrame < ATCommandResponseData > {
98
+ let rawData = try readSerialData ( maxTimeout : maxTimeout )
95
99
let frameData = ATCommandResponseData ( rawData: rawData)
96
100
return try APIFrame ( rawData: rawData, frameData: frameData)
97
101
}
98
102
99
103
/// Reads the serial port.
100
104
///
105
+ /// - Parameter maxTimeout: The maximum time to wait before checking the serial port for data
101
106
/// - Returns: All the available data in the serial port
102
- /// - Throws: Any errors while reading the serial port
103
- public func readSerialData( ) throws -> [ UInt8 ] {
104
- return try serial. readData ( from: uart)
107
+ /// - Throws: Any errors while reading the serial port
108
+ public func readSerialData( maxTimeout : TimeInterval = Constant . defaultReadDataTimeout ) throws -> [ UInt8 ] {
109
+ return try serial. readData ( from: uart, maxTimeout : maxTimeout )
105
110
}
106
111
107
112
/// Writes data to the serial port.
0 commit comments