Event using FTD2XX_NET.dll

ftdiuart

I am using a FT232RL chip with FTD2XX_NET.dll
I've made a program which writes and reads data to/from AVR atmega32 mcu.
First writes data, then reads data as answer.

Now, i want to make an event which indicated me if there's available unreaded data, only when AVR sends data to FTDI buffer and ONLY then. Whithout forcing my program to making loops for checking available data.
For my purpose, i want to do the mcu to sends data only when he wants, and the PC must to knows when there's new data in FTDI buffer's chip

Best Answer

Well, first off, from the PC side, it is impossible to know when the AVR sends data to the FTDI chip, you only can know when the FTDI sends its data to the PC. I'm going to assume that is what you meant.

I don't remember what all functions are in the .NET wrapper for the D2XX interface, but in the raw ftd2xx.dll there is a function FT_SetEventNotification which will do what you want. I'm sure it's exposed in the .NET wrapper somehow or another.

Anyways you create an EventWaitHandle, pass it to that function, and as long as your device is opened, the FTDI driver will set it as signaled when a character arrives. Your program, or your reading loop, waits on that handle, then when a character arrives, you read whats in the buffer and parse away.

Keep in mind, you are still going to have to loop over and over while reading data, but what the event signaling is mostly good for is taking it easy on CPU usage.