Comment d'un programme objective C appeler une procédure en C
Bonjour
Comment d'un programme objective C appeler une procédure en C
Exemple
Je souhaite manager le port serie sur mon iphone ( j'ai SDK 3.1 et Xcode 3.1)
et je suis sur Leopard 10.5
J'ai trouvé sur internet SerialManager, une classe de Cocoa
En voici un exemple :
Extrait de SerialManager.m
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
- (int)findRS232Ports
{
return [ self findPorts:CFSTR( kIOSerialBSDRS232Type ) ] ;
}
- (NSString*)streamAtIndex:(int)n
{
if ( n < 0 || n >= numberOfPorts ) return nil ;
return stream[n] ;
}
- (NSString*)pathAtIndex:(int)n
{
if ( n < 0 || n >= numberOfPorts ) return nil ;
return path[n] ;
}
// common function to open port and set up serial port parameters
static int openPort( NSString *path, int speed, int bits, int parity, int stops, int openFlags, Boolean input )
{
int fd, cflag ;
struct termios termattr ;
fd = open( [ path cStringUsingEncoding:NSASCIIStringEncoding], openFlags ) ;
if ( fd < 0 ) return -1 ;
// build other flags
cflag = 0 ;
cflag |= ( bits == 7 ) ? CS7 : CS8 ; // bits
if ( parity != 0 ) {
cflag |= PARENB ; // parity
if ( parity == 1 ) cflag |= PARODD ;
}
if ( stops > 1 ) cflag |= CSTOPB ;
// merge flags into termios attributes
tcgetattr( fd, &termattr ) ;
termattr.c_cflag &= ~( CSIZE | PARENB | PARODD | CSTOPB ) ; // clear all bits and merge in our selection
termattr.c_cflag |= cflag ;
// set speed, split speed not support on Mac OS X?
cfsetispeed( &termattr, speed ) ;
cfsetospeed( &termattr, speed ) ;
// set termios
tcsetattr( fd, TCSANOW, &termattr ) ;
return fd ;
} |
j'ai créé une appli Gestion des port série
Dans le fichier Gestion_des_ports_s_rieAppDelegate.m
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#import "Gestion_des_ports_s_rieAppDelegate.h"
#import "SerialManager.h"
@implementation Gestion_des_ports_s_rieAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[ static: openPort("Com1",9600, 8, 0, 1, 0, 0)];
[window makeKeyAndVisible];
}
- (void)dealloc {
[window release];
[super dealloc];
} |
Forcément j'essaye d'ouvrir le port mais comme je débute en objective C
je sais pas vraiment comment appeler cette fonction depuis mon fichier
Gestion_des_ports_s_rieAppDelegate.m
La ligne
[ static: openPort("Com1",9600, 8, 0, 1, 0, 0)];
me génére des erreurs
Et puis cela doit pas non plus s'appeler Com1
Donc je suis un peu perdu