FT_Read fails, UNLESS reading byte-by-byte where every FT_Read is followed
by FT_Purge
PROBLEM: Micro-controller is transmitting 10 bytes(ASCII
A,B,C,D,E,F,G,H,I,J) in for-loop under debugger control. Windows
application (C++/CLI Code abstracted below) is supposed to receive these
bytes.
Refer the two different FT_Read attempts in BOLD-text.
Case #1: Executing without debugger-stepping, both FT_Read attempts
receive first byte correctly as A but successive bytes received as junk.
Though FT_Read returns only when 10th byte is transmitted from
micro-controller. Post that dwhandled holds 0xa suggesting success in
reading 10 bytes
Case #2: Executing For-loop to execute second FT_Read followed by Purge,
under debugger stepping to receive byte-by-byte where micro-controller
also transmits byte-by-byte under respective debugger stepping. Array
RxMessage receives all 10 bytes correctly as A,B,C,D,E,F,G,H,I,J
private:
/// Required designer variable.
PVOID fth;
BOOL fSuccess, fthsuccess;
array<wchar_t> ^ TxMessage;
array<unsigned char> ^ RxMessage;
Form1(void) //Constructor
{
fthsuccess = false;
InitializeComponent();
TxMessage = gcnew array<wchar_t> (12);
RxMessage = gcnew array<unsigned char> (12);
}
/*PS. All the FT_xxxx calls below are tested for fsuccess before
proceeding ahead */
FT_Open(0, ppfthandle);
FT_SetBaudRate(*ppfthandle, 9600);
unsigned char LatencyTimer;
FT_SetLatencyTimer(*ppfthandle, 2);
FT_GetLatencyTimer(*ppfthandle, &LatencyTimer);
FT_SetDataCharacteristics(*ppfthandle, FT_BITS_8, FT_STOP_BITS_1,
FT_PARITY_NONE);
res = FT_SetTimeouts(*ppfthandle, 10000/*read*/, 1000/*write*/);
pin_ptr<FT_HANDLE> ppfthandle = &fth;
pin_ptr<unsigned char> ppRx = &RxMessage[0];
fSuccess = FT_Read(*ppfthandle,ppRx,10,&dwhandled);//reading 10 bytes
in one go
for(int i=0;i<10;i++)//reading byte-by-byte in debug steps
{
fSuccess = FT_Read(*ppfthandle,&ppRx[i],1,&dwhandled);
/*in absence of Purge below, alternate characters are read as 0xFF
ultimately workaround would be needed to avoid Purging of real
time RxData at runtime
*/
FT_Purge(*ppfthandle, FT_PURGE_RX | FT_PURGE_TX);
}
No comments:
Post a Comment