Help Sending Commands to a USB Device(Prolific) with modified Deva Example

Discussion in 'Mac Programming' started by smokyonion, Dec 27, 2009.

  1. smokyonion macrumors newbie

    Joined:
    Dec 13, 2009
    #1
    Hi, all
    Recently I bought my first iMac and start to learn programming on Mac
    my first project is a small USB communication program.
    I have a USB device which has a red light on it,
    and I also have the command list of this device.

    The capabilities of the device allow me to turn on/off the light.

    this is an examples of the commands listed in the document:
    - Turn light on
    Initial code: 0x00
    Command: 0xFF
    Data: 0xCC
    Check Sum: 0xDD
    Ending Code: 0xEE

    - Turn light off
    Initial code: 0x00
    Command: 0xFF
    Data: 0xAA
    Check Sum: 0xBB
    Ending Code: 0xEE

    I changed the VID & PID in the "Deva Example" and it works in the first initial sequence but when the program jump into
    "SetIoPortsConfig()" there comes an error:

    ---Debugger console output start---
    Running...
    Found device VID 0x067B (1659), PID 0x2303 (8963), release 768
    Configuration value is 1
    3 endpoints found
    Endpoint 1: Interrupt In 1, max packet 10, interval 1
    Endpoint 2: Bulk Out 2, max packet 64, interval 0
    Endpoint 3: Bulk In 3, max packet 64, interval 0
    Now we actually get to do something with this device, wow!!!!
    Doing ReadIoPorts with portbits ffffffff
    unable to do ReadIoPorts (0xE000404F) USB error 79(0x4F)
    Debugger stopped.
    Program exited with status value:0.
    ---Debugger console output end---

    I have traced the code of "Deva Example" to :
    void finallyDoSomethingWithThisDevice(IOUSBInterfaceInterface245 **intf)
    {
    .....
    #else
    IOReturn err;
    UInt32 portBits, IOBits, IOBits1;
    UInt32 light, light2;
    Boolean dirn;
    // First set all ports to input
    err = DevaSetIoPortsConfig(intf, 0x000FFFFF); // and then I step into this function
    }

    // encounter an error in this function
    IOReturn DevaSetIoPortsConfig(IOUSBInterfaceInterface245 **intf, UInt32 portBits)
    {
    IOUSBDevRequest req;
    IOReturn err;

    req.bmRequestType = USBmakebmRequestType(kUSBOut, kUSBVendor, kUSBDevice);
    req.bRequest = 0xF0; // SetIoPortsConfig
    req.wValue = 0; // unused
    req.wIndex = 0; // unused
    req.wLength = 4; // 32bit int
    req.pData = &portBits;

    portBits = HostToUSBLong(portBits);
    // 000CBBAA <-port mappings
    // 1 is Input (looks like I, 0 is output, looks like O)
    #if NARRATEIO
    printf("Doing SetIoPortsConfig with portbits %08x\n", USBToHostLong(portBits));
    #endif

    err = (*intf)->ControlRequest(intf, 0, &req);
    if (kIOReturnSuccess == err)
    {
    if(req.wLenDone != 4)
    {
    err = kIOReturnUnderrun;
    }
    }
    return(err);
    }

    ---my question---
    How do I replace and insert the command provided in the document, I am really sorry I have tried Google, official website of Prolific Technologies
    but I have no clue about the right format, any replies will be highly appreciated. Thank you so much!

    --my USB device specification--

    USB-Serial Controller:
    Product ID: 0x2303
    Vendor ID: 0x067b (Prolific Technology, Inc.)
    Version: 3.00
    Speed: Up to 12 Mb/sec
    Manufacturer: Prolific Technology Inc.
    Location ID: 0x06400000
    Current Available (mA): 500
    Current Required (mA): 100

    deviceName: USB-Serial Controller
    Location ID: 0x6400000
    Device Class: 0x0
    Device Speed: 0x1
    Device Vendor ID: 0x67b
    Device Product ID: 0x2303
    Device Address: 0x3
    Device Configuration: 0x1

    --Detail Device and Interface Inforamtion in IORegistryExplore--
    Device
    [​IMG]
    Interface 1
    [​IMG]
    Interface 2
    [​IMG]
    --Apple Developer Reference Example--
    Deva Example
    USB Private Data Sample
     
  2. Xantos macrumors newbie

    Joined:
    May 27, 2010
    #2
    Hi smokyonion,

    I'm trying to do the same here (probably different device but same vendor en productid).

    Where you able to solve your problem and are you willing to share the solution with me?
     

Share This Page