Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,544
306
Nowheresville
Ok I was reading through my Objective-C programming book and I found out that they access devices through pointers (I think that's what it said), but how is this done? I mean is it something like this:

unsigned int *device = 799; //must be a + value
*device = some_other_int

or something like that? How exactly do you access devices via pointers w/o other functions (besides those listed in <stdio.h>). I'm really curious about this and always have been. If someone can direct me to a site or explain it, that'd be great. A programming example is always a +.
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,544
306
Nowheresville
caveman_uk said:
What sort of device?

Just any sort of device. Let's take a... keyboard for example or a Parallel cable with wires and LED's attached to the end of each PIN on a male-female cable. I've seen this done with a || cable. They can send a # to turn on a specific LED. the keyboard, how would you tell it to turn on the CAPS LOCK light or that?
What about a modem? Sending light commands to that. That's just a basic roundabout, but how about for storage on a device OS X knows not what to do with, is there a way I can connect to the device (programming wise all with pointers and whatever else) tell it to format an MBR as FAT12 or HFS+ (its only 8MB) and use it as an external storage? Stuff like that, how to access it via pointers or stdio.h functions/methods, etc. I'm thinking its done more along the lines of pointers (but ASM also, but I don't want ASM so yeah). If you could point this kind of stuff out, that'd be great.
 

Palad1

macrumors 6502a
Feb 24, 2004
647
0
London, UK
You can use the I/O kit (double plus good)
http://developer.apple.com/document...//apple_ref/doc/uid/TP0000011-CH204-TPXREF101

Or you can try to do it the unix way.

PHP:
#define BUFSIZE 1024;
//...
int fdInput;
int index;
size_t sRead;
char* buffer=malloc(sizeof(char)*BUFSIZE);
memzero((void*) buffer,sizeof(char)*BUFSIZE);

// open the device and check the return code as well
if(-1 == (int)(fdInput=open("/dev/usb0",O_RDONLY)))
{
 // ouchie! see ERRNO
 return -1;
}

// read and check the return code as well
if(-1 == (int)(sRead=read(fdInput,(void*) buf,BUFSIZE)))
{
 // ouch, see ERRNO
 close(fdInput);
 return -2:
}

// let's see what we got 
for(index=0;index<(int)sRead;index++)
{
 printf("elem %d => %x\n",index,buffer[index]);
}

// when done
close(fdInput);
But the unix way gets messy real quick. I'd advise against using it if you don't plan on having a portable app.

ps: shouldn't your sig read
PHP:
[AppleComputer speed: 1.33F];
;)
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,544
306
Nowheresville
Nah, [AppleComputer speed: 1.33] knows 1.33 is a double data type. Lol, I don't think that exta F would have fit either :( I hate the 150 char limit, they should do a limit on it yes, but if you have smaller text make the limit like 300.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.