01-27-2016, 05:04 PM
This should help you with the transfers. This is code I use for reading and writing data to the USB port:
Note: Visual Basic treats memory as an array. So, RawBuffer(RawOffset) is the same thing as RawBuffer+RawOffset if you were dealing with memory directly.
Code:
' This routine gets data from the SCP USB port and stores "ReadLength" number of bytes starting
' at RawBuffer(RawOffset).
'
' RawBuffer = BYTE buffer
' RawOffset = LONG offset into buffer
' ReadLength = length of data to transfer
'
' lngTotalBytesRead > actual number of bytes transferred
' ftStatus > completion status
Public Sub GetFIFOData()
flTimedout = False ' clear timeout
flFatalError = False ' clear fatal error
lngTotalBytesRead = 0 ' clear total number of bytes
Do
lngBytesRead = 0 ' reset number of bytes read so far
ftStatus = FT_Read_Bytes(lngHandle, RawBuffer(RawOffset), ReadLength, lngBytesRead) ' get bytes from USB port
If (ftStatus = FT_OK) Or (ftStatus = FT_IO_ERROR) Then ' if return status is good or there is a FTDI I/O error
If lngBytesRead > 0 Then ' then check to see if length so far is > 0 and if so
lngTotalBytesRead = lngTotalBytesRead + lngBytesRead ' add length so far to total
Else
ftStatus = FT_ERROR ' otherwise, set return code to error
flTimedout = True ' and set timeout error
End If
Else
ftStatus = FT_ERROR ' if length so far is 0, then set return code to error
flFatalError = True ' and set fatal error
End If
Loop Until (lngTotalBytesRead = ReadLength) Or (flTimedout = True) Or (flFatalError = True) ' loop until all bytes read, timeout, or fatal error occurs
End Sub
' This routine sends "WriteLength" number of bytes to the SCP USB port starting at RawBuffer(RawOffset).
'
' RawBuffer = BYTE buffer
' RawOffset = LONG offset into buffer
' WriteLength = length of data to transfer
'
' lngTotalBytesWritten > actual number of bytes transferred
' ftStatus > completion status
Public Sub PutFIFOData()
ftStatus = FT_Write_Bytes(lngHandle, RawBuffer(RawOffset), WriteLength, lngBytesWritten)
End Sub
Note: Visual Basic treats memory as an array. So, RawBuffer(RawOffset) is the same thing as RawBuffer+RawOffset if you were dealing with memory directly.