I was going through the example code on FTDI's website. After opening the device and setting the flow control to be RTS/CTS they send and receive data in the following manner:
' Set RTS
FT_Status = FT_SetRts(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set DTR
FT_Status = FT_SetDtr(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Write string data to device
FT_Status = FT_Write_String(FT_Handle, TextBox4.Text, Len(TextBox4.Text), BytesWritten)
If FT_Status <> FT_OK Then
Exit Sub
End If
Sleep(100)
' Get number of bytes waiting to be read
FT_Status = FT_GetQueueStatus(FT_Handle, FT_RxQ_Bytes)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Read number of bytes waiting
TempStringData = Space(FT_RxQ_Bytes + 1)
FT_Status = FT_Read_String(FT_Handle, TempStringData, FT_RxQ_Bytes, BytesRead)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Close device
FT_Status = FT_Close(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
Basically they set the RTS, DTR, then write data to the device.
Is this correct? If I was sending multiple times to the device, do I need to clear the RTS each time? and then set it high again? or do I just set it high each time I send new data? Why are they setting DTR if the flow control is defined as RTS/CTS?
As far as best practices go, is this the best way to read and write?