UTL-015サンプルアプリケーションの プログラム一部抜粋です

const BYTE PORT_SCLK = 0x01;
const BYTE PORT_DO = 0x02;
const BYTE PORT_DI = 0x04;
const BYTE PORT_ALERT = 0x20;   //ADBUS5
const BYTE PORT_THERM = 0x80;   //ADBUS7
const BYTE MSB_FALLING_EDGE_CLOCK_BYTE_OUT = 0x11;
const BYTE MSB_RISING_EDGE_CLOCK_BIT_IN = 0x22;
const BYTE MSB_RISING_EDGE_CLOCK_BYTE_IN = 0x20;
const BYTE SET_DATA_BITS_LOW_BYTE = 0x80;
const BYTE READ_DATA_BITS_LOW_BYTE = 0x81;
const bool TEMP_MODE_LOCAL = false;
const bool TEMP_MODE_REMOTE = true;

//---------------------------------------------------------------------------
int __fastcall TForm2::FTDI_DeviceDetect(void)
{
    FT_DEVICE_LIST_INFO_NODE *devInfo;
    FT_STATUS ftStatus;
    DWORD numDevs;
    String str;
    int ret;

    ret = -1;

    ComboBox_ComPort->Clear();
    ComboBox_ComPort->Text = "Select FT2232H Port...";

    // create the device information list
    ftStatus = FT_CreateDeviceInfoList(&numDevs);

    if(ftStatus == FT_OK){
        AddReport(str.sprintf("Number of channels: %d",numDevs));

        if(numDevs > 0){
            devInfo = new FT_DEVICE_LIST_INFO_NODE[numDevs];
            ftStatus = FT_GetDeviceInfoList(devInfo,&numDevs);

            if (ftStatus == FT_OK){

                ret = 0;

                for (int i=0; i<(int)numDevs; i++){
                    AddReport(str.sprintf("No.%d:",i));
                    AddReport(str.sprintf("  Flags: 0x%x",devInfo[i].Flags));
                    AddReport(str.sprintf("  Type: 0x%x",devInfo[i].Type));
                    AddReport(str.sprintf("  ID: 0x%x",devInfo[i].ID));
                    AddReport(str.sprintf("  LocId: 0x%x",devInfo[i].LocId));
                    AddReport(str.sprintf("  SerialNumber: %s",devInfo[i].SerialNumber));
                    AddReport(str.sprintf("  Description: %s",devInfo[i].Description));
                    AddReport(str.sprintf("  Handle: 0x%x",devInfo[i].ftHandle));

                    ComboBox_ComPort->Items->Add(devInfo[i].Description);
                }
            }

            delete []devInfo;
        }
    }else{
        ComboBox_ComPort->Items->Add("No Device detected");
    }

    return ret;
}
//---------------------------------------------------------------------------
int __fastcall TForm2::FTDI_PortOpen(void)
{
    String portName;
    FT_STATUS ftStatus;
    int ret;

    ret = -1;

    portName = ComboBox_ComPort->Text;
    ftStatus = FT_OpenEx(portName.c_str(), FT_OPEN_BY_DESCRIPTION, &ftHandle);

    if(ftStatus == FT_OK)
    {
        for(ftStatus = (!FT_OK);;){
            if(FT_ResetDevice(ftHandle) != FT_OK ) break;
            Sleep(100);     //Wair fot reset process
            if(FT_Purge(ftHandle, FT_PURGE_RX | FT_PURGE_TX) != FT_OK) break;
            if(FT_SetUSBParameters(ftHandle, 65536, 65535) != FT_OK) break;
            if(FT_SetChars(ftHandle, FALSE, 0, FALSE, 0) != FT_OK) break;
            if(FT_SetTimeouts(ftHandle, 0, 5000) != FT_OK) break;
            if(FT_SetLatencyTimer(ftHandle, 2) != FT_OK) break;
            if(FT_SetFlowControl(ftHandle, FT_FLOW_NONE, 0, 0) != FT_OK) break;
            //Mode Reset
            if( FT_SetBitMode(ftHandle, (UCHAR)0x00, (UCHAR)0x00) != FT_OK ) break;
            Sleep(100);     //Wair fot reset process
            if( FT_SetBitMode(ftHandle, (UCHAR)0x00, (UCHAR)0x02) != FT_OK ) break;

            //All function returned FT_OK
            ftStatus = FT_OK;
            break;
        }

        if(ftStatus != FT_OK){
            AddReport("PORT OPEN ERROR, FT_STATUS ERROR");
            ret = -1;
        }else{
            AddReport("PORT OPEN OK");
            ret = 0;
        }
    }

    return ret;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FTDI_MPSSESetup(void)
{
    DWORD dwByteWritten;
    BYTE outBuffer[] = {
        0x85,               //Disconnect TDI to TDO LoopBack
        0x97,               //Turn off Adaptive clocking
        0x8C,               //Enable 3 Phase Data Clocking
        0x86, 0x13, 0x00,   //Set TCK Divisor
    };

    FT_Write(ftHandle, (BYTE*)outBuffer, sizeof(outBuffer), &dwByteWritten);

    return;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FTDI_I2CStart(void)
{
    DWORD dwByteWritten;
    BYTE outBuffer[] = {
    //Keep CLK=H, DO=H
        SET_DATA_BITS_LOW_BYTE, PORT_DO|PORT_SCLK, 0x03,
    //Make DO down edge while CLK=H
        SET_DATA_BITS_LOW_BYTE, PORT_SCLK, 0x03,
    //Set to Initial condition
        SET_DATA_BITS_LOW_BYTE, 0x00, 0x03,
    };

    FT_Write(ftHandle, (BYTE*)outBuffer, sizeof(outBuffer), &dwByteWritten);

    return;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FTDI_I2CStop(void)
{
    DWORD dwByteWritten;
    BYTE outBuffer[] = {
    //Keep CLK=H, DO=H
        SET_DATA_BITS_LOW_BYTE, PORT_DO|PORT_SCLK, 0x03,
    //Make DO down edge while CLK=H
        SET_DATA_BITS_LOW_BYTE, PORT_SCLK, 0x03,
    };

    FT_Write(ftHandle, outBuffer, sizeof(outBuffer), &dwByteWritten);

    return;
}
//---------------------------------------------------------------------------
BYTE __fastcall TForm2::FTDI_SendByteAndCheckACK(BYTE data)
{
    BYTE ret;
    DWORD dwByteWritten;
    DWORD dwByteRead;

    BYTE outBuffer[] = {
    //Data
        MSB_FALLING_EDGE_CLOCK_BYTE_OUT, 0x00, 0x00, data,
    //Get Ack
        SET_DATA_BITS_LOW_BYTE, 0x00, 0x01, //SCLK:out, DO:in, DI:in
        MSB_RISING_EDGE_CLOCK_BIT_IN, 0x00,
        0x87,                               //Send Immediate
        SET_DATA_BITS_LOW_BYTE, 0x00, 0x03, //SCLK:out, DO:out, DI:in
    };

    FT_Write(ftHandle, outBuffer, sizeof(outBuffer), &dwByteWritten);
    FT_Read(ftHandle, &ret, 1, &dwByteRead);

    ret &= 0x01;

    return ret;
}
//---------------------------------------------------------------------------
BYTE __fastcall TForm2::FTDI_ReadByteAndSendACK(void)
{
    DWORD dwByteWritten, dwByteRead;
    BYTE ret;
    BYTE outBuffer[] = {
        //InDirection
        SET_DATA_BITS_LOW_BYTE, 0x00, 0x01,
        MSB_RISING_EDGE_CLOCK_BYTE_IN, 0x00, 0x00,
        //Send Ack
        SET_DATA_BITS_LOW_BYTE, 0x00, 0x03,
        SET_DATA_BITS_LOW_BYTE, PORT_SCLK, 0x03,
        //Out Direction
        SET_DATA_BITS_LOW_BYTE, 0x00, 0x03,
    };

    FT_Write(ftHandle, (BYTE*)&outBuffer, sizeof(outBuffer), &dwByteWritten);
    FT_Read(ftHandle, &ret, 1, &dwByteRead);

    return ret;
}
//---------------------------------------------------------------------------
BYTE __fastcall TForm2::FTDI_GPIOCheck(void)
{
    DWORD dwByteWritten, dwByteRead;
    BYTE ret;
    BYTE outBuffer[] = {
        //Set Direction
            SET_DATA_BITS_LOW_BYTE, 0x00, 0x01,   //SCLK:out, DO:in, DI:in
        //Get 1Byte from DI
            READ_DATA_BITS_LOW_BYTE,
            0x87,   //Send Immediate
    };

    FT_Write(ftHandle, outBuffer, sizeof(outBuffer), &dwByteWritten);
    FT_Read(ftHandle, &ret, 1, &dwByteRead);

    return ret;
}