The ModMyTM Family of Sites:
ModMyMotoModMyiModMyGphone




 
 
Register or Connect with Facebook

Discuss AppStore Apps | Browse / Search Cydia | MMi Cydia Stats




  Apple Forums & iPhone Forums, Mods, Hacks, News, Themes, Downloads, and more! | ModMyi.com > 3rd Party Apps For iPhone | iPod Touch > iPhone / iPod Touch SDK | Development Discussion
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 12-12-2008, 01:24 PM
What's Jailbreak?
 
Join Date: Feb 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
How do I access the serial / UART / USB connection on the iPhone?

I haven't developed a single thing yet for the iPhone but what I need is access to the iPhones's serial/USB connection to read/write data to a device.

1) It this possible yet, using Apple's SDK, to access the USB port and communicate with any device?

2) If not, can I obtain access if I Jailbreak the iPhone?

3) Does this UART trick still work?

4) Where the heck are guides to developing applications for a Jailbroken iPhone? If Jailbroken, can I still use Apple's SDK at all?
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #2  
Old 12-12-2008, 01:49 PM
sziklassy's Avatar
Livin the iPhone Life
 
Join Date: Jan 2008
Device + Firmware: iPhone 3GS 3.1 JB
Operating System: Windows 7 Ultimate 64 and OSX Snow Leopard
Location: Iowa (ISU for Vet School!)
Posts: 2,219
Thanks: 15
Thanked 181 Times in 165 Posts

I know that Apple does not allow this under their SDK. Not sure about jailbreak, etc.
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #3  
Old 12-15-2008, 11:15 AM
What's Jailbreak?
 
Join Date: Feb 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

Here it is everyone, thanks to Collin's tutorial at: DevDot » Iphone Serial Port Tutorial, I modified it so it actually runs on a 2.2 jailbroken iPhone/iPod Touch. Here are the directions to get 3.3v UART access.

1) Jailbreak your 2.2 iPhone/iPod Touch.
2) Using Cydia, install "OpenSSH".
3) Using Cydia, install the "iPhone 2.0 Toolchain"
4) Ensure SSH is running
5) Using WinSCP, extract the serial folder found here to anywhere on your phone (ie "/" root).
4) Using Putty or whatever console app you chose, run:
Code:
# ./(install directory)/serial (ie "./serial/serial")
5) That will establish a 9600 N-8-1 serial connection over USB.

UPDATE: You do not need to create the "*" handshake if your using firmware after 1.1, nor do you need to do the strobe hack mentioned in Collin's tutorial.

If you make changes to it, compiling is as simple as:
Code:
# cd /(install directory)/ (ie "cd /serial/")
# make


If my link goes down, here is the serial.c code with minimal comments:

Code:
//////////////////////////////////////////////////////////////////////////
//  Iphone Serial I/O demo.  see DevDot.wikispaces.com for more info
//  ---------------------------------------------------------------------------------------
//  By Collin Meyer (TheRain)
//  12-09-2007 revision 1
//  Feel free to reuse this code.
//
// Modified by Chris K.
//////////////////////////////////////////////////////////////////////////

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

    fileDescriptor = open("/dev/tty.iap", O_RDWR | O_NOCTTY | O_NONBLOCK);
    if (fileDescriptor != -1) {
		if (ioctl(fileDescriptor, TIOCEXCL) != -1) {
			if (fcntl(fileDescriptor, F_SETFL, 0) != -1) {
				if (tcgetattr(fileDescriptor, &gOriginalTTYAttrs) != -1) {
					options = gOriginalTTYAttrs;

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

					return fileDescriptor;
				} else {
					printf("Error getting tty attributes %s - %s(%d).n", "/dev/tty.iap", strerror(errno), errno);
					if (fileDescriptor != -1) {
						close(fileDescriptor);
					}
					return -1;
				}
			} else {
				printf("Error clearing O_NONBLOCK %s - %s(%d).n", "/dev/tty.iap", strerror(errno), errno);
				if (fileDescriptor != -1) {
					close(fileDescriptor);
				}
				return -1;
			}
		} else {
			printf("Error setting TIOCEXCL on %s - %s(%d).n", "/dev/tty.iap", strerror(errno), errno);
			if (fileDescriptor != -1) {
				close(fileDescriptor);
			}
			return -1;
		}
	} else {
        printf("Error opening serial port %s - %s(%d).n", "/dev/tty.iap", strerror(errno), errno);
		if (fileDescriptor != -1) {
			close(fileDescriptor);
		}
		return -1;
    }

    return fileDescriptor;
} 

int main(int args, char *argv[]) {
	int fd;
	char somechar[8];
	fd = OpenSerialPort(); 
	if(fd >- 1) {
		write(fd,"*",1); 
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		// 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); 
		if(somechar[0]=='*') { 
			printf("Serial connection established!  n");
			while(1) {
				read(fd,&somechar[0],1);
				putchar(somechar[0]);
			}
		}
	}
	return 0;
}
...and here is the make file:

Code:
CC=gcc
TARGET=serial
LD=$(CC)
LDFLAGS = -framework CoreFoundation 
          -framework Foundation 
          -framework UIKit 
          -framework CoreGraphics 
          -lobjc

all:	$(TARGET)

