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; }
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 }
int nifalcon_close(falcon_device* dev) { if(!dev->is_open) nifalcon_error_return(NIFALCON_DEVICE_NOT_FOUND_ERROR, "tried to close an unopened device"); dev->is_open = 0; FT_Close(dev->falcon); return 0; }
/*************************************************************************** Routine: LinkClose Inputs: None Returns: void Description: Closes the communications channel to the OPTOTRAK. ***************************************************************************/ NDI_DECL1 boolean NDI_DECL2 LinkClose( void ) { #ifdef MESSAGE_BOX_OUTPUT { char szBuff[ 100 ]; sprintf( szBuff, "LinkClose: Count = %d", s_nOpenCount ); MessageBox( 0, szBuff, "LinkClose", MB_OK ); } #endif /* * Close regardless of the Open Count since there's no need to keep the connection open. * Note that we were originally keeping the connection open until Open Count was 1 but * for some unknown reason, s_hndl and s_nOpenCount were being reset to 0 between the * Close and Open count (resulting in Open errors). */ if( s_hndl ) { FT_Close( s_hndl ); s_hndl = 0; } if( s_nOpenCount > 0 ) s_nOpenCount = 0; return TRUE; }
static int ublast_ftd2xx_quit(struct ublast_lowlevel *low) { FT_HANDLE *ftdih = ublast_getftdih(low); FT_Close(*ftdih); return ERROR_OK; }
int gecko_opendevice() { // Open by Serial Number status = FT_OpenEx("GECKUSB0", FT_OPEN_BY_SERIAL_NUMBER, &fthandle); if(status != FT_OK){ eprintf("Error: Couldn't connect to USB Gecko. Please check Installation\n"); return 0; } // Reset the Device status = FT_ResetDevice(fthandle); if(status != FT_OK){ eprintf("Error: Couldnt Reset Device %d\n",status); status = FT_Close(fthandle); return 0; } // Set a 3 second timeout for this example status = FT_SetTimeouts(fthandle,3000,3000); if(status != FT_OK){ eprintf("Error: Timeouts failed to set %d\n",status); status = FT_Close(fthandle); return 0; } // Purge RX buffer status = FT_Purge(fthandle,FT_PURGE_RX); if(status != FT_OK){ eprintf("Error: Problem clearing buffers %d\n",status); status = FT_Close(fthandle); return 0; } // Purge TX buffer status = FT_Purge(fthandle,FT_PURGE_TX); if(status != FT_OK){ eprintf("Error: Problem clearing buffers %d\n",status); status = FT_Close(fthandle); return 0; } // Set packet size in bytes - 65536 packet is maximum packet size (USB 2.0) status = FT_SetUSBParameters(fthandle,65536,0); if(status != FT_OK){ eprintf("Error: Couldnt Set USB Parameters %d\n",status); status = FT_Close(fthandle); return 0; } // take breath sleep(1); return 1; }
void dxl_hal_close() { if( ghFt_Handle != 0 ) { FT_Close( ghFt_Handle ); ghFt_Handle = 0; } }
VOID CDriverInterface::Cleanup() { if (m_FTHandle) { FT_Close(m_FTHandle); m_FTHandle = NULL; } }
/** Close a power meter probe \param pm a pointer to a pm_context \retval 0 - all fine \retval -1 - invalid pm_context */ PM600X_EXPORT int pm_close(struct pm_context *pm) { if (!pm->handle) pm_error_return(-1, "invalid pm_context"); FT_Close(pm->handle); return pm_init(pm); }
/* * Class: kinetic_Kinetic1090Puck * Method: puckClose * Signature: ()I */ JNIEXPORT jint JNICALL Java_kinetic_Kinetic1090Puck_puckClose(JNIEnv * env, jobject obj) { FT_STATUS ftStatus = FT_Close(ftHandle); if (ftStatus != FT_OK) { return -1; } 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); }
static void serial_close () { ProgramMode (0); Reset (1); /* >3 mSec reset pulse */ usleep(3*1000); Reset (0); FT_Close (handle); }
Dynamixel::~Dynamixel(){ if(initialized_){ FT_STATUS ftStatus = FT_Close(ftHandleDYNA_); if (ftStatus != FT_OK){ emit failedToClose(); }else{ emit closed(); } } }
bool FTDXXDevice::disconnect () throw () { if (!_initialized) return false; _initialized = false; FTDLOG("Closing FTDI bus."); #ifdef FOUND_ftd2xx FT_Close(_handle); FXXCHECK("Unable to close handle."); #endif return true; }
int CKMotionIO::Disconnect() { Mutex->Lock(); m_Connected=false; FT_Close(ftHandle); Mutex->Unlock(); return 0; }
void TellStick::rebootTellStick() { FT_STATUS ftStatus = FT_SetBitMode(d->ftHandle, 0xff, 0x20); for (int i = 0; i < 100; ++i) { msleep(1); QApplication::processEvents(); } ftStatus = FT_SetBitMode(d->ftHandle, 0xf0, 0x20); FT_Close(d->ftHandle); QApplication::processEvents(); setUpgradeStep(5); QTimer::singleShot(0, this, SLOT(connectTellStick())); }
/* This is the main reader thread - continually waits for a read */ void *read_watch(void *pArgs) { char buf[20]; DWORD dwRet; FT_STATUS ftStatus; while(exit_reader != 1) { // printf("Write\n"); FT_Write(ftHandle, buf, 20, &dwRet); // sleep(1); } FT_Close(ftHandle); }
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; }
static int presto_close(void) { int result = ERROR_OK; #if BUILD_PRESTO_FTD2XX == 1 DWORD ftbytes; if (presto->handle == (FT_HANDLE)INVALID_HANDLE_VALUE) return result; presto->status = FT_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX); if (presto->status != FT_OK) result = ERROR_JTAG_DEVICE_ERROR; presto->status = FT_Write(presto->handle, &presto_init_seq, sizeof(presto_init_seq), &ftbytes); if (presto->status != FT_OK || ftbytes != sizeof(presto_init_seq)) result = ERROR_JTAG_DEVICE_ERROR; presto->status = FT_SetLatencyTimer(presto->handle, 16); if (presto->status != FT_OK) result = ERROR_JTAG_DEVICE_ERROR; presto->status = FT_Close(presto->handle); if (presto->status != FT_OK) result = ERROR_JTAG_DEVICE_ERROR; else presto->handle = (FT_HANDLE)INVALID_HANDLE_VALUE; #elif BUILD_PRESTO_LIBFTDI == 1 presto->retval = ftdi_write_data(&presto->ftdic, presto_init_seq, sizeof(presto_init_seq)); if (presto->retval != sizeof(presto_init_seq)) result = ERROR_JTAG_DEVICE_ERROR; presto->retval = ftdi_set_latency_timer(&presto->ftdic, 16); if (presto->retval < 0) result = ERROR_JTAG_DEVICE_ERROR; presto->retval = ftdi_usb_close(&presto->ftdic); if (presto->retval < 0) result = ERROR_JTAG_DEVICE_ERROR; else ftdi_deinit(&presto->ftdic); #endif return result; }
int gecko_sendbyte(unsigned char Textbyte) { unsigned int ret = 0; ret = gecko_writebyte(&cmd_sendbyte, 1, &TxSent); if(ret == 0 || ret == 2) { eprintf("Couldn't send the command to console, check DOL is loaded and connection\n"); status = FT_Close(fthandle); return 0; } gecko_writebyte(&Testbyte, 1, &TxSent); // Send byte return 1; }
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; }
//***************************************************** //* Name: pinddrvDeInit //* Purpose: //* In: //* Out: //***************************************************** void pinddrvDeInit(void) { if(enabled) { #ifdef PINDMD2 usb_release_interface( device, MY_INTF ); usb_close( device ); #else // have to reset bitbangmode or the ftdi chip will flood the serial with '[00]' FT_SetBitMode(ftHandle, 0x00, 0x0); FT_Close(ftHandle); #endif } }
/** * Запись в порт Б микросхемы 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 ); } } }
int closeSerialPorts() { int i; FT_STATUS ftStatus; /* Cleanup */ for(i = 0; i < foundDevices; i++) { if((ftStatus = FT_SetDataCharacteristics(ftHandle[i], FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE)) != FT_OK) { printf("Error FT_SetDataCharacteristics(%d) = %s\n", ftStatus, cBufLD[i]); break; } FT_Close(ftHandle[i]); printf("Closed device %s\n", cBufLD[i]); } return 0; }
/*************************************************************************** Routine: LinkReset Inputs: None Returns: void Description: Resets the OPTOTRAK system. ***************************************************************************/ NDI_DECL1 boolean NDI_DECL2 LinkReset( void ) { if( s_hndl ) { FT_ResetPort( s_hndl ); FT_Close( s_hndl ); Sleep( s_nResetDelay ); s_hndl = OpenUSBDevice( s_nUsbType, s_nUsbId ); if( s_hndl ) { return TRUE; } } return FALSE; }
int gecko_readbyte(LPVOID lpBuffer, DWORD dwBytesToRead, LPDWORD lpdwBytesReturned) { // read data based on FTDI D2XX USB 2.0 API status = FT_Read(fthandle, lpBuffer, dwBytesToRead, lpdwBytesReturned); if (status == FT_OK) { if(*lpdwBytesReturned != dwBytesToRead) return 2; } else { eprintf("Error: Read Error. Closing\n"); status = FT_Close(fthandle); return 0; } return 1; }
/**************************************************************************** Function : TCclose() Description : Close FTDI connection and free any data previously allocated by the library. Parameters : None (void). Returns : Nothing (void). ****************************************************************************/ void TCclose(void) { if(ftdiHandle) { FT_Close(ftdiHandle); ftdiHandle = NULL; } if(pixelCurrent) { free(pixelCurrent); pixelCurrent = NULL; pixelOutBuffer = NULL; } nStrands = 0; pixelsPerStrand = 0; }
int gecko_writebyte(LPVOID lpBuffer, DWORD dwBytesToWrite, LPDWORD lpdwBytesWritten) { // write data based on FTDI D2XX USB 2.0 API status = FT_Write(fthandle, lpBuffer, dwBytesToWrite, lpdwBytesWritten); if (status == FT_OK) { if(*lpdwBytesWritten != dwBytesToWrite) return 2; // Can be used for packet retry code ect } else { eprintf("Error: Write Error. Closing.\n"); status = FT_Close(fthandle); // Close device if fatal error return 0; } // Packet Sent return 1; }
int CKMotionIO::Failed() { Mutex->Lock(); m_Connected=false; FT_Close(ftHandle); if (!FailMessageAlreadyShown) ErrorMessageBox("Read Failed - Auto Disconnect"); FailMessageAlreadyShown=true; Mutex->Unlock(); return 0; }
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"); } } }