0

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.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Sabobin
  • 4,256
  • 4
  • 27
  • 33
  • 1
    Are you in the Made for iPod program, or do you have a specific MFi-compatible device that you will be communicating with? Make sure of that first before getting too far into the EAAccessory stuff. – Brad Larson Jan 06 '11 at 15:49
  • 1
    Yes I am in the MFi program, and developing a custom accessory, and in-house serial communication protocol. – Sabobin Jan 06 '11 at 16:37

2 Answers2

1

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

skantner
  • 480
  • 4
  • 19
0

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]];   
G-Power
  • 149
  • 7