$(TARGET):	$(TARGET).o
	@$(LD) $(LDFLAGS) -o $@ $^
		@ldid -S $(TARGET)

clean:
		@rm -f *.o $(TARGET)

Last edited by cmk1523; 12-17-2008 at 04:17 PM..
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #4  
Old 12-17-2008, 07:33 AM
Mes's Avatar
Mes Mes is offline
My iPhone is a Part of Me
 
Join Date: May 2008
Device + Firmware: 3G-16G 3.0; 2G-8G 2.2.1 T-Mobile
Operating System: XPSP3, VistaHPSP1, OSX10.4.10
Location: Sunny California :)
Posts: 825
Thanks: 29
Thanked 91 Times in 81 Posts

Thanks for the info cmk1523. I don't need this now, but who knows.
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #5  
Old 12-17-2008, 04:15 PM
What's Jailbreak?
 
Join Date: Feb 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

Here's some even more barebones code to set up a 9600 N-8-1 UART connection...

Code:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>

static int OpenSerialPort(void);

static int OpenSerialPort() {
    int fileDescriptor = -1;
    struct termios  options;
    printf("Initializing Serial Port... ");
    fileDescriptor = open("/dev/tty.iap", O_RDWR | O_NOCTTY | O_NONBLOCK);
    if (fileDescriptor != -1) {
       if (fcntl(fileDescriptor, F_SETFL, 0) != -1) {
	   if (tcgetattr(fileDescriptor, &gOriginalTTYAttrs) != -1) {
	      options = gOriginalTTYAttrs;
	      printf("[DONE]rn");	
	      return fileDescriptor;
	   } else {
		printf("[FAIL]rn");
		printf("Error getting tty attributes %s - %s(%d).n", "/dev/tty.iap", strerror(errno), errno);
		if (fileDescriptor != -1) {
		   close(fileDescriptor);
		}
		return -1;
	   }
	} else {
	   printf("[FAIL]rn");
	   printf("Error clearing O_NONBLOCK %s - %s(%d).n", "/dev/tty.iap", strerror(errno), errno);
	   if (fileDescriptor != -1) {
	      close(fileDescriptor);
	   }
	   return -1;
	}
     } else {
	printf("[FAIL]rn");
	printf("Error setting TIOCEXCL on %s - %s(%d).n", "/dev/tty.iap", strerror(errno), errno);
	if (fileDescriptor != -1) {
	   close(fileDescriptor);
	}
	return -1;
   }
} 

int main (int argc, char * const argv[]) {
  int fd;	
  char c[1];

  if((fd = OpenSerialPort()) >= 1) {
     while(1) {
	if (read(fd, (void *)c, 1) == -1) {
	   printf("Read Error.rn");
	}
			
	if (write(fd, (void *)c, 1) == -1) {
           printf("Write Error.rn");
	}
     }
   }

   return 0;
}
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #6  
Old 12-17-2008, 05:42 PM
Chase817's Avatar
Livin the iPhone Life
 
Join Date: Mar 2008
Device + Firmware: White iPhone 3G
Operating System: MacBook - Leopard & Vista
Location: Orange County, CA
Posts: 1,403
Thanks: 102
Thanked 74 Times in 56 Posts
Send a message via AIM to Chase817

nice work cmk, sounds very complicated. lol
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #7  
Old 12-22-2008, 06:05 PM
What's Jailbreak?
 
Join Date: Dec 2008
Device + Firmware: iPhone 3G 2.2
Operating System: Mac OS X Leopard
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

Are you trying to communicate with a micro controller? If so have you had any success?
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #8  
Old 12-23-2008, 04:36 PM
What's Jailbreak?
 
Join Date: Feb 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

Yes I have been successful. The TX/RX lines work just like any other UART so a micro controller would work.
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #9  
Old 12-23-2008, 05:00 PM
What's Jailbreak?
 
Join Date: Dec 2008
Device + Firmware: iPhone 3G 2.2
Operating System: Mac OS X Leopard
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

Awesome. What sort of project are you working on? I've started building a relay and sensor control board using a PIC because its the only one I know how to use. The only computer side programs I've used to communicate with a micro controller over serial are MATLAB and Hyper Terminal. I'm aware this is a newb question but what are you using to build the iPhone software interface side?
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #10  
Old 10-01-2009, 11:39 PM
What's Jailbreak?
 
Join Date: Oct 2009
Device + Firmware: iPhone Touch 2nd 3.0
Operating System: Leopard 10.5.7
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Hello cmk1523.

Thanks a lot! Do you have any update for iPhone/iPod 3.0?
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
Reply

  Apple Forums & iPhone Forums, Mods, Hacks, News, Themes, Downloads, and more! | ModMyi.com > 3rd Party Apps For iPhone | iPod Touch > iPhone / iPod Touch SDK | Development Discussion

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Go to Top
ModMyI

All times are GMT -6. The time now is 11:59 AM. Powered by vBulletin® Version 3.8.4
If you need Dedicated Server Hosting, you should check out SingleHop. | Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0 Copyright © 2007-09 by ModMy, LLC. All rights reserved.

iPhone News / iPhone Forums / Apple News / Apple Forums / RSS / Contact Us / / Privacy Statement / Top