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*21
what 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!
I don't believe it's the MFi program.
If you’re using External Accessory framework then, yes, the accessory is MFi. An accessory must be MFi for the EA framework to talk to it.
It seems like your device has two interfaces:
an NMEA 0183 interface, which produces ASCII data — This is what you’re Android app is getting.
an EA stream, which produces binary data — This is what your iOS app is getting.
If you want to continue with the EA stream approach, you will either have to talk to the vendor to get a specification of the format of that stream or reverse engineer it for yourself.
Share and Enjoy
—
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"