使用绑定速率配置外部附件 - 解释输出流

时间:2017-08-30 08:41:50

标签: swift swift3

我与硬件建立了连接,每10秒钟后数据会返回一次。返回的数据没有告诉我什么,我怎么能解释它?

修改

打开附件:

public func openAccessory() {
        let _accessories = getConnectedAccessories()
        var _accessory: EAAccessory?

        for acsy in _accessories {
            if acsy.protocolStrings.contains("com.protocol.link") {
                _accessory = acsy
            }
        }
        if _accessory != nil {
            let session = EASession(accessory: _accessory!, forProtocol: "com.protocol.link")
            if session != nil {
                guard let inputStream2 = session?.inputStream else {
                    return
                }
                inputStream2.delegate = self
                inputStream2.schedule(in: .current, forMode: .defaultRunLoopMode)
                inputStream = inputStream2
                inputStream.open()
                session?.outputStream?.delegate = self
                session?.outputStream?.schedule(in: .current, forMode: .defaultRunLoopMode)
                session?.outputStream?.open()
            }
        }
    }

阅读流:

func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
        switch eventCode{
        case Stream.Event.hasBytesAvailable:
            if (aStream == inputStream) {
                var buffer = [UInt8](repeating: 0, count: 9)
                while (inputStream.hasBytesAvailable) {
                    let bytesRead: Int = inputStream.read(&buffer, maxLength: buffer.count)
                    if bytesRead > 0 {
                        let data = Data(bytes: buffer)
                        let answer = String.init(data: data, encoding: .ascii)
                        print(answer ?? "")
                    }
                }
            }
        default:
            print("No bytes available")
        }
    }

我的输出仍然相同:

2017-09-14 12:53:49.612822+0200 extDemo[7456:2344109] refreshPreferences: HangTracerEnabled: 1
2017-09-14 12:53:49.613059+0200 extDemo[7456:2344109] refreshPreferences: HangTracerDuration: 500
2017-09-14 12:53:49.613211+0200 extDemo[7456:2344109] refreshPreferences: ActivationLoggingEnabled: 0 ActivationLoggingTaskedOffByDA:0
2017-09-14 12:53:51.343255+0200 extDemo[7456:2344109] eaAccessory CoreAccessoryPrimaryUUID = 467AAB42-8EDD-4256-A0B2-ECFCDB99D986
connected right accessory to the phone
2017-09-14 12:53:51.361954+0200 extDemo[7456:2344109] accessoryd sessionResult = 1, useSocketInterace = 0, sessionID = 0xD
No bytes available
No bytes available
No bytes available
«ÍÕ
«ÍÕ«Í"¦a@ø
«Íbâaþ
«Íbâaþ
«ÍÕ«Í1âéþ
«Í"¦a@ø«Í"¦a@ø
«Íbâaþ
«ÍÕ\246
«Í"¦a@ø
«ÍÕ
«Í"¦öóþ
«ÍÕ\242@æ
«Í"¦a@ø
«Íª1ñ´þ
«Íbâaþ«Í"¦öóþ

但得到了一些额外的信息:

  1. 绑定率为115200 - 我知道如何通过putty设置它,并且收到的消息是应该的。
  2. 在我与我的链接(com.protocol.link)建立连接之后,它是一条电缆,通过它我与LMU一致,我需要配置正确的参数(23字节):

    {0x08,0x00,0x00,0x00,0x00,0x03,0x00,0xC2,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x01}

  3. 我为LMU找到了Guide - 他们说我需要使用套接字端口和UDP协议,但我已经与设备建立了连接,但是收到的消息并不像我所说的那样。 提前致谢!

0 个答案:

没有答案