【问题标题】:Can't get Notification after connecting serial dock connector between iPhone and iMac在 iPhone 和 iMac 之间连接串行坞站连接器后无法收到通知
【发布时间】:2011-11-27 10:58:07
【问题描述】:

是否可以通过底座连接器将 iMac 连接到 iPhone?我也在使用 EAAccessory 框架,但是当我将串行电缆连接到 iPhone 时,我没有收到任何通知。如果有人知道这件事,请给我一个建议。

【问题讨论】:

  • 请不要删除并重新发布相同的问题 - 您现在已经删除了对原始问题所做的编辑以修复错别字等,并且要求澄清的 cmets 也已被删除 -这是非常粗鲁的。
  • 串行坞站连接器表示串行电缆..
  • serial 电缆是什么意思? “串行”非常模糊。您是在谈论 RS-232 还是什么?
  • 是的,抱歉,保罗,但我的帐户有问题,所以我必须删除它...如果你知道的话,请给我任何解决方案。
  • 你需要先澄清问题

标签: iphone ios external-accessory


【解决方案1】:

如果您将 iPhone 连接到 iMac 并且运行 iTunes 或 Xcode,您将能够看到 iPhone 已连接。

在 Xcode 中,转到管理器窗口。在 iTunes 中,查看左侧栏中的“设备”下方。

我没用过的EAAccessory框架应该和这个没什么关系。

【讨论】:

  • 嗨,感谢您的回答,但是当我将 USB 电缆连接到我的 iPhone 时,我想在我的 iOS 应用程序中收到通知
  • 我也检查了那个 eademo 应用程序,但在那个应用程序中,当我在 iPhone 和 iMac 之间连接 USB 电缆时,我也无法收到任何通知\
  • 我认为EA框架需要对方与iOS设备上的代码进行对话。我不知道 EA 在设计时是否考虑了 Mac 作为附件。我认为他们认为配件是响应 EA 查询的硬件设备。
【解决方案2】:

拉吉..

要获得连接附件的通知,首先您必须将您的附件注册到 MFI。否则你必须越狱你的 iPhone。越狱检查此代码

#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */

static struct termios gOriginalTTYAttrs;

