I've developed this for the android and simply used a bufferedreader and
br.readline() and the code properly interpreted the data coming through.I should be getting data that looks like this:
$GPRMC,191830.00,A,4159.87613,N,09338.29258,W,0.065,303.4,270815,0.8,E,D*21what I am getting is data that looks like this:
(WK#
The code in viewDidLoad()
if accessoryList.count > 0 {
var accessory = accessoryList[0] as! EAAccessory
accessory.delegate = self
println(accessoryList[0].description)
session = EASession(accessory: accessoryList[0] as! EAAccessory, forProtocol: "com.trimble.mcs.gnss")
if session != nil {
inputStream = session.inputStream
/
inputStream.delegate = self
inputStream.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
inputStream.open()
}
}
and the stream code
func stream(aStream: NSStream, handleEvent eventCode: NSStreamEvent) {
let inStream = aStream as? NSInputStream
switch (eventCode){
case NSStreamEvent.OpenCompleted:
NSLog("Stream opened")
break
case NSStreamEvent.HasBytesAvailable:
/
let bufferSize = 8
var buffer = [UInt8](count: bufferSize, repeatedValue: 0)
while(session.inputStream!.hasBytesAvailable) {
let result :Int = session.inputStream!.read(&buffer, maxLength: bufferSize)
if(result > 0){
var output = NSString(bytes: &buffer, length: bufferSize, encoding: NSUTF8StringEncoding)
if(output != nil) {
print(output!)
}
}
}
println("")
break
case NSStreamEvent.ErrorOccurred:
NSLog("ErrorOccurred")
break
case NSStreamEvent.EndEncountered:
NSLog("EndEncountered")
break
default:
NSLog("unknown.")
}
}
Is there something I'm missing? I'm getting data, it's just not in english. I know that the encoding is UTF8. Any help would be appreciated!