I used DeviceConnect sample code from "The Bosch GLM/PLR Bluetooth App Kit" to add BoschGLM support into my framework. I connected CBPeripheral (save it strong var), created MTDataExchengeService: fileprivate func createDataExchangeService(peripheral: CBPeripheral) -> Bool {
guard let dataExchangeService = MTDataExchangeService.dataExchangeService(with: peripheral) as? MTDataExchangeService else {
return false
}
self.dataExchangeService = dataExchangeService
dataExchangeService.delegate = self
dataExchangeService.isConnectedToGLM = isGLM
dataExchangeService.serviceUUID = type(of: self).dataServiceUUID.uuidString
dataExchangeService.charectristicsRXUUID = type(of: self).receiveCharacteristicUUID?.uuidString
dataExchangeService.charectristicsTXUUID = type(of: self).sendCharacteristicUUID?.uuidString
dataExchangeService.initialize()
return true
} and added MTProtocol func dataExchangeService(_ service: MTDataExchangeService!, didInitilizeWithError error: Error!) {
if let error = error {
dlog("[Bosch] Initializitaion callback: \(error)")
disconnect { _ in }
} else {
dlog("[Bosch] Initializitaion callback: init completed, no error.")
self.mtProtocol = MTProtocol.`protocol`() as! MTProtocol
self.mtProtocol.connection = service
self.mtProtocol.delegate = self
service.delegate = self.mtProtocol
dlog("[Bosch] MTProtocol ready ... \(mtProtocol.isReady)")
turnOnAutoSync()
}
} turnOnAutoSync is method from AppKit sample and for GLM165 it send the following request: let message = MTExchangeDataOutputMessage.message() as! MTExchangeDataOutputMessage
message.syncControl = MODE_AUTOSYNC_CONTROL_ON
self.mtProtocol.sendRequest(message) But into MTProtocolDelegate: func `protocol`(_ protocol: MTProtocol!, didReceive message: MTMessage!) {
dlog("[Bosch] MMProtocol didReceiveMessage: \(message.description)")
....
} I got only 1 packet for 1st measurement after connect, and no more - other measurement nothing posting [10:01:50.110] [Bosch] MMProtocol didReceiveMessage: MTExchangeDataInputMessage mode: 0 distReference: 0 errorStatus: 0 laserOn: 0 temperatureWarning: 0 batteryWarning: 0 measurementId: 25 result: 0.000000 component1: 0.000000 component2: 0.000000 When testings DeviceConnect with the same GLM165-27C, I get 2 packets for each measurement, like: [15:07:19.196] MMProtocol didReceiveMessage: MTExchangeDataInputMessage mode: 1 distReference: 0 errorStatus: 0 laserOn: 0 temperatureWarning: 0 batteryWarning: 0 measurementId: 17 result: 3.278450 component1: 0.000000 component2: 0.000000 [15:07:23.336] MMProtocol didReceiveMessage: MTExchangeDataInputMessage mode: 0 distReference: 0 errorStatus: 0 laserOn: 1 temperatureWarning: 0 batteryWarning: 0 measurementId: 17 result: 0.000000 component1: 0.000000 component2: 0.000000 What could be the reason for this problem? UPD: it looks like first packet with mode, laserOn and resultValue set to zeros is response on turnOnAutoSync (MODE_AUTOSYNC_CONTROL_ON), so my app doesn't get measurements at all
... View more