Pointers, Devices -- need some q?'s answered.

Discussion in 'Mac Programming' started by slooksterPSV, Jul 3, 2006.

  1. macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
    #1
    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 +.
     
  2. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
  3. thread starter macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
    #3
    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.
     
  4. macrumors 6502a

    Palad1

    Joined:
    Feb 24, 2004
    Location:
    London, UK
    #4
    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;
    charbuffer=malloc(sizeof(char)*BUFSIZE);
    memzero((void*) buffer,sizeof(char)*BUFSIZE);

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

    // read and check the return code as well
    if(-== (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 speed1.33F];
    ;)
     
  5. thread starter macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
    #5
    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.
     

Share This Page