gpt4 book ai didi

ios - 无法使用类型为 '(UInt64)' 的参数列表调用

转载 作者:行者123 更新时间:2023-11-28 10:24:56 25 4
gpt4 key购买 nike

我正在构建机械臂,并打算使用 iOS 应用程序控制机械臂。我无法将位置发送到 arduino 蓝牙 4.0 屏蔽。

我正在使用 slider 来控制 ARM 的位置。

有两个错误。

  1. “无法使用类型为‘(UInt8)’的参数列表调用‘writePosition’”
  2. “无法使用类型为‘(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 之间的简单转换,但这些都没有用。

最佳答案

您的问题是您使用的 int 类型不同。

首先让我们检查一下writePosition 方法。您使用 Int8 作为参数。因此,您需要确保还使用 Int8 作为参数调用该方法。为确保您使用的是 Int8,您可以强制转换它:

bleService.writePosition(Int8(position))

如您所见,您需要将 position 转换为 Int8

现在检查您的sendPosition 方法。你有一个类似的问题。你想要一个 UInt8 作为参数,但是你用一个 UInt64 参数调用它。那是你做不到的。您需要使用相同的整数类型:

self.sendPosition(UInt8(self.currentClawValue.value))

这里也是一样的。使用 UInt8 而不是 UInt64 来进行转换。

关于ios - 无法使用类型为 '(UInt64)' 的参数列表调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28685213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com