Question

I am writing an iPhone application that needs to send and receive data over the serial connection. I have been studying Apple's EADemo found here: EAAccessory reference

The problem is that I am finding this example too complex to take in. Is there a simpler example available for how to send and receive to and from a connected accessory over a serial connection?

I'm looking for something like sending four integer values to the accessory, and then sending them back to the iPhone using a const char buffer.

Was it helpful?

Solution

Will cost you $5 on Amazon, but the examples are easy: EAAccessory ebook

OTHER TIPS

If you use MFi Programming, I think that's very simple. First, you must setup connection, in this step you need know protocol string of external accessory. Open session with this protocol string. When open session use codes:

 _session = [[EASession alloc] initWithAccessory:accessory forProtocol:_iAPProtocolString];
    if (_session)
    {
        [[_session inputStream] setDelegate:self];
        [[_session inputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
        [[_session inputStream] open];

        [[_session outputStream] setDelegate:self];
        [[_session outputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
        [[_session outputStream] open];
    }

Then, you can write data to external accessory like this:

uint8_t buff[4];
buff[0] = 0xE0;
buff[1] = 0x10;  
buff[2] = 0x00;
buff[3] = 0x1A;

bytesWritten = [[_session outputStream] write:[_writeData bytes] maxLength:[_writeData length]];   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top