int main(int argc, char *argv[]) { pthread_t thread_id; int i; FT_STATUS ftStatus; exit_reader = 0; ftStatus = FT_Open(0, &ftHandle); pthread_create(&thread_id, NULL, &read_watch, NULL); for(i = 0; i < 1000; i++) { char buf[100]; int index = 0; ftStatus = FT_ListDevices((PVOID)index, (void*)buf, FT_LIST_BY_INDEX | FT_OPEN_BY_SERIAL_NUMBER); if(ftStatus == FT_OK) { // printf("FT_LIST_BY_INDEX = %s\n"); } else { printf("FT_LIST_BY_INDEX failed(%d)\n", ftStatus); } } exit_reader = 1; /* wait for it to exit */ pthread_join(thread_id, NULL); }
int main(void) { FT_HANDLE FT_handle; // handle to FT 232 chip FT_STATUS FT_status; // status of the FT 232 chip UCHAR Mask; // for selecting which pins are input/output UCHAR Mode; // Selects the mode of operation for the chip UCHAR UpperNibble_Direction; //whether port is input/output UCHAR LowerNibble_Data; // 4 bit data to be sent UpperNibble_Direction = 0xF0; // setting the direction nibble LowerNibble_Data = 0x0F; // setting the data nibble Mask = UpperNibble_Direction | LowerNibble_Data;//OR'ing FT_status = FT_Open(0,&FT_handle); // Open a connection to FT232RL Mode = 0x20; // Select Chip mode as CBUS Bit Bang FT_status = FT_SetBitMode(FT_handle,Mask,Mode); // Opening Bit Bang Mode getchar(); Mode = 0x00; // Reset the chip Mask = 0x00; // FT_status = FT_SetBitMode(FT_handle,Mask,Mode); //Bring back the chip to default mode FT_Close(FT_handle);//Close the connection }
FT_STATUS ftdimut_setup() { FT_STATUS ftStatus; unsigned char timer; ftStatus = FT_SetVIDPID(USB_VID, USB_PID); if(ftStatus != FT_OK) return ftStatus; ftStatus = FT_Open(0, &ftHandle); if(ftStatus != FT_OK) return ftStatus; ftStatus = FT_ResetDevice(ftHandle); if(ftStatus != FT_OK) return ftStatus; ftStatus = FT_Purge(ftHandle, FT_PURGE_RX | FT_PURGE_TX); if(ftStatus != FT_OK) return ftStatus; ftStatus = FT_SetBaudRate(ftHandle, 15625); if(ftStatus != FT_OK) return ftStatus; ftStatus = FT_SetDataCharacteristics(ftHandle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE); if(ftStatus != FT_OK) return ftStatus; ftStatus = FT_SetFlowControl(ftHandle, FT_FLOW_NONE, 0, 0); if(ftStatus != FT_OK) return ftStatus; ftStatus = FT_SetTimeouts(ftHandle, 1000, 1000); if(ftStatus != FT_OK) return ftStatus; ftStatus = FT_GetLatencyTimer(ftHandle, &timer); if(ftStatus != FT_OK) return ftStatus; ftStatus = FT_SetLatencyTimer(ftHandle, 1); if(ftStatus != FT_OK) return ftStatus; return FT_OK; }
bool FTDXXDevice::connect (int baudrate) throw () { #ifdef FOUND_ftd2xx disconnect(); _status = FT_SetVIDPID(0x0403, 0x6001); FXXCHECK("Could not set IDs."); _status = FT_Open(0, &_handle); FXXCHECK("Could not open handle."); _status = FT_SetBaudRate(_handle, baudrate); FXXCHECK("Could not set baudrate."); _status = FT_SetLatencyTimer(_handle, 0); FXXCHECK("Unable to set latency timer."); _status = FT_Purge(_handle, FT_PURGE_RX | FT_PURGE_TX); FXXCHECK("Unable to purge buffers."); _initialized = true; FTDLOG("Connection successful."); return true; #else _initialized = false; FTDERROR("cannot connect FTD2xx device: compiled without required libraries"); return false; #endif }
int main(int argc, char *argv[]) { unsigned char * pucUAdata; DWORD dwUASize, dwUARead; FILE * fp; FT_HANDLE ftHandle0; FT_STATUS ftStatus; int iport; if(argc > 1) { sscanf(argv[1], "%d", &iport); } else { iport = 0; } printf("opening port %d\n", iport); ftStatus = FT_Open(iport, &ftHandle0); if(ftStatus == FT_OK) { printf("ftHandle0 = %p\n", ftHandle0); } else { /* This can fail if the ftdi_sio driver is loaded use lsmod to check this and rmmod ftdi_sio to remove also rmmod usbserial */ printf("FT_Open(%d) failed\n", iport); return 1; } ftStatus = FT_EE_UASize(ftHandle0, &dwUASize); if(ftStatus == FT_OK) printf("dwUASize = %d\n", (int)dwUASize); else { printf("Could not read UA size\n"); FT_Close(ftHandle0); return 1; } pucUAdata = (unsigned char *)malloc(dwUASize); if(pucUAdata == NULL) { printf("Out of resources\n"); FT_Close(ftHandle0); return 1; } ftStatus = FT_EE_UARead(ftHandle0, pucUAdata, dwUASize, &dwUARead); if(ftStatus == FT_OK) { fp = fopen("UA_DATA.bin", "w+"); fwrite(pucUAdata, 1, dwUARead, fp); fclose(fp); } else{ printf("could not read UA\n"); } free(pucUAdata); FT_Close(ftHandle0); return 0; }
QString FTD2XXInterface::readLabel(uchar label, int *ESTA_code) { FT_HANDLE ftdi = NULL; if (FT_Open(id(), &ftdi) != FT_OK) return QString(); if(FT_ResetDevice(ftdi) != FT_OK) return QString(); if(FT_SetBaudRate(ftdi, 250000) != FT_OK) return QString(); if(FT_SetDataCharacteristics(ftdi, FT_BITS_8, FT_STOP_BITS_2, FT_PARITY_NONE) != FT_OK) return QString(); if(FT_SetFlowControl(ftdi, 0, 0, 0) != FT_OK) return QString(); QByteArray request; request.append(ENTTEC_PRO_START_OF_MSG); request.append(label); request.append(ENTTEC_PRO_DMX_ZERO); // data length LSB request.append(ENTTEC_PRO_DMX_ZERO); // data length MSB request.append(ENTTEC_PRO_END_OF_MSG); DWORD written = 0; if (FT_Write(ftdi, (char*) request.data(), request.size(), &written) != FT_OK) return QString(); if (written == 0) { qDebug() << Q_FUNC_INFO << "Cannot write data to device"; return QString(); } uchar* buffer = (uchar*) malloc(sizeof(uchar) * 40); Q_ASSERT(buffer != NULL); int read = 0; QByteArray array; FT_SetTimeouts(ftdi, 500,0); FT_Read(ftdi, buffer, 40, (LPDWORD) &read); qDebug() << Q_FUNC_INFO << "----- Read: " << read << " ------"; for (int i = 0; i < read; i++) array.append((char) buffer[i]); if (array[0] != ENTTEC_PRO_START_OF_MSG) qDebug() << Q_FUNC_INFO << "Reply message wrong start code: " << QString::number(array[0], 16); *ESTA_code = (array[5] << 8) | array[4]; array.remove(0, 6); // 4 bytes of Enttec protocol + 2 of ESTA ID array.replace(ENTTEC_PRO_END_OF_MSG, '\0'); // replace Enttec termination with string termination FT_Close(ftdi); return QString(array); }
bool D2xxSerial::open(int which, int baudRate) { FT_STATUS err = FT_Open(0,&handle); if (err != FT_OK) { // FT_OpenEx failed printf("Error connecting to [%d]: %s\n", which, getError(err)); return false; } setBaudRate(baudRate); return true; }
int main(int argc, char *argv[]) { DWORD dwBytesInQueue = 0; EVENT_HANDLE eh; FT_STATUS ftStatus; FT_HANDLE ftHandle; int iport; if(argc > 1) { sscanf(argv[1], "%d", &iport); } else { iport = 0; } pthread_mutex_init(&eh.eMutex, NULL); pthread_cond_init(&eh.eCondVar, NULL); ftStatus = FT_Open(iport, &ftHandle); if(ftStatus != FT_OK) { /* This can fail if the ftdi_sio driver is loaded use lsmod to check this and rmmod ftdi_sio to remove also rmmod usbserial */ printf("FT_Open(%d) failed\n", iport); return 1; } ftStatus = FT_SetFlowControl(ftHandle, FT_FLOW_NONE, 0, 0); if(ftStatus != FT_OK) { printf("Failed to set flow control\n"); } ftStatus = FT_SetEventNotification(ftHandle, FT_EVENT_RXCHAR, (PVOID)&eh); if(ftStatus != FT_OK) { printf("Failed to set events\n"); return 1; } pthread_mutex_lock(&eh.eMutex); pthread_cond_wait(&eh.eCondVar, &eh.eMutex); pthread_mutex_unlock(&eh.eMutex); FT_GetQueueStatus(ftHandle, &dwBytesInQueue); printf("Received chars %d bytes in queue\n", (int)dwBytesInQueue); FT_Close(ftHandle); return 0; }
/** * Открытие устройства */ int FtdiDevices::openDSUSession() { ftStatus = FT_Open( 0 /* Порт A */, &m_ftHandleA ); if ( ftStatus != FT_OK ) { /* Запись в лог сообщения */ appLogger.sendDataToViewer( appLogger.ERROR_MSG_TYPE," Операция открытия порта не выполнена! ", appLogger.SYSTEM_LOGGER ); return false; } else { /* Запись в лог сообщения */ appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE," Операция открытия порта выполнена! ", appLogger.SYSTEM_LOGGER ); return true; } return true; }
int main(int argc, char *argv[]) { char * pcBufRead; DWORD dwBytesRead; FILE * fh; FT_HANDLE ftHandle; FT_STATUS ftStatus; int iport; if(argc > 1) { sscanf(argv[1], "%d", &iport); } else { iport = 0; } fh = fopen("target.bin", "wb+"); if(fh == NULL) { printf("Cant open source file\n"); return 1; } ftStatus = FT_Open(iport, &ftHandle); if(ftStatus != FT_OK) { /* This can fail if the ftdi_sio driver is loaded use lsmod to check this and rmmod ftdi_sio to remove also rmmod usbserial */ printf("FT_Open(%d) failed\n", iport); return 1; } pcBufRead = (char *)malloc(BUF_SIZE); FT_ResetDevice(ftHandle); FT_SetBaudRate(ftHandle, 115200); FT_SetDtr(ftHandle); FT_SetRts(ftHandle); FT_SetFlowControl(ftHandle, FT_FLOW_RTS_CTS, 0, 0); FT_SetTimeouts(ftHandle, 0, 0); // infinite timeouts FT_SetBitMode(ftHandle, 0xFF, 0x01); FT_Read(ftHandle, pcBufRead, BUF_SIZE, &dwBytesRead); fwrite(pcBufRead, 1, dwBytesRead, fh); fclose(fh); free(pcBufRead); FT_Close(ftHandle); return 0; }
/** * Запись в порт Б микросхемы ftdi */ void FtdiDevices::writeToPortB( char data ){ DWORD BytesWritten; /* Запись в лог сообщения */ appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE, " Исполнение операции записи (WRITE_PORTB) ", appLogger.SYSTEM_LOGGER ); if ( listPorts.size() > -1 ) { ftStatus = FT_Open( 1 /* Порт Б */, &m_ftHandleB ); if ( ftStatus != FT_OK ) { /* Запись в лог сообщения */ appLogger.sendDataToViewer( appLogger.ERROR_MSG_TYPE," Операция открытия порта не выполнена! ", appLogger.SYSTEM_LOGGER ); } else { /* Запись в лог сообщения */ appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE," Операция открытия порта выполнена! ", appLogger.SYSTEM_LOGGER ); } ftStatus = FT_SetBitMode( m_ftHandleB, 0xFE, 0x01 ); if ( ftStatus == FT_OK ) { /* Запись в лог сообщения */ appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE," Операция установки bitbang порта выполнена! ", appLogger.SYSTEM_LOGGER ); } else { /* Запись в лог сообщения */ appLogger.sendDataToViewer( appLogger.ERROR_MSG_TYPE," Операция установки bitbang порта не выполнена! ", appLogger.SYSTEM_LOGGER ); } ftStatus = FT_Write( m_ftHandleB, &data, 1, &BytesWritten ); if ( ftStatus != FT_OK ) { /* Запись в лог сообщения */ appLogger.sendDataToViewer( appLogger.ERROR_MSG_TYPE," Операция записи в порт не выполнена! ", appLogger.SYSTEM_LOGGER );; } else { /* Запись в лог сообщения */ appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE," Операция записи в порт выполнена! ", appLogger.SYSTEM_LOGGER ); } FT_Close( m_ftHandleB ); if ( ftStatus != FT_OK ) { /* Запись в лог сообщения */ appLogger.sendDataToViewer( appLogger.ERROR_MSG_TYPE," Операция закрытия порта не выполнена! ", appLogger.SYSTEM_LOGGER ); } else { /* Запись в лог сообщения */ appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE," Операция закрытия порта выполнена! ", appLogger.SYSTEM_LOGGER ); } } }
bool NxDeviceDmx::ConnectDevice() { int RTimeout =120; int WTimeout =100; int VersionMSB =0; int VersionLSB =0; unsigned char temp[4]; long version; unsigned char major_ver,minor_ver,build_ver; int recvd =0; unsigned char byte = 0; int size = 0; int res = 0; int tries =0; unsigned char latencyTimer; FT_STATUS ftStatus; int BreakTime; int MABTime; mDevice->mUsePro = false; // to do if Log("Waiting for GET_WIDGET_PARAMS_REPLY packet... "); is noresponse if( mDevice->mUsePro ) { int device_num = 0; FT_STATUS ftStatus = FT_Open(device_num,&mDevice->device_handle); if( ftStatus == FT_OK ) { Log(" opened Pro enttec Device"); } else { Log(" Cant open Pro enttec Device"); } // GET D2XX Driver Version ftStatus = FT_GetDriverVersion(mDevice->device_handle,(LPDWORD)&version); if (ftStatus == FT_OK) { major_ver = (unsigned char) version >> 16; minor_ver = (unsigned char) version >> 8; build_ver = (unsigned char) version & 0xFF; //Log("\nD2XX Driver Version:: %02X.%02X.%02X ",major_ver,minor_ver,build_ver); Log("Found Driver Version"); }
bool FTD2XXInterface::open() { if (isOpen() == true) return true; FT_STATUS status = FT_Open(id(), &m_handle); if (status != FT_OK) { qWarning() << Q_FUNC_INFO << "Error opening" << name() << status; return false; } else { return true; } }
bool QLCFTDI::open() { if (isOpen() == true) return true; FT_STATUS status = FT_Open(m_id, &m_handle); if (status != FT_OK) { qWarning() << Q_FUNC_INFO << "Error opening" << name() << status; return false; } else { return true; } }
void setCBUSbits(UCHAR cbus1) { ftStatus = FT_Open(i,&ftHandle); ftStatus = FT_EE_Read(ftHandle, &ftData); if (ftStatus == FT_OK) { old_cbus1_state=ftData.Cbus1; // save state of cbus1 // ftData.Cbus0=0; ftData.Cbus1 = cbus1; // 0x0A will set to I/O mode, otherwise restore from old_cbus1_state // ftData.Cbus2=1; // ftData.Cbus3=2; // ftData.Cbus4=1; ftStatus = FT_EE_Program(ftHandle, &ftData); if (ftStatus == FT_OK) { ftStatus = FT_CyclePort(ftHandle); if (ftStatus == FT_OK) { // Port has been cycled. // Close the handle. ftStatus = FT_Close(ftHandle); if (ftStatus==FT_OK) { printf("Device Close OK! \n"); ftStatus=FT_Rescan(); Sleep(5000); } else { printf("Device Close Failed! \n"); } } else { // FT_CyclePort FAILED! printf("CyclePort Failed!\n"); } } else { // FT_EE_Program FAILED! printf("FT_EE_Program FAILED!\n"); } } }
int main(int argc, char *argv[]) { DWORD dwBytesInQueue = 0; FT_STATUS ftStatus; FT_HANDLE ftHandle; unsigned char ucMode = 0x00; int iport; if(argc > 1) { sscanf(argv[1], "%d", &iport); } else { iport = 0; } ftStatus = FT_Open(iport, &ftHandle); if(ftStatus != FT_OK) { /* This can fail if the ftdi_sio driver is loaded use lsmod to check this and rmmod ftdi_sio to remove also rmmod usbserial */ printf("FT_Open(%d) failed\n", iport); return 1; } ftStatus = FT_SetBitMode(ftHandle, 0xFF, 1); if(ftStatus != FT_OK) { printf("Failed to set bit mode\n"); } FT_SetBaudRate(ftHandle, 9600); FT_Write(ftHandle, &ucMode, 1, &dwBytesInQueue); ftStatus = FT_GetBitMode(ftHandle, &ucMode); if(ftStatus != FT_OK) { printf("Failed to get bit mode\n"); } else { printf("ucMode = 0x%X\n", ucMode); } FT_Close(ftHandle); return 0; }
BOOL InitializeForBitIO(void) { DWORD DeviceCount; FT_Status = FT_CreateDeviceInfoList(&DeviceCount); if (FT_Status) return printf("FT_CreateDeviceInfoList failed (%d)", FT_Status); if (DeviceCount == 0) return printf("No FTDI devices attached\n"); FT_Status = FT_Open(0, &FT_Handle); if (FT_Status) return printf("FT_Open failed (%d)", FT_Status); FT_Status = FT_SetBaudRate(FT_Handle, 921600); if (FT_Status) return printf("FT_SetBaudRate failed (%d)", FT_Status); FT_Status = FT_SetBitMode(FT_Handle, 1, SyncBitBang); if (FT_Status) return printf("FT_SetBitMode failed (%d)", FT_Status); return 0; }
int dxl_hal_open() { FT_STATUS ft_status; dxl_hal_close(); ft_status = FT_Open( 1, &ghFt_Handle ); if( ft_status != FT_OK ) goto DXL_HAL_OPEN_ERROR; ft_status = FT_ResetDevice( ghFt_Handle ); if( ft_status != FT_OK ) goto DXL_HAL_OPEN_ERROR; ft_status = FT_SetDataCharacteristics( ghFt_Handle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE ); if( ft_status != FT_OK ) goto DXL_HAL_OPEN_ERROR; ft_status = FT_SetFlowControl( ghFt_Handle, FT_FLOW_NONE, (UCHAR)0, (UCHAR)0 ); if( ft_status != FT_OK ) goto DXL_HAL_OPEN_ERROR; ft_status = FT_SetLatencyTimer( ghFt_Handle, LATENCY_TIME ); if( ft_status != FT_OK ) goto DXL_HAL_OPEN_ERROR; ft_status = FT_SetUSBParameters( ghFt_Handle, IN_TRASFER_SIZE, 0 ); if( ft_status != FT_OK ) goto DXL_HAL_OPEN_ERROR; ft_status = FT_SetTimeouts( ghFt_Handle, 0, 0 ); if( ft_status != FT_OK ) goto DXL_HAL_OPEN_ERROR; ft_status = FT_Purge( ghFt_Handle, FT_PURGE_RX|FT_PURGE_TX ); if( ft_status != FT_OK ) goto DXL_HAL_OPEN_ERROR; return 1; DXL_HAL_OPEN_ERROR: dxl_hal_close(); return 0; }
int main(int argc, char *argv[]) { char cBufRead[BUF_SIZE]; DWORD dwBytesRead; FT_STATUS ftStatus; FT_HANDLE ftHandle; int iport; int i; if(argc > 1) { sscanf(argv[1], "%d", &iport); } else { iport = 0; } ftStatus = FT_Open(iport, &ftHandle); if(ftStatus != FT_OK) { /* This can fail if the ftdi_sio driver is loaded use lsmod to check this and rmmod ftdi_sio to remove also rmmod usbserial */ printf("FT_Open(%d) failed, with error %d.\n", iport, (int)ftStatus); printf("Use lsmod to check if ftdi_sio (and usbserial) are present.\n"); printf("If so, unload them using rmmod, as they conflict with ftd2xx.\n"); return 1; } FT_SetTimeouts(ftHandle, 3000, 3000); // 3 second read timeout for(i = 0; i < 10 ; i++) { FT_Read(ftHandle, cBufRead, BUF_SIZE, &dwBytesRead); if(dwBytesRead != BUF_SIZE) printf("Timeout %d\n", i); else printf("Read %d\n", (int)dwBytesRead); } FT_Close(ftHandle); return 0; }
/** * Get some interesting strings from the device. * * @param deviceIndex The device index, whose strings to get * @param vendor Returned vendor string * @param description Returned description string * @param serial Returned serial string * @return FT_OK if strings were extracted successfully */ static FT_STATUS get_interface_info(DWORD deviceIndex, QString& vendor, QString& description, QString& serial, quint16 &VID, quint16 &PID) { char cVendor[256]; char cVendorId[256]; char cDescription[256]; char cSerial[256]; FT_HANDLE handle; FT_STATUS status = FT_Open(deviceIndex, &handle); if (status != FT_OK) return status; FT_PROGRAM_DATA pData; pData.Signature1 = 0; pData.Signature2 = 0xFFFFFFFF; pData.Version = 0x00000005; pData.Manufacturer = cVendor; pData.ManufacturerId = cVendorId; pData.Description = cDescription; pData.SerialNumber = cSerial; status = FT_EE_Read(handle, &pData); if (status == FT_OK) { VID = pData.VendorId; PID = pData.ProductId; if (pData.ProductId == DMXInterface::DMX4ALLPID) vendor = QString("DMX4ALL"); else vendor = QString(cVendor); description = QString(cDescription); serial = QString(cSerial); } FT_Close(handle); return status; }
/* Open USB */ quint16 ftdiChip::Open() { FT_STATUS ftStatus; if (hdUSB!=NULL){Close();} ftStatus=FT_Open(numDevice,&hdUSB); if (ftStatus!=FT_OK){ emit signalStatusError(tr("Error open USB"),true); return retErr; } ftStatus=FT_SetUSBParameters(hdUSB,1024,1024); if (ftStatus!=FT_OK){// Error setting buffer sizes USB emit signalStatusError(tr("Error setting buffer sizes USB"),true); return retErr; } ftStatus = FT_SetTimeouts(hdUSB,10,1); if(ftStatus != FT_OK){ return retErr; } return retOk; }
int main() { int i,n; unsigned char data[255 * 256]; FT_HANDLE handle; DWORD bytes; /* Generate data for a single PWM 'throb' cycle */ memset(data, 0, sizeof(data)); for(i=1; i<128; i++) { /* Apply gamma correction to PWM brightness */ n = (int)(pow((double)i / 127.0, 2.5) * 255.0); memset(&data[i * 255], LED1, n); /* Ramp up */ memset(&data[(256 - i) * 255], LED1, n); /* Ramp down */ } /* Copy data from first LED to others, offset as appropriate */ n = sizeof(data) / 4; for(i=0; i<sizeof(data); i++) { if(data[i] & LED1) { data[(i + n ) % sizeof(data)] |= LED2; data[(i + n * 2) % sizeof(data)] |= LED3; data[(i + n * 3) % sizeof(data)] |= LED4; } } /* Initialize, open device, set bitbang mode w/5 outputs */ if(FT_Open(0, &handle) != FT_OK) { puts("Can't open device"); return 1; } FT_SetBitMode(handle, LED1 | LED2 | LED3 | LED4, 1); FT_SetBaudRate(handle, 9600); /* Actually 9600 * 16 */ /* Endless loop: dump precomputed PWM data to the device */ for(;;) FT_Write(handle, &data, (DWORD)sizeof(data), &bytes); }
int main(int argc, char *argv[]) { DWORD dwUASize; FT_STATUS ftStatus; FT_HANDLE ftHandle0; int iport; if(argc > 1) { sscanf(argv[1], "%d", &iport); } else { iport = 0; } printf("opening port %d\n", iport); ftStatus = FT_Open(iport, &ftHandle0); if(ftStatus == FT_OK) { printf("ftHandle0 = %p\n", (void *)ftHandle0); } else { /* This can fail if the ftdi_sio driver is loaded use lsmod to check this and rmmod ftdi_sio to remove also rmmod usbserial */ printf("FT_Open(%d) failed\n", iport); return 1; } ftStatus = FT_EE_UASize(ftHandle0, &dwUASize); if(ftStatus == FT_OK) printf("dwUASize = %d\n", (int)dwUASize); ftStatus = FT_Close(ftHandle0); return 0; }
int main(int argc, char *argv[]) { pthread_t thread_id; int i; FT_STATUS ftStatus; (void)argc; /* Deliberately unused parameter */ (void)argv; /* Deliberately unused parameter */ exit_reader = 0; ftStatus = FT_Open(0, &ftHandle); pthread_create(&thread_id, NULL, &read_watch, NULL); for(i = 0; i < 1000; i++) { char buf[100]; DWORD index = 0; ftStatus = FT_ListDevices((PVOID)(uintptr_t)index, (void*)buf, FT_LIST_BY_INDEX | FT_OPEN_BY_SERIAL_NUMBER); if(ftStatus == FT_OK) { // printf("FT_LIST_BY_INDEX = %s\n"); } else { printf("FT_LIST_BY_INDEX failed(%d)\n", (int)ftStatus); } } exit_reader = 1; /* wait for it to exit */ pthread_join(thread_id, NULL); return 0; }
int main(int argc, char *argv[]) { static const struct option long_opts[] = { {"verbose", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, {"id", required_argument, NULL, 'i'}, {NULL, no_argument, NULL, 0} }; opterr = 0; int c; int option_index = 0; while ((c = getopt_long(argc, argv, "vhi:", long_opts, &option_index)) != -1) switch (c) { case 'v': verbose++; break; case 'h': print_usage(); return EXIT_SUCCESS; case 'i': { pid = parse_pid(optarg); if (!pid) { fprintf(stderr, "Invalid ID argument.\n"); return EXIT_FAILURE; } break; } case '?': if (optopt == 'i') fprintf(stderr, "ID argument requires an argument.\n"); else fprintf(stderr, "Unknown option `-%c'.\n", optopt); return EXIT_FAILURE; default: abort(); } int iport = 0; /* Try to open device using input PID, or our custom PID if no input. */ if (verbose) printf("Trying to open with VID=0x%04x, PID=0x%04x...",USB_CUSTOM_VID,pid); ft_status = FT_SetVIDPID(USB_CUSTOM_VID, pid); if (ft_status != FT_OK){ fprintf(stderr,"ERROR : Failed to set VID and PID, ft_status = %d\n",ft_status); return EXIT_FAILURE; } ft_status = FT_Open(iport, &ft_handle); /* Exit program if we haven't opened the device. */ if (ft_status != FT_OK){ if (verbose) printf("FAILED\n"); fprintf(stderr,"ERROR : Failed to open device : ft_status = %d\n",ft_status); return EXIT_FAILURE; } if (verbose) printf("SUCCESS\n"); /* Erase the EEPROM to set the device to UART mode. */ if (verbose) printf("Erasing device EEPROM\n"); ft_status = FT_EraseEE(ft_handle); if(ft_status != FT_OK) { fprintf(stderr, "ERROR: Device EEPROM could not be erased : ft_status = %d\n", ft_status); return EXIT_FAILURE; } /* Reset the device. */ if (verbose) printf("Resetting device\n"); ft_status = FT_ResetDevice(ft_handle); if(ft_status != FT_OK) { fprintf(stderr, "ERROR: Device could not be reset : ft_status = %d\n", ft_status); return EXIT_FAILURE; } /* Close the device. */ if (verbose) printf("Closing device\n"); FT_Close(ft_handle); if(ft_status != FT_OK) { fprintf(stderr,"ERROR : Failed to close device : ft_status = %d\n",ft_status); return EXIT_FAILURE; } if (verbose) printf("Re-configuring for UART mode successful, please unplug and replug your device now\n"); return EXIT_SUCCESS; }
static int bitforce_autodetect_ftdi(void) { char devpath[] = "\\\\.\\COMnnnnn"; char *devpathnum = &devpath[7]; char **bufptrs; char *buf; int found = 0; int i; FT_STATUS ftStatus; DWORD numDevs; HMODULE dll = LoadLibrary("FTD2XX.DLL"); if (!dll) { applog(LOG_DEBUG, "FTD2XX.DLL failed to load, not using FTDI bitforce autodetect"); return 0; } LOAD_SYM(FT_ListDevices); LOAD_SYM(FT_Open); LOAD_SYM(FT_GetComPortNumber); LOAD_SYM(FT_Close); ftStatus = FT_ListDevices(&numDevs, NULL, FT_LIST_NUMBER_ONLY); if (ftStatus != FT_OK) { applog(LOG_DEBUG, "FTDI device count failed, not using FTDI bitforce autodetect"); goto out; } applog(LOG_DEBUG, "FTDI reports %u devices", (unsigned)numDevs); buf = alloca(65 * numDevs); bufptrs = alloca(numDevs + 1); for (i = 0; i < numDevs; ++i) bufptrs[i] = &buf[i * 65]; bufptrs[numDevs] = NULL; ftStatus = FT_ListDevices(bufptrs, &numDevs, FT_LIST_ALL | FT_OPEN_BY_DESCRIPTION); if (ftStatus != FT_OK) { applog(LOG_DEBUG, "FTDI device list failed, not using FTDI bitforce autodetect"); goto out; } for (i = numDevs; i > 0; ) { --i; bufptrs[i][64] = '\0'; if (!(strstr(bufptrs[i], "BitFORCE") && strstr(bufptrs[i], "SHA256"))) continue; FT_HANDLE ftHandle; if (FT_OK != FT_Open(i, &ftHandle)) continue; LONG lComPortNumber; ftStatus = FT_GetComPortNumber(ftHandle, &lComPortNumber); FT_Close(ftHandle); if (FT_OK != ftStatus || lComPortNumber < 0) continue; sprintf(devpathnum, "%d", (int)lComPortNumber); if (bitforce_detect_one(devpath)) ++found; } out: dlclose(dll); return found; }
int main(int argc, char *argv[]) { FT_STATUS ftStatus; FT_HANDLE ftHandle0; int iport; FT_PROGRAM_DATA Data; if(argc > 1) { sscanf(argv[1], "%d", &iport); } else { iport = 0; } printf("opening port %d\n", iport); FT_SetVIDPID(0x0403, 0x6011); ftStatus = FT_Open(iport, &ftHandle0); if(ftStatus != FT_OK) { /* This can fail if the ftdi_sio driver is loaded use lsmod to check this and rmmod ftdi_sio to remove also rmmod usbserial */ printf("FT_Open(%d) failed\n", iport); return 1; } printf("ftHandle0 = %p\n", ftHandle0); #ifndef BM_DEVICE Data.Signature1 = 0x00000000; Data.Signature2 = 0xffffffff; Data.VendorId = 0x0403; Data.ProductId = 0x6001; Data.Manufacturer = "FTDI"; Data.ManufacturerId = "FT"; Data.Description = "USB <-> Serial"; Data.SerialNumber = "FT000001"; // if fixed, or NULL Data.MaxPower = 44; Data.PnP = 1; Data.SelfPowered = 0; Data.RemoteWakeup = 1; Data.Rev4 = 1; Data.IsoIn = 0; Data.IsoOut = 0; Data.PullDownEnable = 1; Data.SerNumEnable = 1; Data.USBVersionEnable = 0; Data.USBVersion = 0x110; #else // If 2232C Data.Signature1 = 0x00000000; Data.Signature2 = 0xffffffff; Data.VendorId = 0x0403; Data.ProductId = 0x6010; Data.Manufacturer = "FTDI"; Data.ManufacturerId = "FT"; Data.Description = "SPI"; Data.SerialNumber = "FT123452"; // if fixed, or NULL Data.MaxPower = 200; Data.PnP = 1; Data.SelfPowered = 0; Data.RemoteWakeup = 0; Data.Rev4 = 0; Data.IsoIn = 0; Data.IsoOut = 0; Data.PullDownEnable = 0; Data.SerNumEnable = 0; Data.USBVersionEnable = 0; Data.USBVersion = 0; Data.Rev5 = 1; // non-zero if Rev5 chip, zero otherwise Data.IsoInA = 0; // non-zero if in endpoint is isochronous Data.IsoInB = 0; // non-zero if in endpoint is isochronous Data.IsoOutA = 0; // non-zero if out endpoint is isochronous Data.IsoOutB = 0; // non-zero if out endpoint is isochronous Data.PullDownEnable5 = 0; // non-zero if pull down enabled Data.SerNumEnable5 = 1; // non-zero if serial number to be used Data.USBVersionEnable5 = 0; // non-zero if chip uses USBVersion Data.USBVersion5 = 0x0200; // BCD (0x0200 => USB2) Data.AIsHighCurrent = 0; // non-zero if interface is high current Data.BIsHighCurrent = 0; // non-zero if interface is high current Data.IFAIsFifo = 1; // non-zero if interface is 245 FIFO Data.IFAIsFifoTar = 0; // non-zero if interface is 245 FIFO CPU target Data.IFAIsFastSer = 0; // non-zero if interface is Fast serial Data.AIsVCP = 0; // non-zero if interface is to use VCP drivers Data.IFBIsFifo = 1; // non-zero if interface is 245 FIFO Data.IFBIsFifoTar = 0; // non-zero if interface is 245 FIFO CPU target Data.IFBIsFastSer = 0; // non-zero if interface is Fast serial Data.BIsVCP = 0; // non-zero if interface is to use VCP drivers #endif ftStatus = FT_EE_Program(ftHandle0, &Data); if(ftStatus != FT_OK) { printf("FT_EE_Program failed (%d)\n", ftStatus); FT_Close(ftHandle0); } FT_Close(ftHandle0); return 0; }
static void FTClassicPort_open(FTClassicPort *self,int deviceNumber){ self->status = FT_Open(deviceNumber, &(self->handle)); }
int main(int argc, char *argv[]) { int retCode = -1; // Assume failure int f = 0; FT_STATUS ftStatus = FT_OK; FT_HANDLE ftHandle = NULL; int portNum = -1; // Deliberately invalid DWORD bytesToWrite = 0; DWORD bytesWritten = 0; int inputRate = -1; // Entered on command line int baudRate = 38400; // Rate to actually use int rates[] = {50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 576000, 921600}; if (argc > 1) { sscanf(argv[1], "%d", &portNum); } if (portNum < 0) { // Missing, or invalid. Just use first port. portNum = 0; } if (portNum > 16) { // User probably specified a baud rate without a port number printf("Syntax: %s [port number] [baud rate]\n", argv[0]); portNum = 0; } if (argc > 2) { sscanf(argv[2], "%d", &inputRate); for (f = 0; f < (int)(ARRAY_SIZE(rates)); f++) { if (inputRate == rates[f]) { // User entered a rate we support, so we'll use it. baudRate = inputRate; break; } } } if (baudRate < 0) baudRate = 9600; printf("Trying FTDI device %d at %d baud.\n", portNum, baudRate); ftStatus = FT_Open(portNum, &ftHandle); if (ftStatus != FT_OK) { printf("FT_Open(%d) failed, with error %d.\n", portNum, (int)ftStatus); printf("Use lsmod to check if ftdi_sio (and usbserial) are present.\n"); printf("If so, unload them using rmmod, as they conflict with ftd2xx.\n"); goto exit; } assert(ftHandle != NULL); ftStatus = FT_ResetDevice(ftHandle); if (ftStatus != FT_OK) { printf("Failure. FT_ResetDevice returned %d.\n", (int)ftStatus); goto exit; } ftStatus = FT_SetBaudRate(ftHandle, (ULONG)baudRate); if (ftStatus != FT_OK) { printf("Failure. FT_SetBaudRate(%d) returned %d.\n", baudRate, (int)ftStatus); goto exit; } ftStatus = FT_SetDataCharacteristics(ftHandle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE); if (ftStatus != FT_OK) { printf("Failure. FT_SetDataCharacteristics returned %d.\n", (int)ftStatus); goto exit; } // Indicate our presence to remote computer ftStatus = FT_SetDtr(ftHandle); if (ftStatus != FT_OK) { printf("Failure. FT_SetDtr returned %d.\n", (int)ftStatus); goto exit; } // Flow control is needed for higher baud rates ftStatus = FT_SetFlowControl(ftHandle, FT_FLOW_RTS_CTS, 0, 0); if (ftStatus != FT_OK) { printf("Failure. FT_SetFlowControl returned %d.\n", (int)ftStatus); goto exit; } // Assert Request-To-Send to prepare remote computer ftStatus = FT_SetRts(ftHandle); if (ftStatus != FT_OK) { printf("Failure. FT_SetRts returned %d.\n", (int)ftStatus); goto exit; } ftStatus = FT_SetTimeouts(ftHandle, 3000, 3000); // 3 seconds if (ftStatus != FT_OK) { printf("Failure. FT_SetTimeouts returned %d\n", (int)ftStatus); goto exit; } bytesToWrite = (DWORD)(sizeof(testPattern) - 1); // Don't write string terminator ftStatus = FT_Write(ftHandle, testPattern, bytesToWrite, &bytesWritten); if (ftStatus != FT_OK) { printf("Failure. FT_Write returned %d\n", (int)ftStatus); goto exit; } if (bytesWritten != bytesToWrite) { printf("Failure. FT_Write wrote %d bytes instead of %d.\n", (int)bytesWritten, (int)bytesToWrite); goto exit; } // Success retCode = 0; printf("Successfully wrote %d bytes\n", (int)bytesWritten); exit: if (ftHandle != NULL) FT_Close(ftHandle); return retCode; }
int main(int argc, char *argv[]) { FT_STATUS ftStatus; FT_HANDLE ftHandle0; int iport; FT_PROGRAM_DATA Data; char *serialstr; if(argc == 3) { sscanf(argv[1], "%d", &iport); serialstr = argv[2]; } else { fprintf(stderr, "syntax: %s iPort serialPrefix serialNumber\n", argv[0]); return -1; } //printf("opening port %d\n", iport); FT_SetVIDPID(0x0403, 0x6014); ftStatus = FT_Open(iport, &ftHandle0); if(ftStatus != FT_OK) { /* This can fail if the ftdi_sio driver is loaded use lsmod to check this and rmmod ftdi_sio to remove also rmmod usbserial */ printf("FT_Open port %d failed\n", iport); return 1; } Data.Signature1 = 0x00000000; Data.Signature2 = 0xffffffff; Data.Version = 5; //FT232H Data.VendorId = 0x0403; Data.ProductId = 0x6014; Data.Manufacturer = "DLRC"; Data.ManufacturerId = "FT"; Data.Description = "DLRC SNAPNODE Plus Rev 2.0"; Data.SerialNumber = serialstr; // if fixed, or NULL Data.MaxPower = 500; Data.PnP = 1; Data.SelfPowered = 0; Data.RemoteWakeup = 1; //FT232H Data.PullDownEnableH = 1; // non-zero if pull down enabled Data.SerNumEnableH = 1; // non-zero if serial number to be used Data.ACSlowSlewH = 0; // non-zero if AC pins have slow slew Data.ACSchmittInputH = 0; // non-zero if AC pins are Schmitt input Data.ACDriveCurrentH = 4; // valid values are 4mA, 8mA, 12mA, 16mA Data.ADSlowSlewH = 0; // non-zero if AD pins have slow slew Data.ADSchmittInputH = 0; // non-zero if AD pins are Schmitt input Data.ADDriveCurrentH = 4; // valid values are 4mA, 8mA, 12mA, 16mA Data.Cbus0H = 0; // Cbus Mux control Data.Cbus1H = 0; // Cbus Mux control Data.Cbus2H = 0; // Cbus Mux control Data.Cbus3H = 1; // Cbus Mux control Data.Cbus4H = 2; // Cbus Mux control Data.Cbus5H = 0; // Cbus Mux control Data.Cbus6H = 0; // Cbus Mux control Data.Cbus7H = 0; // Cbus Mux control Data.Cbus8H = 0; // Cbus Mux control Data.Cbus9H = 0; // Cbus Mux control Data.IsFifoH = 0; // non-zero if interface is 245 FIFO Data.IsFifoTarH = 0; // non-zero if interface is 245 FIFO CPU target Data.IsFastSerH = 0; // non-zero if interface is Fast serial Data.IsFT1248H = 0; // non-zero if interface is FT1248 Data.FT1248CpolH = 0; // FT1248 clock polarity - clock idle high (1) or clock idle low (0) Data.FT1248LsbH = 0; // FT1248 data is LSB (1) or MSB (0) Data.FT1248FlowControlH = 0;// FT1248 flow control enable Data.IsVCPH = 1; // non-zero if interface is to use VCP drivers Data.PowerSaveEnableH = 1; // non-zero if using ACBUS7 to save power for self-powered designs #ifdef H2232_DEVICE // If 2232C Data.Signature1 = 0x00000000; Data.Signature2 = 0xffffffff; Data.VendorId = 0x0403; Data.ProductId = 0x6010; Data.Manufacturer = "FTDI"; Data.ManufacturerId = "FT"; Data.Description = "SPI"; Data.SerialNumber = "FT123452"; // if fixed, or NULL Data.MaxPower = 200; Data.PnP = 1; Data.SelfPowered = 0; Data.RemoteWakeup = 0; Data.Rev4 = 0; Data.IsoIn = 0; Data.IsoOut = 0; Data.PullDownEnable = 0; Data.SerNumEnable = 0; Data.USBVersionEnable = 0; Data.USBVersion = 0; Data.Rev5 = 1; // non-zero if Rev5 chip, zero otherwise Data.IsoInA = 0; // non-zero if in endpoint is isochronous Data.IsoInB = 0; // non-zero if in endpoint is isochronous Data.IsoOutA = 0; // non-zero if out endpoint is isochronous Data.IsoOutB = 0; // non-zero if out endpoint is isochronous Data.PullDownEnable5 = 0; // non-zero if pull down enabled Data.SerNumEnable5 = 1; // non-zero if serial number to be used Data.USBVersionEnable5 = 0; // non-zero if chip uses USBVersion Data.USBVersion5 = 0x0200; // BCD (0x0200 => USB2) Data.AIsHighCurrent = 0; // non-zero if interface is high current Data.BIsHighCurrent = 0; // non-zero if interface is high current Data.IFAIsFifo = 1; // non-zero if interface is 245 FIFO Data.IFAIsFifoTar = 0; // non-zero if interface is 245 FIFO CPU target Data.IFAIsFastSer = 0; // non-zero if interface is Fast serial Data.AIsVCP = 0; // non-zero if interface is to use VCP drivers Data.IFBIsFifo = 1; // non-zero if interface is 245 FIFO Data.IFBIsFifoTar = 0; // non-zero if interface is 245 FIFO CPU target Data.IFBIsFastSer = 0; // non-zero if interface is Fast serial Data.BIsVCP = 0; // non-zero if interface is to use VCP drivers #endif ftStatus = FT_EE_Program(ftHandle0, &Data); if(ftStatus != FT_OK) { printf("FT_EE_Program failed (%d)\n", (int)ftStatus); FT_Close(ftHandle0); return -1; } //FT_CyclePort(ftHandle0); FT_Close(ftHandle0); return 0; }