テストに使ったプログラムの抜粋です
//---------------------------------------------------------------------------
int __fastcall TForm2::FifoOpen()
{
FT_STATUS ftStatus;
DWORD InTransferSize =65535;
DWORD OutTransferSize =4096;
DWORD nDeviceCount;
DWORD numDevs;
DWORD Flags;
DWORD VID_PID,VID,PID;
DWORD Type;
DWORD LocId;
char SerialNumber[16];
char Description[64];
String wk;
char *serial;
int ret;
ret = -1;
for(;;){
ftStatus = FT_CreateDeviceInfoList(&nDeviceCount);
if (ftStatus == FT_OK)
{
AddMemo("FT_CreateDeviceInfoList OK\n");
}
AddMemo("-------information----------");
for( int i = 0; i < nDeviceCount; i++ ){
// get information for device 0
ftStatus = FT_GetDeviceInfoDetail(i, &Flags, &Type,
&VID_PID, &LocId, SerialNumber, Description, &handle);
if (ftStatus == FT_OK)
{
AddMemo("No: "+ IntToStr(i));
wk= SerialNumber; AddMemo(" SerialNumber: "+wk);
wk= Description; AddMemo(" Description: "+wk);
VID = VID_PID >>16 & 0xffff;
PID = VID_PID & 0xffff;
wk = IntToHex(StrToInt(VID),4)+"_"+
IntToHex(StrToInt(PID),4) ;
AddMemo(" VID_PID: "+wk);
}
}
AddMemo("-----------------");
//////////////////////////
serial = ftdi_serial.c_str();
ftStatus = FT_ListDevices(&nDeviceCount, NULL, FT_LIST_NUMBER_ONLY);
ftStatus = FT_OpenEx(serial, FT_OPEN_BY_SERIAL_NUMBER, &handle);
if(ftStatus != FT_OK){
AddMemo("FT_OPEN_BY_SERIAL_NUMBER : NG");
break;
}else{
AddMemo("FT_OPEN_BY_SERIAL_NUMBER : OK");
}
if( RadioButton1->Checked ){
ftStatus = FT_SetBitMode(handle, 0, 0x40);
if(ftStatus != FT_OK){
AddMemo("FT_SetBitMode(Sync-FIFO Mode) : NG");
break;
}else{
AddMemo("FT_SetBitMode(Sync-FIFO Mode) : OK");
}
}else{
ftStatus = FT_SetBitMode(handle, 0, 0x00);
if(ftStatus != FT_OK){
AddMemo("FT_SetBitMode(Async-FIFO Mode) : NG");
break;
}else{
AddMemo("FT_SetBitMode(Async-FIFO Mode) : OK");
}
}
ftStatus = FT_SetLatencyTimer(handle, 2);
if(ftStatus != FT_OK){
AddMemo("FT_SetLatencyTimer : NG");
break;
}else{
AddMemo("FT_SetLatencyTimer : OK");
}
ftStatus = FT_SetUSBParameters(handle, InTransferSize, OutTransferSize);
if(ftStatus != FT_OK){
AddMemo("FT_SetUSBParameters : NG");
break;
}else{
AddMemo("FT_SetUSBParameterse : OK");
}
ftStatus = FT_SetFlowControl( handle, FT_FLOW_RTS_CTS, 0x10,0x13);
if(ftStatus != FT_OK){
AddMemo("FT_SetFlowControl : NG");
break;
}else{
AddMemo("FT_SetFlowControl : OK");
}
// normal reterun
ret = 0;
break;
}
if( ret == 0 ){
AddMemo("FifoOpen() : OK");
}else{
AddMemo("FifoOpen() : NG");
}
return ret;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button_FIFOCloseClick(TObject *Sender)
{
rcv_thred_stop(); // stop the thred
FifoClose();
Button_FIFOExam->Enabled = False;
Button_FIFOClose->Enabled = False;
Button_FIFOOpen->Enabled = True;
ComboBox_kaich->Enabled = True;
RadioButton1->Enabled = True;
RadioButton2->Enabled = True;
}
//---------------------------------------------------------------------------
int __fastcall TForm2::FifoClose()
{
FT_STATUS ftStatus;
ftStatus = FT_SetBitMode(handle, 0, 0);
if(ftStatus == FT_OK){
AddMemo("Mode Reset : OK");
}else{
AddMemo("Mode Reset : NG");
}
ftStatus = FT_Close(handle);
if(ftStatus == FT_OK){
AddMemo("FifoClose() : OK");
return 1;
}else{
AddMemo("FifoClose() : NG");
return 0;
}
}
int __fastcall TForm2::Write_1000( char *p, int len, int kaisuu )
{
FT_STATUS ftStatus;
DWORD writtenBytes;
int ret;
ret = 0;
ftStatus = FT_Write(handle, p, len, &writtenBytes);
if(ftStatus != FT_OK){
ret = -1;
}
return ret;
}
// send test
int __fastcall TForm2::FifoExam_snd()
{
String str;
char *TxData;
String DiffTime;
int len;
String str1;
str = LabeledEdit_stext->Text;
len = str.Length();
TxData = new char[len+2+1]; //*1
for(int i=0; i < len; i++){
TxData[i] = str.c_str()[i];
}
if( CheckBox_addcr->Checked ){
TxData[len++] = 0x0d;
str = str + "[cr]";
}
if( CheckBox_addlf->Checked ){
TxData[len++] = 0x0a;
str = str + "[lf]";
}
TxData[len] = '\0';
for(;;){
str1 ="SEND:"+str ;
if( Write_1000(TxData, len, 1)!= FT_OK){
AddMemo("FT_Write ERROR");
break;
}else{
AddMemo(str1);
}
// normal return
break;
}
delete [] TxData; //*1
return 0;
}