static int OpenSerialPort()
{
    int        fileDescriptor = -1;
    int        handshake;
    struct termios  options;

    // Open the serial port read/write, with no controlling terminal, and don't wait for a connection.
    // The O_NONBLOCK flag also causes subsequent I/O on the device to be non-blocking.
    // See open(2) ("man 2 open") for details.

    fileDescriptor = open("/dev/tty.iap", O_RDWR | O_NOCTTY | O_NONBLOCK);
    if (fileDescriptor == -1)
    {
        printf("Error opening serial port %s - %s(%d).\n",
               "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }

    // Note that open() follows POSIX semantics: multiple open() calls to the same file will succeed
    // unless the TIOCEXCL ioctl is issued. This will prevent additional opens except by root-owned
    // processes.
    // See tty(4) ("man 4 tty") and ioctl(2) ("man 2 ioctl") for details.

    if (ioctl(fileDescriptor, TIOCEXCL) == -1)
    {
        printf("Error setting TIOCEXCL on %s - %s(%d).\n",
            "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }

    // Now that the device is open, clear the O_NONBLOCK flag so subsequent I/O will block.
    // See fcntl(2) ("man 2 fcntl") for details.

    if (fcntl(fileDescriptor, F_SETFL, 0) == -1)
    {
        printf("Error clearing O_NONBLOCK %s - %s(%d).\n",
            "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }

    // Get the current options and save them so we can restore the default settings later.
    if (tcgetattr(fileDescriptor, &gOriginalTTYAttrs) == -1)
    {
        printf("Error getting tty attributes %s - %s(%d).\n",
            "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }

    // The serial port attributes such as timeouts and baud rate are set by modifying the termios
    // structure and then calling tcsetattr() to cause the changes to take effect. Note that the
    // changes will not become effective without the tcsetattr() call.
    // See tcsetattr(4) ("man 4 tcsetattr") for details.

    options = gOriginalTTYAttrs;

    // Print the current input and output baud rates.
    // See tcsetattr(4) ("man 4 tcsetattr") for details.

    printf("Current input baud rate is %d\n", (int) cfgetispeed(&options));
    printf("Current output baud rate is %d\n", (int) cfgetospeed(&options));

    // Set raw input (non-canonical) mode, with reads blocking until either a single character 
    // has been received or a one second timeout expires.
    // See tcsetattr(4) ("man 4 tcsetattr") and termios(4) ("man 4 termios") for details.

    cfmakeraw(&options);
    options.c_cc[VMIN] = 1;
    options.c_cc[VTIME] = 10;

    // The baud rate, word length, and handshake options can be set as follows:

    cfsetspeed(&options, B19200);    // Set 19200 baud    
    options.c_cflag |= (CS8);  // RTS flow control of input


    printf("Input baud rate changed to %d\n", (int) cfgetispeed(&options));
    printf("Output baud rate changed to %d\n", (int) cfgetospeed(&options));

    // Cause the new options to take effect immediately.
    if (tcsetattr(fileDescriptor, TCSANOW, &options) == -1)
    {
        printf("Error setting tty attributes %s - %s(%d).\n",
            "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }    
    // Success
    return fileDescriptor;

    // Failure "/dev/tty.iap"
error:
    if (fileDescriptor != -1)
    {
        close(fileDescriptor);
    }

    return -1;
}

int main(int args, char *argv[])
{
    int fd;
    char somechar[8];
    fd=OpenSerialPort(); // Open tty.iap with no hardware control, 8 bit, BLOCKING and at 19200 baud
    if(fd>-1)
    {
        write(fd,"*",1); // Write handshaking message over serial
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        // After this, our device or our PC program should be strobing serial ground to gain access to the Iphone Serial Line
        //////////////////////////////////////////////////////////////////////////////////////////////////
        read(fd,&somechar[0],1); // Read 1 byte  over serial.  This will block (wait) untill the byte has been received
        if(somechar[0]=='*') // Check if this byte is a "handshaking" message
        {
            printf("Serial connection established!\n"); // If it is, we have established a connection to the device and can freely read/write over serial!
            while(1) // Do this forever or untill someone presses CTRL+C
            {
                read(fd,&somechar[0],1);  // Read a character over serial!
                putchar(somechar[0]); // Write the character to the Terminal!!
            }
        }
    }
    return 0;
}

【讨论】:

    【解决方案3】:

    对于 EAAccessoryManager 及其附带的类,似乎存在很多混淆。这些仅适用于 MFI 认可的硬件,即那些花时间遵循 MFI 计划并将必要的硬件集成到其设备中的制造商。

    使用芯片和建立协议可以促进应用和设备之间的通信流。

    Sam 在他的陈述中是正确的,但是没有必要越狱您的应用程序以绕过 MFI 程序但是,如果您按照我将简要介绍的程序进行操作,您将无法提交到 App Store:

    1. 获取 IOKit iOS OpenSource Browser 的所有头文件
    2. 将它们添加到您的解决方案中
    3. 包含 IOKit.h 框架
    4. 前往http://www.arduino.cc/playground/Interfacing/Cocoa#IOKit 获取有关如何使用 IOKit 和 icotl 命令来实现所需的示例

    我已经在 iOS 设备上成功实现了 IOKit 操作,所以只要你愿意放弃提交到 App Store,这绝对是可能的。

    【讨论】:

    • 听起来不错,但是为什么使用它的应用不能在 App Store 中出售呢?
    • 好的,我明白了——苹果不允许在 App Store 应用程序中使用 IOKit 库。
    【解决方案4】:

    答案如下:Launch specific app when external accessory attached - 并非所有配件都可以在连接时发出启动应用程序的信号。我认为普通的USB线也不能。

    关于 IOKit:您可以从 Xcode 本身添加必要的文件 - 打开 Xcode.app 包。 IOKit 框架位于 Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks 只需将缺少的文件(或制作链接)复制到

    Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/IOKit.framework

    Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/Frameworks/IOKit.framework

    也适用于所有模拟器平台

    您应该知道,由于 iOS 沙盒的安全性,并非 IOKit 的所有功能都可以在真实设备上运行(但它们可以在模拟器下运行)。 但是您可以很好地使用 IORegistry。我在 iOS 上的第一个项目是 IORegistryExplorer 的实现。 祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-06
      • 2010-11-29
      • 2023-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      相关资源
      最近更新 更多