我正在构建一个机械臂并使用 iOS 应用程序控制机械臂。我无法将位置发送到 arduino 蓝牙 4.0 防护罩。
我正在使用滑块来控制手臂的位置。
有两个错误。
- “不能使用 '(UInt8)' 类型的参数列表调用 'writePosition'”
“不能使用 '(UInt64)' 类型的参数列表调用 'sendPosition'”
func sendPosition(position: UInt8) if !self.allowTX { return } // Validate value if UInt64(position) == lastPosition { return } else if ((position < 0) || (position > 180)) { return } // Send position to BLE Shield (if service exists and is connected) if let bleService = btDiscoverySharedInstance.bleService { bleService.writePosition(position) ***1)ERROR OCCURS ON THIS LINE*** lastPosition = position // Start delay timer self.allowTX = false if timerTXDelay == nil { timerTXDelay = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: Selector("timerTXDelayElapsed"), userInfo: nil, repeats: false) } } } func timerTXDelayElapsed() { self.allowTX = true self.stopTimerTXDelay() // Send current slider position self.sendPosition(UInt64(self.currentClawValue.value)) **2)ERROR OCCURS ON THIS LINE**
}
这是我的“writePosition”函数。
func writePosition(position: Int8) {
// See if characteristic has been discovered before writing to it
if self.positionCharacteristic == nil {
return
}
// Need a mutable var to pass to writeValue function
var positionValue = position
let data = NSData(bytes: &positionValue, length: sizeof(UInt8))
self.peripheral?.writeValue(data, forCharacteristic: self.positionCharacteristic, type: CBCharacteristicWriteType.WithResponse)
}
我不知道我是遗漏了什么还是完全遗漏了什么。我尝试过 UInt8 和 UInt64 之间的简单转换,但没有奏效。