Sending data from RAM to USB
#20
This should help you with the transfers.  This is code I use for reading and writing data to the USB port:

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.
Reply


Messages In This Thread
Sending data from RAM to USB - by dfstudios - 01-18-2016, 02:41 PM
RE: Sending data from RAM to USB - by admin - 01-18-2016, 03:04 PM
RE: Sending data from RAM to USB - by dfstudios - 01-18-2016, 04:18 PM
RE: Sending data from RAM to USB - by admin - 01-18-2016, 09:54 PM
RE: Sending data from RAM to USB - by dfstudios - 01-19-2016, 02:31 PM
RE: Sending data from RAM to USB - by admin - 01-19-2016, 08:32 PM
RE: Sending data from RAM to USB - by dfstudios - 01-27-2016, 01:59 PM
RE: Sending data from RAM to USB - by admin - 01-27-2016, 02:45 PM
RE: Sending data from RAM to USB - by dfstudios - 01-27-2016, 03:23 PM
RE: Sending data from RAM to USB - by admin - 01-27-2016, 04:30 PM
RE: Sending data from RAM to USB - by dfstudios - 01-27-2016, 04:36 PM
RE: Sending data from RAM to USB - by dfstudios - 01-27-2016, 04:31 PM
RE: Sending data from RAM to USB - by admin - 01-27-2016, 04:35 PM
RE: Sending data from RAM to USB - by dfstudios - 01-27-2016, 04:47 PM
RE: Sending data from RAM to USB - by admin - 01-27-2016, 04:41 PM
RE: Sending data from RAM to USB - by dfstudios - 01-27-2016, 04:50 PM
RE: Sending data from RAM to USB - by admin - 01-27-2016, 04:44 PM
RE: Sending data from RAM to USB - by dfstudios - 01-27-2016, 04:52 PM
RE: Sending data from RAM to USB - by admin - 01-27-2016, 05:02 PM
RE: Sending data from RAM to USB - by admin - 01-27-2016, 05:04 PM
RE: Sending data from RAM to USB - by dfstudios - 01-27-2016, 05:36 PM



Users browsing this thread: 1 Guest(s)