Skip to content

Unable to connect to HID reply port using FBSimulatorControl framework #525

Description

@aravindgs

Using FBSimulatorControl in a CLI to control multiple simulators and I am not able to register HID port

Description

I am launching the device in direct launch mode. I am able to create the simulator. I am creating the HID, and then boot the simulator. But then when I try to connect the HID port, it fails. The error shows the port has not been registered

Reproduction

       // Creatind HID
        let simHIDFuture = FBSimulatorHID.hid(for: self.sim!)
        simHIDFuture.onQueue(.main, notifyOfCompletion: {(simHIDFut) in
            
        })
        do {
            try simHIDFuture.await()
        } catch let simHIDCreateError {
            print("[Error]HID creation for simulator \(sim!.udid) failed because \(simHIDCreateError.localizedDescription)")
            throw simHIDCreateError
        }
        self.simHID = simHIDFuture.result!
       
        // Booting simulator in direct launch mode
        let bootOptions = FBSimulatorBootOptions.enableDirectLaunch
        let bootConfiguration = FBSimulatorBootConfiguration.default.withScale(scale).withOptions(bootOptions)
        if sim?.state != .booted {
            let simBootFuture = sim?.boot(with: bootConfiguration)
            simBootFuture?.onQueue(.main, notifyOfCompletion: { (simBoot) in
                
            })
            do {
                try simBootFuture?.await()
                
            } catch let bootError {
                print("[Error] Failed to boot simulator \(sim!.udid) because \(bootError.localizedDescription)")
                throw bootError
            }
            let _ = simBootFuture?.result
        }

        // Connecting HID for reply port
        let simHIDConnectFuture = simHID!.connect()
        simHIDConnectFuture.onQueue(.main, notifyOfCompletion: { (simHIDConnectFuture) in

        })
        do {
            try simHIDConnectFuture.await()
        } catch let hidConnectError {
            print("[Error] HID reply port failed to connect to simulator \(sim!.udid) because \(hidConnectError.localizedDescription)")
            throw hidConnectError
        }
        let _ = simHIDConnectFuture.result

The console will print [Error] HID reply port failed to connect to simulator 04B6D540-3E5A-4343-AEEE-4DE9B40B56DA because Cannot connect when there is no registration port

Can anyone please let me know what I am missing out?

Activity

  1. lawrencelomax commented on May 22, 2019

    @lawrencelomax
    Contributor

    The HID object can't be created until the Simulator is booted.

    If you want to access this, use the connectToHID method on FBSimulator instead, this should ensure that all the invariants are met. For the most part, you'll not need to create instances of most helper classes yourself, they are all exposed on FBSimulator.

  2. aravindgs commented on May 23, 2019

    @aravindgs
    Author

    @lawrencelomax I used the connectToHID method as suggested. I was able to get the HID object. But I was unable to obtain the reply port.

    The registration port was 14671.
    It failed to connect to the reply port. It produced an error.

    The console log was [Error] Failed to get the Indigo Reply Port 268451843

    func bootSimulator() throws {
        let bootOptions = FBSimulatorBootOptions.enableDirectLaunch
        let bootConfiguration = FBSimulatorBootConfiguration.default.withScale(scale).withOptions(bootOptions)
        if sim?.state != .booted {
            let simBootFuture = sim?.boot(with: bootConfiguration)
            simBootFuture?.onQueue(.main, notifyOfCompletion: { (simBoot) in
                
            })
            do {
                try simBootFuture?.await()
                
            } catch let bootError {
                print("[Error] Failed to boot simulator \(sim!.udid) because \(bootError.localizedDescription)")
                throw bootError
            }
        }
        do {
            let simConFut = sim?.connect()
            simConFut?.onQueue(DispatchQueue.main, notifyOfCompletion: { (simConFuture) in
                
            })
            try simConFut?.await()
            simCon = simConFut?.result
            
            let simHIDFuture = self.simCon?.connectToHID()
            simHIDFuture?.onQueue(.main, notifyOfCompletion: { (simHIDFut) in
                
            })
            try simHIDFuture?.await()
            self.simHID = simHIDFuture?.result
            
            let hidConnectFuture = self.simHID?.connect()
            hidConnectFuture?.onQueue(.main, notifyOfCompletion: { (hidConnectFut) in
    
            })
            try hidConnectFuture?.await()
            _ = hidConnectFuture?.result
            
        } catch let hidConnectError{
            print("[Error] \(hidConnectError.localizedDescription)")
            throw hidConnectError
        }
    }
    
  3. lawrencelomax commented on May 30, 2019

    @lawrencelomax
    Contributor

    Can you make sure that SimulatorKit is loaded by using FBSimulatorControlFrameworkLoader.xcodeFrameworks.loadPrivateFrameworksOrAbort before any of the calls?

    I think your code is taking an old code path that might not work on newer versions of xcode.

  4. aravindgs commented on Jul 12, 2019

    @aravindgs
    Author

    I have tried in different machines. The result seems to be same. Used FBSimulatorControlFrameworkLoader.xcodeFrameworks.loadPrivateFrameworksOrAbort. The path seems to be fine. Still the HID registration port is connected but the reply port is not getting registered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions