コード例 #1
0
BOOL openChannel( FT_HANDLE ftHandle, int nSpeed )
{
  char buf[80];
  unsigned long size;
  unsigned long retLen;
  
  // Set baudrate
  FT_Purge( ftHandle, FT_PURGE_RX );

  sprintf( buf, "S%d\r", nSpeed );
  size = 3;
  if ( !( FT_OK == FT_Write( ftHandle, buf, size, &retLen ) ) ) { 
    printf("Write failed\n");
    return FALSE;
  }
      
  // Open device
  FT_Purge( ftHandle, FT_PURGE_RX );
  strcpy( buf, "O\r" );
  size = 2;
  if ( !( FT_OK == FT_Write( ftHandle, buf, size, &retLen ) ) ) {
    printf("Write failed\n");
    return FALSE;
  }

  return TRUE;
}
コード例 #2
0
ファイル: d2xx.c プロジェクト: GBert/openwrt-misc
void
serial_write_block(unsigned char *ch, int len)
{
#if 1
  while (len--)
    serial_write(*ch++);
  serial_sync ();
#else
  DWORD num;
  if (verbose > 1)
    {
      int i;
      printf("\033[36m[%d]\033[0m", len);
      for (i=0; i<len; i++)
	dw (ch[i]);
    }
  while (len > 32)
    {
      FT_Write (handle, ch, 32, &num);
      ch += 32;
      len -= 32;
      serial_sync ();
    }
  if (len)
    FT_Write (handle, ch, len, &num);
  serial_sync ();
#endif
}
コード例 #3
0
void FTDIDMXDevice::run()
{
	// Write the data to the device
	ULONG bytesWritten;
	unsigned char startCode = 0;

	// Wait for device to clear
	usleep(1000);

	while (m_threadRunning == true)
	{
		// usleep values added by suggestion of Hugh Blemings
		// on qlc-devel mailing list (11/02/09).
		// As I have not run more than one dimmer rack with this
		// plugin I am unable to assertain whether or not this
		// is better or equivilent to previous code therefore
		// I am including it in order for the analysis of the users.
		// At the time of writing LLA is being re-vamped so this
		// plugin will become redundant for all but Windows users.

		// Write data
		FT_SetBreakOn(m_handle);
		usleep(88);
		FT_SetBreakOff(m_handle);
		usleep(8);
		FT_Write(m_handle, &startCode, 1, &bytesWritten);
		FT_Write(m_handle, m_values, 512, &bytesWritten);
		usleep(24000);
	}
}
コード例 #4
0
ファイル: MmcUsbHndlLinux.cpp プロジェクト: RIVeR-Lab/eposcmd
bool CMmcUsbHndlBase::Write(void *pDataBuffer, unsigned int dNumberOfBytesToWrite, unsigned int *pdNumberOfBytesWritten)
{

	if( !AreLibraryFunctionsLoaded() )
    {
		perror("Library not loaded");
        return false;
    }

	FT_STATUS ftStatus = FT_Write(m_Handle, pDataBuffer, dNumberOfBytesToWrite, (DWORD*)pdNumberOfBytesWritten);

	if( ftStatus != FT_OK )
	{
		std::string errormsg = GetFtStatusDescription(ftStatus);
		errormsg += ":FT_Write";
		perror(errormsg.c_str());
	}

	if( *pdNumberOfBytesWritten <= 0 )
	{
		perror("Write processed successfully, but number of bytes written is 0");
		return false;
	}

	return true;
}
コード例 #5
0
ファイル: ft232r_spi.cpp プロジェクト: g-gabber/FTDI_nRF24L01
void FT232R_SPI::ftdi_spi_rw(unsigned char *write, unsigned char *read, int size){

    unsigned char * buffWrite = (unsigned char *)malloc((size+2)*((8*3)+3));
    unsigned char * buffRead = (unsigned char *)malloc((size+2)*((8*3)+3));
    int index = 0;


    state &= ~CSN;
    buffWrite[index++] = state;

    for(int i = 0; i < size; i++){
        index += ftdi_byte_encode(buffWrite+index, write[i]);
    }

    state |= CSN;
    buffWrite[index++] = state;


#ifdef _WIN32
    DWORD written = 0;
    FT_Write(ftHandle,(void*)buffWrite, index, &written);
    written = 0;
    FT_Read(ftHandle, (void*) buffRead, index, &written);
#elif __linux__
    unsigned int written = 0;
    written = ftdi_write_data(ftdi, (unsigned char*)buffWrite, index);
    ftdi_read_data(ftdi, (unsigned char*) buffRead, index);
#endif

    ftdi_spi_decode(buffRead, written, read);

    free(buffWrite);
    free(buffRead);

}
コード例 #6
0
ファイル: presto.c プロジェクト: 01org/CODK-A-Flashpack
static int presto_write(uint8_t *buf, uint32_t size)
{
#if BUILD_PRESTO_FTD2XX == 1
	DWORD ftbytes;
	presto->status = FT_Write(presto->handle, buf, size, &ftbytes);
	if (presto->status != FT_OK) {
		LOG_ERROR("FT_Write returned: %s", ftd2xx_status_string(presto->status));
		return ERROR_JTAG_DEVICE_ERROR;
	}

#elif BUILD_PRESTO_LIBFTDI == 1
	uint32_t ftbytes;
	presto->retval = ftdi_write_data(&presto->ftdic, buf, size);
	if (presto->retval < 0) {
		LOG_ERROR("ftdi_write_data: %s", ftdi_get_error_string(&presto->ftdic));
		return ERROR_JTAG_DEVICE_ERROR;
	}
	ftbytes = presto->retval;
#endif

	if (ftbytes != size) {
		LOG_ERROR("couldn't write the requested number of bytes to PRESTO (%u < %u)",
			(unsigned)ftbytes, (unsigned)size);
		return ERROR_JTAG_DEVICE_ERROR;
	}

	return ERROR_OK;
}
コード例 #7
0
void getSerialNumber( FT_HANDLE ftHandle )
{
  FT_STATUS status;
  char buf[80];
  char c;
  char *p;
  unsigned long nBytesWritten;
  unsigned long eventStatus;
  unsigned long nRxCnt;// Number of characters in receive queue
  unsigned long nTxCnt;// Number of characters in transmit queue

  memset( buf, 0, sizeof( buf ) );
  printf("Get serial number.\n");
  printf("==================\n");

  FT_Purge( ftHandle, FT_PURGE_RX | FT_PURGE_TX );

  sprintf( buf, "N\r" );
  if ( FT_OK != ( status = FT_Write( ftHandle, buf, strlen( buf ), &nBytesWritten ) ) ) {
    printf("Error: Failed to write command. return code = %d\n", status );
    return;
  }
  
  // Check if there is something to receive
  while ( 1 ){

    if ( FT_OK == FT_GetStatus( ftHandle, &nRxCnt, &nTxCnt, &eventStatus ) ) {
      
      // If there are characters to receive
      if ( nRxCnt ) {
	
	if ( FT_OK != ( status = FT_Read( ftHandle, buf, nRxCnt, &nBytesWritten ) ) ) {
	  printf("Error: Failed to read data. return code = %d\n", status );
	  return;
	}
	
	p = buf;
	while ( *p ) {
	  if ( 0x0d == *p ) {
	    *p = 0;
	    break;
	  }
	  p++;
	}
      
	printf( "Serial = %s \n", buf  );
	break;
	
      }
      
    }
    else {
      printf("Error: Failed to get status. return code = %d\n", status );
      return;
    }

  }
  
}
コード例 #8
0
ファイル: libpm600x.c プロジェクト: bitwigglers/lib-pm600x
static int pm_write(struct pm_context *pm, char *buffer, unsigned int count)
{
	FT_STATUS ftstat;
	DWORD bytes_written;

	ftstat = FT_Write(pm->handle, buffer, count, &bytes_written);
	return ftstat == FT_OK ? bytes_written : -1;
}
コード例 #9
0
int nifalcon_write(falcon_device* dev, unsigned char* str, unsigned int size)
{
	unsigned long bytes_written;

	if(!dev->is_open) nifalcon_error_return(NIFALCON_DEVICE_NOT_FOUND_ERROR, "tried to write to an unopened device");
	if((dev->falcon_status_code = FT_Write(dev->falcon, str, size, &bytes_written)) != FT_OK) return -dev->falcon_status_code;
	return bytes_written;
}
コード例 #10
0
ファイル: Example1.cpp プロジェクト: jjturn/lb-boards
void WriteBits(UCHAR Value) {
	DWORD BytesWritten;
	FT_Status = FT_Write(FT_Handle, &Value, 1, &BytesWritten);
	if (FT_Status != FT_OK) {
		printf("\nFT_Write error (%d), Cable disconnected?\n", FT_Status);
		Idle(2000);		// Display error message for 2 seconds
		Quit();
		}
	}
コード例 #11
0
ファイル: D2xxSerial.cpp プロジェクト: imclab/MLF-Forest
int D2xxSerial::write(unsigned char *buffer, int length) {
	DWORD outCount = 0;
	FT_STATUS err = FT_Write (handle, buffer, length, &outCount);
	if (err != FT_OK) {
		printf("Error writing: %s\n", getError(err));
		return 0;
	}
	return outCount;
}
コード例 #12
0
ファイル: ft245r.c プロジェクト: arnonh/myelin-matrix-display
static int ft245r_send(PROGRAMMER * pgm, char * buf, size_t len)
{
  FT_STATUS r;
  DWORD rlen;
  r = FT_Write(handle, buf, len, &rlen);
  if (r == FT_OK) return 0;
  if (len != rlen) return -1;
  return -1;
}
コード例 #13
0
ファイル: ftd2xx-interface.cpp プロジェクト: enbyted/qlcplus
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);
}
コード例 #14
0
void setPin(byte pin, byte value) {
	static DWORD b = 0;
	switch (pin) {
		case MISO_8051: ftdi_pins.miso = value; break;
		case MOSI_8051: ftdi_pins.mosi = value; break;
		case CLK_8051: ftdi_pins.clk = value; break;
		case RST_8051: ftdi_pins.rst  = value; break;
	}
	FT_Write(ftdi_chip, &ftdi_pins, 1, &b);
}
コード例 #15
0
ファイル: io.cpp プロジェクト: saiand83/copynesw
BOOL	WriteByteEx (BYTE data, int timeout, BOOL warn)
{
	if (ParPort == -1)
	{
		DWORD BytesWritten = 0;
		FT_SetTimeouts(ftHandleA,10000,0);
		TxBuffer[0] = data;
		ftStatus = FT_Write(ftHandleA,TxBuffer,1,&BytesWritten);
		if (ftStatus == FT_OK)
		{
			if (BytesWritten == 1)
			{
				// FT_Read OK
				return TRUE;
			}
			else
			{
				// FT_Write Timeout
				if (warn)
					MessageBox(topHWnd, "USB Error: Write Timeout", "WriteByteEx", MB_OK | MB_ICONERROR);
				return FALSE;
			}
		}
		else
		{
			// FT_Write Failed
			StatusText("FT STATUS = %i", ftStatus);
			MessageBox(topHWnd, "USB Error: Write Failed", "WriteByteEx", MB_OK | MB_ICONERROR);
			return FALSE;
		}
	}
	else
	{
		time_t starttime = time(NULL);
		BYTE b;
		shadow &= 0xDF;
		pwControl(shadow);	// set port to output mode
		pwData(data);		// output data
		shadow ^= 0x01;
		pwControl(shadow);	// signal byte sent
		b = prStatus();		// wait for ACK
		while (!((b ^ c) & 0x10))
		{
			b = prStatus();
			if (time(NULL) > starttime + (time_t)timeout)
			{
				if (warn)
					MessageBox(topHWnd, "Timeout on data transfer!", "WriteByte", MB_OK | MB_ICONERROR);
				return FALSE;
			}
		}
		c = b;
		return TRUE;
	}
}
コード例 #16
0
ファイル: MarmoteControl.cpp プロジェクト: kitnic/marmote
void sendMsg(FT_HANDLE ftHandle, MsgClass_t msg_class, MsgId_t msg_id, uint8_t* payload, uint16_t len)
{
	FT_STATUS ftStatus;
	DWORD bytesWritten;

	PktHdr_t* pkt;
	uint8_t* chk_a_ptr; // pointer to checksum A
	uint8_t* chk_itr; // iterator for calculating checksum
	uint8_t i;	
	uint8_t tx_buf[256];

	len = (len > 128) ? 128 : len;

	pkt = (PktHdr_t*)tx_buf;

	pkt->sync_1 = SYNC_CHAR_1;
	pkt->sync_2 = SYNC_CHAR_2;
	pkt->msg_class = msg_class;
	pkt->msg_id = msg_id;
	pkt->len = len;

	memcpy(&(pkt->payload), payload, len);

	chk_a_ptr = pkt->payload + pkt->len;
	chk_itr = &(pkt->msg_class);

	// Checksum calculation (over msg_class, msg_id, len and payload)
	*chk_a_ptr = 0;
	*(chk_a_ptr+1) = 0;
	for (i = 0; i < 4 + pkt->len; i++) // TODO: remove 4
	{
		*(chk_a_ptr) += *(chk_itr+i);
		*(chk_a_ptr+1) += *(chk_a_ptr);
	}


	ftStatus = FT_Write(ftHandle, (uint8_t*)pkt, sizeof(PktHdr_t) + len + PKT_CHK_LEN, &bytesWritten);
	if (ftStatus == FT_OK)
	{
		/*
		printf("Sent packet (%d bytes):\n", bytesWritten);
		for (i = 0; i < sizeof(PktHdr_t) + len + PKT_CHK_LENGTH; i++)
		{
			printf("%02X ", *((uint8_t*)pkt + i));
		}
		printf("\n");
		printPkt(pkt);
		*/
	}
	else
	{
		printf("sendMsg(): FT_Write failed\n");
	}
}
コード例 #17
0
NDI_DECL1 unsigned int NDI_DECL2 LinkWrite( void *pBuff, unsigned int uBytes )
{
	DWORD	dwWritten;

	if( s_hndl )
	{
		if( FT_Write( s_hndl, pBuff, uBytes, &dwWritten ) == FT_OK )
			return dwWritten;
	} /* if */
	return 0;
}
コード例 #18
0
ファイル: d2xx.c プロジェクト: GBert/openwrt-misc
void
serial_write (unsigned char ch)
{
  DWORD num;

  if (verbose > 1)
    dw (ch);
  FT_Write (handle, &ch, 1, &num);
  serial_sync ();
  usleep(100);
}
コード例 #19
0
int dxl_hal_tx( unsigned char *pPacket, int numPacket )
{
	FT_STATUS ft_status;
	DWORD dwNumToWrite = (DWORD)numPacket;
	DWORD dwNumWritten;

	ft_status = FT_Write( ghFt_Handle, (LPVOID)pPacket, dwNumToWrite, &dwNumWritten );
	if( ft_status == FT_IO_ERROR )
		return 0;

	return (int)dwNumWritten;
}
コード例 #20
0
int _tmain(int argc, _TCHAR* argv[])
{
	if( ftdi_init() )
	{
		printf("Cannot init FTDI chip\n");
		return -1;
	}

	byOutputBuffer[0]=0x55;
	FT_Write(ftHandle, byOutputBuffer, 1, &dwNumBytesSent);
	byOutputBuffer[0]=0x33;
	FT_Write(ftHandle, byOutputBuffer, 1, &dwNumBytesSent);
	byOutputBuffer[0]=0xaa;
	FT_Write(ftHandle, byOutputBuffer, 1, &dwNumBytesSent);
	byOutputBuffer[0]=0x69;
	FT_Write(ftHandle, byOutputBuffer, 1, &dwNumBytesSent);

	#define BLOCK_LEN (4096*16)
	unsigned char sbuf[BLOCK_LEN];
	for(int i=0; i<BLOCK_LEN; i++)
		sbuf[i] = (i & 0xff);

		DWORD ticks = GetTickCount();
		int sz = 0;
		while(1)
		{
			FT_Write(ftHandle,sbuf,BLOCK_LEN,&dwNumBytesSent);
			sz += BLOCK_LEN;
			DWORD t = GetTickCount();
			if( (t-ticks) >= 1000)
			{
				//one second lapsed
				printf("sent %d bytes/sec\n",sz);
				ticks = t;
				sz = 0;
			}
		}

	return 0;
}
コード例 #21
0
ファイル: main.c プロジェクト: 0x6a77/JD2XX
/*
	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);
}
コード例 #22
0
ファイル: presto.c プロジェクト: 01org/CODK-A-Flashpack
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;
}
コード例 #23
0
ファイル: libftdimut.c プロジェクト: harshadura/Lancer-Scan
unsigned char ftdimut_getData(unsigned char request) {
  unsigned int bytesRead, bytesWrote;
  unsigned char buf[2];
  FT_Write(ftHandle, &request, 1, &bytesWrote);
  if(bytesWrote != 1) {
    return 0;
  }
  FT_Read(ftHandle, buf, 2, &bytesRead);
  if(bytesRead != 2) {
    return 0;
  }

  return buf[1];
}
コード例 #24
0
ファイル: ftdimodule.cpp プロジェクト: gen1izh/cpp
/**
 * Запись в порт Б микросхемы 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 );
     }
  }
}
コード例 #25
0
ファイル: APSRack.cpp プロジェクト: eccstartup/Qlab
int APSRack::raw_read(int deviceID, FPGASELECT fpga) {
	DWORD bytesRead, bytesWritten;
	UCHAR dataBuffer[2];
	USHORT transferSize = 1;
	int Command = APS_FPGA_IO;

	//Send the read command byte
	UCHAR commandPacket = 0x80 | Command | (fpga<<2) | transferSize;
    FT_Write(APSs_[deviceID].handle_, &commandPacket, 1, &bytesWritten);

	//Look for the data
	FT_Read(APSs_[deviceID].handle_, dataBuffer, 2, &bytesRead);
	FILE_LOG(logDEBUG2) << "Read " << bytesRead << " bytes with value" << myhex << ((dataBuffer[0] << 8) | dataBuffer[1]);
	return int((dataBuffer[0] << 8) | dataBuffer[1]);
}
コード例 #26
0
ファイル: usb.cpp プロジェクト: meierb/psi46test
void CUSB::Flush()
{
	DWORD bytesWritten;
	DWORD bytesToWrite = m_posW;
	m_posW = 0;

	if (!isUSB_open) throw RpcError(RpcError::WRITE_ERROR);

	if (!bytesToWrite) return;

	ftStatus = FT_Write(ftHandle, m_bufferW, bytesToWrite, &bytesWritten);

	if (ftStatus != FT_OK) throw RpcError(RpcError::WRITE_ERROR);
	if (bytesWritten != bytesToWrite) { ftStatus = FT_IO_ERROR; throw RpcError(RpcError::WRITE_ERROR); }
}
コード例 #27
0
BOOL sendFrame( FT_HANDLE ftHandle, CANMsg *pmsg )
{
  int i; 
  char txbuf[80];
  unsigned long size;
  unsigned long retLen;

  if ( pmsg->flags & CANMSG_EXTENDED ) {
    if ( pmsg->flags & CANMSG_RTR ) {
      sprintf( txbuf, "R%08.8lX%i", pmsg->id, pmsg->len );
      pmsg->len = 0; 
    }
    else {
      sprintf( txbuf, "T%08.8lX%i", pmsg->id, pmsg->len );
    }
  }
  else {
    if ( pmsg->flags & CANMSG_RTR ) {
      sprintf( txbuf, "r%03.3lX%i", pmsg->id, pmsg->len );
      pmsg->len = 0; // Just dlc no data for RTR
    }
    else {
      sprintf( txbuf, "t%03.3lX%i", pmsg->id, pmsg->len );
    }
  }

  if ( pmsg->len ) {
    char hex[5];
    
    for ( i= 0; i< pmsg->len; i++ ) {
      sprintf( hex, "%02.2X", pmsg->data[i] );
      strcat( txbuf, hex );
    }
  }

  // Add CR
  strcat( txbuf, "\r" );

  size = strlen( txbuf );

  // Transmit fram
  if ( !( FT_OK == FT_Write( ftHandle, txbuf, size, &retLen ) ) ) { 
    return FALSE;
  }
  

  return TRUE;
}
コード例 #28
0
int motor_spin(FT_HANDLE ftHandleDYNA, int motorNum, int speed)
{

    unsigned char InstructionPacket[160] = {0};
    // unsigned char StatusPacket[70]={0};
    FT_STATUS ft_status;

    //make the instruction packet
    InstructionPacket[0] = 0xff;
    InstructionPacket[1] = 0xff;
    InstructionPacket[ID] = (unsigned char)motorNum;
    InstructionPacket[LENGTH] = 5; //=parameter number +2
    InstructionPacket[INSTRUCTION] = INST_WRITE;
    InstructionPacket[PARAMETER] = (unsigned char) 32; //address for free spin
    InstructionPacket[PARAMETER+1] = (unsigned char)get_lowbyte(speed);
    InstructionPacket[PARAMETER+2] = (unsigned char)get_highbyte(speed);

    unsigned char checksum = 0;
    for(unsigned char i=0; i<(InstructionPacket[LENGTH]+1); i++ )
        checksum += InstructionPacket[i+2];
    InstructionPacket[InstructionPacket[LENGTH]+3] = ~checksum;

    /*    qDebug()<<"Packet:";
        qDebug()<<InstructionPacket[0]<<" "<<InstructionPacket[1]<<" "
                <<InstructionPacket[ID] <<" "<<InstructionPacket[LENGTH] <<" "
                <<InstructionPacket[INSTRUCTION] <<" " <<InstructionPacket[PARAMETER]<<" "
                <<InstructionPacket[PARAMETER+1] <<" "<< InstructionPacket[PARAMETER+2];
    */
    //send the packet
    unsigned char *pPacket = InstructionPacket;
    int numPacket = 9; //length plus 4
    DWORD dwNumToWrite = (DWORD)numPacket;
    DWORD dwNumWritten;

    ft_status = FT_Write(ftHandleDYNA, (LPVOID)pPacket, dwNumToWrite, &dwNumWritten );
    if( ft_status == FT_IO_ERROR )
    {
        qDebug() << "\n\nError sending packet to motor!";
        return 0;
    }
    if(numPacket != dwNumWritten)
    {
        qDebug() << "\n\nAll Bytes were not written to device!";
        return 0;
    }

    return 1;
}
コード例 #29
0
ファイル: ublast_access_ftd2xx.c プロジェクト: Bot007/openOCD
static int ublast_ftd2xx_write(struct ublast_lowlevel *low, uint8_t *buf, int size,
			      uint32_t *bytes_written)
{
	FT_STATUS status;
	DWORD dw_bytes_written;
	FT_HANDLE *ftdih = ublast_getftdih(low);

	status = FT_Write(*ftdih, buf, size, &dw_bytes_written);
	if (status != FT_OK) {
		*bytes_written = dw_bytes_written;
		LOG_ERROR("FT_Write returned: %s", ftd2xx_status_string(status));
		return ERROR_JTAG_DEVICE_ERROR;
	}
	*bytes_written = dw_bytes_written;
	return ERROR_OK;
}
コード例 #30
0
ファイル: serial_ftdi.cpp プロジェクト: new299/onyxloader
// Write up to the specified number of bytes, return bytes actually written
u32 ser_write( int id, const u8 *src, u32 size )
{
  u32 res;
  FT_STATUS	ftStatus;
  DWORD dwBytesWritten;
  
  FT_SetTimeouts(ftHandle[id], ser_timeout, ser_timeout);

  if((ftStatus = FT_Write(ftHandle[id], (char *) src, size, &dwBytesWritten)) != FT_OK) {
    printf("Error FT_Write(%d)\n", ftStatus);
  }
  if( ser_dbg )
    printf("  - ser_wrt  [%d | %02x] *\n", dwBytesWritten, *src & 0xFF);

  return (u32) dwBytesWritten;
}