View Full Version : Pointers, Devices -- need some q?'s answered.
Jul 3, 2006, 03:11 AM
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 +.
Jul 3, 2006, 03:56 AM
What sort of device?
Jul 3, 2006, 04:20 AM
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.
Jul 3, 2006, 11:09 AM
You can use the I/O kit (double plus good)
Or you can try to do it the unix way.
#define BUFSIZE 1024;
// open the device and check the return code as well
if(-1 == (int)(fdInput=open("/dev/usb0",O_RDONLY)))
// ouchie! see ERRNO
// read and check the return code as well
if(-1 == (int)(sRead=read(fdInput,(void*) buf,BUFSIZE)))
// ouch, see ERRNO
// let's see what we got
printf("elem %d => %x\n",index,buffer[index]);
// when done
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
[AppleComputer speed: 1.33F];
Jul 3, 2006, 03:49 PM
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.