yeokm1 / SwiftSerial

A Swift Linux and Mac library for reading and writing to serial ports.
MIT License
136 stars 40 forks source link

Macos Mojave xcode 10.2.1 app not work but console work #13

Closed zhuyeaini9 closed 5 years ago

zhuyeaini9 commented 5 years ago

Macos Mojave Xcode 10.2.1 create a new macos app:

  1. I have enable the hardware->usb in xcode,the entitlements shows com.apple.security.device.usb --- boolean --- YES

  2. the device is connect via usb ok,it shows its name when I input cmd in ternimal:ls /dev/cu.* I use cmd "screen /dev/cu.usbserial-DQ007X60 115200" in bash and it return correct info.

  3. the code I used: do { let sp: SerialPort = SerialPort(path:"/dev/cu.usbserial-DQ007X60") try sp.openPort() print("OK") } catch { print("error") } but the program always print error.

when I create a new macos console app: the same code but it print OK...

why???do I missed some steps?

yeokm1 commented 5 years ago

Hi @zhuyeaini9 Do you have your sample code hosted somewhere for both of your Mac OS app and terminal app? So I can test both apps myself.

zhuyeaini9 commented 5 years ago

the two code is same,I just changed the SerialPort to support singleton.

the macos console code is very simple:

**import Foundation

print("Hello, World!")

let sp = SerialPort.sharedInstance do { try sp.openPort(path: "/dev/cu.usbserial-DQ007X60") print("ok") } catch{ print("error") }** the result is ok.

the macos cocoa app code is simple also,it just have a button,when click button: **@IBAction func onClickTest(_ sender: NSButton) { let sp = SerialPort.sharedInstance do { try sp.openPort(path: "/dev/cu.usbserial-DQ007X60")

        print("ok")
    }
    catch{
        print("error")
    }

}**

the result is error.

zhuyeaini9 commented 5 years ago

Hi: I test myself and find that when I turn off App SandBox under project's capablities,it's ok.the cocoa app can open port correctly!!!

T1mofi commented 5 years ago

Hi: I test myself and find that when I turn off App SandBox under project's capablities,it's ok.the cocoa app can open port correctly!!!

I spend 5 hours, before read this. Thank you for solution.