[Proramming]/C/VC++2009. 10. 11. 16:05

VC++ .Net을 이용하여 하드웨어 제어 - FT245 USB FIFO 제어

VC++ .Net을 이용하여 하드웨어 제어 - FT245 USB FIFO 제어




#define FT_PREFIX [DllImport("FTD2XX.dll")]

namespace FT245_Test
{
 using namespace System::Runtime::InteropServices;

 FT_PREFIX FT_STATUS FT_Open(int deviceNumber, FT_HANDLE * pHandle);
 FT_PREFIX FT_STATUS FT_OpenEx(PVOID pArg1, DWORD Flags, FT_HANDLE *pHandle);
 FT_PREFIX FT_STATUS FT_Read(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesReturned);
 FT_PREFIX FT_STATUS FT_Write(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesWritten);
 FT_PREFIX FT_STATUS  FT_SetBitMode(FT_HANDLE ftHandle, UCHAR ucMask, UCHAR ucEnable);
 FT_PREFIX FT_STATUS FT_SetBaudRate(FT_HANDLE ftHandle, ULONG BaudRate);
 FT_PREFIX FT_STATUS FT_ListDevices(PVOID pArg1, PVOID pArg2, DWORD Flags);
 FT_PREFIX FT_STATUS FT_ListDevices(UInt32 pvArg1, void * pvArg2, UInt32 dwFlags);
 :
}

초기화 함수
 private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    FT_STATUS ftStatus = FT_OK;
    ftStatus = FT_Open(0, &m_ftHandle);

    if(ftStatus == FT_OK)
    {
     label1->Text = "Success";
     button1->Image = pictureConnected->Image;

     ftStatus = FT_SetBaudRate(m_ftHandle, 115200);
     ftStatus = FT_SetBitMode(m_ftHandle, 0xFF, 0x01);
    }
    else
    {
     label1->Text = "Fail";
     button1->Image = pictureDisConnected->Image;
    }
}

Led On/Off 처리 함수
 private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
    unsigned char buffer[1];
    DWORD written_size;

     if(button2->Text == "Led On")
     {
      button2->Text = "Led Off";
      button2->Image = picLedOn->Image;

      buffer[0] = 0x00;
      FT_Write(m_ftHandle, buffer, 1, &written_size);
     }
     else
     {
      button2->Text = "Led On";
      button2->Image = picLedOff->Image;
     }
    }

Posted by nexp

댓글을 달아 주세요