- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
Microchip 发布具有私有(private) MLDP 配置文件的 RN4020 BT LE 芯片已经有好几年了。然而,到目前为止,仍然没有公开可用的 iOS 示例源代码可用,尽管他们在 Apple App Store 中有一个 iOS 应用程序。有没有人有任何工作代码并愿意分享/发布它?
谢谢!
蒂姆
最佳答案
我有一些工作代码。我会在这里给出一些片段。在符合 CBCentralManagerDelegate
的第一个 ViewController 中,我们有:
var cbc : CBCentralManager? = nil
override func viewDidLoad() {
super.viewDidLoad()
cbc = CBCentralManager(delegate: self, queue: nil)
}
触摸一个按钮开始扫描外围设备
@IBAction func scan(_ sender: Any) {
cbc?.scanForPeripherals(withServices: nil, options: nil)
}
对于找到的每个外围设备,将调用以下委托(delegate)成员
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
// store peripherals here to let select user one
NSLog("name=%@", peripheral.name ?? "unnamed")
}
我们将外围设备存储在字典中,并使用表格 View 将其名称呈现给用户。如果用户选择了一个外设,我们会尝试连接到它
@IBAction func connect(_ sender: Any) {
// selectedPeripheral set by selection from the table view
cbc?.connect(selectedPeripheral!, options: nil)
}
成功的连接将调用以下委托(delegate)方法:
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
performSegue(withIdentifier: "ConnectPeriph", sender: self)
}
这导致第二个 ViewController 负责连接状态。此 ViewController 符合 CBPeripheralDelegate
协议(protocol)并声明以下变量:
var periph : CBPeripheral! // selected peripheral
var dataChar : CBCharacteristic? // characteristic for data transfer
let mchpPrivateService : CBUUID = CBUUID(string: "00035B03-58E6-07DD-021A-08123A000300")
let mchpDataPrivateChar : CBUUID = CBUUID(string: "00035B03-58E6-07DD-021A-08123A000301")
连接后的第一个 Action 是发现外设提供的服务:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
periph.delegate = self
periph.discoverServices(nil)
}
这导致调用此委托(delegate)方法:
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
if let e = error {
NSLog("Error %@", e.localizedDescription)
}
else if let services = peripheral.services {
for s in services {
NSLog("Service=%@", s.uuid.uuidString)
if s.uuid.isEqual(mchpPrivateService) {
peripheral.discoverCharacteristics(nil, for: s)
}
}
}
}
这反过来会导致发现特征:
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
NSLog("characteristics for service %@", service.uuid.uuidString)
if let characteristics = service.characteristics {
for c in characteristics {
if c.uuid.isEqual(mchpDataPrivateChar) {
peripheral.setNotifyValue(true, for: c)
dataChar = c
}
}
}
}
我们唯一感兴趣的特征是具有 uuid 的 mchpDataPrivateChar
。通知请求导致调用:
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
NSLog("update value for %@", characteristic.uuid)
if let d = characteristic.value {
var s : String = String()
for b in d {
s.append(Character(UnicodeScalar(b)))
}
NSLog("received \(d.count) bytes: \(s)")
}
}
这就完成了 iOS 端的接收器。通过以下方式发送字节:
@IBAction func sendClicked(_ sender: Any) {
if let d = dataChar, let s=sendEdit.text {
let buffer : [UInt8] = Array(s.utf8)
let data : Data = Data(buffer)
periph.writeValue(data, for: d, type: .withResponse)
}
}
关于ios - Microchip RN4020 -> MLDP模式iOS示例代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40785023/
也许对我来说,这是一个很小但很难解决的问题。如果有人能把我引向正确的方向来解决这个问题,我将不胜感激。。我正在尝试构建大约10年前的文件,但收到此错误的是MicroChip Studio 7.0.13
我正在使用一对 MRF24J40 radio 芯片来让一个 PIC32 微 Controller 板通过射频传输与另一个微 Controller 板进行通信。我的所有代码都可以正常编译,但我不断收到与
我正在编写与外部 RF 芯片的 SPI 通信。微 Controller 为Microchip的型号PIC24FJ64GA102。 我想使用 SPI 的增强缓冲模式。 问题:从接收缓冲区中取出接收到的字
我正在努力让 PIC16F1829 进入休眠模式。该装置消耗大约 18mA,而数据表在深度 sleep 模式下引用 20nA。谁能帮忙? 根据数据表,我必须执行以下操作“WDT、BOR、FVR 和 T
我正在使用 Microchip C18 编译器,并且在发生中断时,我在 ISR 代码开始运行之前遇到了相当长的延迟。 作为一个实验,这是我的主要功能: while(1) { LATAbits.
按下按钮后我无法跳出 if 语句。按钮激活继电器,按下按钮则关闭继电器。 这是我的完整代码:我是 C 新手,因此非常感谢所有评论和建议。 #include "mcc_generated_files/
我正在为 ARM Cortex M4 使用 ASF4 API hal_timer。我正在使用定时器驱动程序对数据序列进行计时。为什么不存在重置功能?我在 TIMER_TASK_ONE_SHOT 模式下
我刚开始学习用于 pic 编程的 C,我正在查看其他人的代码和编译器提供的包含文件,尤其是基础代码(xc.h、pic.h、pic特定的标题...),我看到了这个结构(它在 pic.h 中找到) #de
Microchip 发布具有私有(private) MLDP 配置文件的 RN4020 BT LE 芯片已经有好几年了。然而,到目前为止,仍然没有公开可用的 iOS 示例源代码可用,尽管他们在 App
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
当我遇到一大堆看起来像这样的结构时,我正在挖掘一些与 PIC 微 Controller 相关的头文件: typedef struct tagPORTDBITS { unsigned RD0:1;
我试图在自由模式下使用 xc8 编译器和 pic16f876a 的项目在库中声明一个类。但 xc8 编译器似乎不接受或编译类... 这是真的吗?如果没有,有人可以发布一个例子吗? 谢谢!! 最佳答案
我想在proteus中模拟我做的一个程序,但是它是在linux上使用MPLABX编译的,proteus运行在虚拟机和windows XP中。我的电脑硬件较少,所以尝试在虚拟机上运行 MPLABX 对我
我正在尝试创建一个包含指向常量数组的指针的数组。我在 MPLABX 中使用 C30 V3.31,我正在尝试使用 PIC24FJ128GA310 为我的 LCD 创建一个分段图。这个想法是让所有的 LC
我问这个只是出于好奇。 我正在使用 Microchip C30 编译器为 PIC24F 开发 EEPROM 驱动程序代码。在此期间,我使用了 C30 内置函数,例如__builtin_tblwtl()
我需要让一台设备与两台服务器通信。 Microchip TCP/IP 协议(protocol)栈是否可行? 最佳答案 您可以(也应该)阅读文档,或咨询 Microchip 支持人员。 Microchi
有人可以建议一个用于 Microchip PIC18 处理器的 Modbus RTU 从站的开源实现吗?我正在寻找用于 RS-232/RS-485 的 Modbus RTU 实现,但也欢迎 Modbu
我在 8 位微 Controller 上使用 Microchip 的免费 TCP/IP(4.55 版)堆栈。 我正在尝试在不使用 asm("RESET") 进行全板重置的情况下重置堆栈。 关于如何重新
我想使用微 Controller 通过 SPI 进行数据通信。因此,我首先选择了带有 PIC32MX470F512L 的 Microchip USB Starter Kit III 模块。我尝试了几种
我在使用 PIC18F67J60 的 Microchip C18 编译器时遇到了这个奇怪的问题。 我创建了一个非常简单的函数,它应该返回较大字符串中子字符串的索引。 我不知道出了什么问题,但该行为似乎
我是一名优秀的程序员,十分优秀!