ORSSerialPort
ORSSerialPort copied to clipboard
Getting duplicate data after closing and opening the port
Hey, I'm really sorry for the noise as I'm sure this is completely user error (demo project works fine) but I'm having a strange issue and you're probably going to know what's wrong right away.
The first time I open the port it works fine but if I close it and open it again I'm getting double the data. If I do this again, I get triple data, etc, etc. Almost as if a callback is being set over and over again but never unset. I can't seem to find where this happens in my code.
This is how I'm opening the port:
@IBAction func recordToggle(sender: AnyObject) {
guard let port = serialPort else {
return
}
let descriptor = ORSSerialPacketDescriptor(prefixString: "{", suffixString: "}", maximumPacketLength: 150, userInfo: nil)
switch recordButton.state {
case NSOffState:
print("Closing serial port \(port)")
port.stopListeningForPacketsMatchingDescriptor(descriptor)
port.close()
case NSOnState:
print("Opening serial port \(port)")
port.startListeningForPacketsMatchingDescriptor(descriptor)
port.open()
default:
break
}
}
same issue here, any update?