Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7660773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:30:39+00:00 2026-05-31T13:30:39+00:00

I have a jailbroken Iphone 4 running iOS 5.0.1 and I’m trying to send

  • 0

I have a jailbroken Iphone 4 running iOS 5.0.1 and I’m trying to send serial data through the Dock Connector to my Arduino. I have successful sent data to the Arduino using Minicom but I can’t seem to get it working in an app. This is my code and the error is at the bottom.

#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 */

#import "ViewController.h"

static struct termios gOriginalTTYAttrs;

static int OpenSerialPort(void);

@implementation ViewController
@synthesize dataLabel, startData;
@synthesize timer;
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{


    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}


-(IBAction)startSerial:(id)sender{
    timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(targetMethod:) userInfo:nil repeats:YES];
             }



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_NDELAY);

        NSLog(@"%d",fileDescriptor);


        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;
    }

-(void) targetMethod: (NSTimer *) theTimer {

    //dataLabel.text = @"timer running";

             int fd;
             char somechar[8];
             fd=OpenSerialPort(); // Open tty.iap with no hardware control, 8 bit, BLOCKING and at 19200 baud
    NSLog(@"%d",fd);

    dataLabel.text = [NSString stringWithFormat:@"%d",fd];

             if(fd>-1)
             {                
               //  dataLabel.text = @"got port";

                 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
                 {
                     dataLabel.text = @"handshake accepted";

                     printf("Serial connection established!\n"); // If it is, we have established a connection to the device and can freely read/write over serial!
                     while(true) // Do this forever or untill someone presses CTRL+C
                     {
                         dataLabel.text = @"in the loop";

                         read(fd,&somechar[0],1);  // Read a character over serial!

                      dataLabel.text = [NSString stringWithFormat:@"%@",somechar[0]]; // Write the character to the Terminal!!
                     }
                 }
             }

}
  @end

But the error i’m getting is:

 2012-03-01 19:58:03.507 Iphone-Serial[2470:707] -1
    Error opening serial port /dev/tty.iap - Resource busy(16).

Should I restart my phone? or somehow close the serial port?

Thanks,
Andrew

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:30:40+00:00Added an answer on May 31, 2026 at 1:30 pm

    Your app must have root permission to access tty.iap. Simply ssh to your device(as root) and chmod 777 YourApp.app may fix the problem. Just start with simpler code, get response and extend more and more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clarify one thing. I have a jailbroken iPhone running iOS 4.0,
I have a jailbroken iPhone 4 running iOS 4.3.3 upon which I want to
I have this jailbroken iPhone 3G with iOS version 4.2.1 (the latest supported version).
I have been working on a Core Data iOS app that works perfectly through
I have had great success with running perl on my jailbroken iPhone 4: http://coredev.nl/
I have iPhone 4 with iOS 4.3.2 not jailbroken. I want to upgrade my
I have GuitarToolkit on my iPhone4S (iOS 5.01 - NOT jailbroken) It has a
I have a Core Data-based iPhone app with a pre-populated read-only database. What protection
my application is running fine in simulator...but not on real device....and i have jailbroken
I want to develop an application like biteSMS (for jailbroken iPhone). I have tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.