#include <stdio>
#include <stdlib>
#include <string>
#include "ftd2xx.h"
int main (int argc, char * const argv[])
{
FT_STATUS ftStatus;
FT_HANDLE ftHandle;
char deviceid[] = "A4004t6d";
ftStatus = FT_OpenEx(deviceid, FT_OPEN_BY_SERIAL_NUMBER, &ftHandle);
if( ftStatus != FT_OK ){
printf("Error FT_OpenEx(%d)\n", ftStatus);
return -1;
}
printf("Opened device %s\n", deviceid);
ftStatus = FT_SetBaudRate(ftHandle, 1000000);
if( ftStatus != FT_OK ){
printf("Error FT_SetBaudRate(%d)\n", ftStatus);
}
ftStatus = FT_SetDataCharacteristics(ftHandle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE);
if( ftStatus != FT_OK ){
printf("Error FT_SetDataCharacteristics(%d)\n", ftStatus);
}
ftStatus = FT_SetFlowControl(ftHandle, FT_FLOW_NONE, 0, 0);
if( ftStatus != FT_OK ){
printf("Error FT_SetFlowControl(%d)\n", ftStatus);
}
// (FT_HANDLE ftHandle, DWORD dwReadTimeout, DWORD dwWriteTimeout)
ftStatus = FT_SetTimeouts(ftHandle,1000,1000);
if( ftStatus != FT_OK ){
printf("Error FT_SetTimeouts(%d)\n", ftStatus);
}
DWORD buff[] = { 0xff, 0xff, 0x9, 0x2, 0x1, 0xf3 };
DWORD written;
DWORD len = 6;
ftStatus = FT_Write(ftHandle, buff, len, &written);
if( ftStatus != FT_OK ){
printf("Error FT_Write(%d)\n", ftStatus);
}
printf("Bytes written: %i\n", written);
DWORD EventDWord;
DWORD TxBytes, RxBytes;
DWORD BytesReceived;
char RxBuffer[256];
FT_GetStatus(ftHandle,&RxBytes,&TxBytes,&EventDWord);
printf("RxBytes: %i\n", RxBytes);
printf("TxBytes: %i\n", TxBytes);
if (RxBytes > 0) {
ftStatus = FT_Read(ftHandle,RxBuffer,RxBytes,&BytesReceived);
if (ftStatus == FT_OK) {
for(int i=0; i<RxBytes; i++){
printf("0x%x ", RxBuffer[i]);
}
printf("\n");
}
else {
printf("Error FT_Read(%d)\n", ftStatus);
}
}
FT_Close(ftHandle);
return 0;
}
Opened device A4004t6d
Bytes written: 6
RxBytes: 0
TxBytes: 0