Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

Help with sending data using 245 FIFO Mode with vb.net wrapper

I am using the VB.NET wrapper for FTD2XX.dll and I am attempting to send bytes in Sync FIFO mode to a Morph-IC-II. I was able to find/program/setup the device o.k. but I am unsure exactly how to send the data/ I know the FPGA should set RD# low when it is ready to receive data, but I do not see any examples of how to check this. I have code written to read a file (small buffer) and I am writing the data to another file rather than to the device. I have the FT_Write_Bytes remarked out because I know there is more I need to do to get it to work correctly without locking up. The FPGA is already set up to receive.

Private Sub Button_Send_Clicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Send.Click
        Dim StartAt As Int64 = 0
        Dim NumBytesToCopy As Int64 
        Dim TotalBytesCopied As Int64 = 0
        Dim bytesRead As Integer
        Dim buffer(360) As Byte
        Dim infoReader As System.IO.FileInfo
        Using inFile As New System.IO.FileStream(StreamFileName, IO.FileMode.Open, IO.FileAccess.Read)
            infoReader = My.Computer.FileSystem.GetFileInfo(StreamFileName)
            NumBytesToCopy = infoReader.Length
            inFile.Seek(StartAt, IO.SeekOrigin.Begin)
            Using outFile As New System.IO.FileStream("test2.txt", IO.FileMode.Create, IO.FileAccess.Write)
                Do
                    If NumBytesToCopy - TotalBytesCopied < buffer.Length Then
                        ReDim buffer(NumBytesToCopy - TotalBytesCopied)
                    End If
                    bytesRead = inFile.Read(buffer, 0, buffer.Length)
                    If bytesRead > 0 Then
                        'FT_Status = FT_Write_Bytes(FT_Handle, buffer(0), bytesRead, BytesWritten)
                        outFile.Write(buffer, 0, bytesRead)
                        TotalBytesCopied = TotalBytesCopied + bytesRead
                    End If
                Loop While bytesRead > 0 AndAlso TotalBytesCopied < NumBytesToCopy AndAlso CancelSend = False
            End Using
        End Using
        If FT_Status <> FT_OK Then
            CommLostError("Write Failed")
            Exit Sub
        End If
        If (DeviceInit = True) Then
            FT_Status = FT_Close(FT_Handle)
            If FT_Status = FT_OK Then
                TB_Status.Text = "Closed"
            End If
        End If
        Close()
    End Sub
No RepliesBe the first to reply