FTDI Community

General Category => Discussion - Software => Topic started by: tklosa on October 05, 2020, 04:01:09 PM

Title: USER_CONTEXT and PUSER_CONTEXT types missing for use of callback notification
Post by: tklosa on October 05, 2020, 04:01:09 PM
Hi all,

I'd like to use the callback notification provided by the D3xx driver. According to the AN_379 programmers guide example starting at page 61, there is a definition:

Code: [Select]
USER_CONTEXT UserContext = {0};
on page 67. This seems to be a structure containing the ftHandle and other fields since later on the page there is:

Code: [Select]
UserContext.m_ftHandle = ftHandle;
ftStatus = FT_SetNotificationCallback(ftHandle, NotificationCallback, &UserContext);

Further down on page 68 a pointer type of it PUSER_CONTEXT is used to cast the void pointer from the callback function and access the fields:

Code: [Select]
PUSER_CONTEXT pUserContext = (PUSER_CONTEXT)pvCallbackContext;
ULONG ulBytesTransferred = 0;
DEBUG(_T("\n\tReading %d bytes!\n"), pInfo->ulRecvNotificationLength);
FT_STATUS ftStatus = FT_ReadPipe( pUserContext->m_ftHandle, pInfo->ucEndpointNo, &pUserContext->m_ucRecvBuffer[pUserContext->m_ulCurrentRecvData], pInfo->ulRecvNotificationLength, &ulBytesTransferred, NULL );

The field name m_ftHandle sugests that this context structure is an FTDI defined type but I can not find this definition eg. in  FTD3XX.h or so. Anybody here who has seen this type beeing defined somewhere?
Title: Re: USER_CONTEXT and PUSER_CONTEXT types missing for use of callback notification
Post by: FTDI Community on October 07, 2020, 04:33:16 PM
Hello,

You are already in contact with our support team on this issue via email.
Please post any resolution here to help other customers.

Best Regards,
FTDI Community
Title: Re: USER_CONTEXT and PUSER_CONTEXT types missing for use of callback notification
Post by: tklosa on October 08, 2020, 01:38:43 PM
Well, yes, thanks for the support reply. I'd like to post it herewith:

> The field USER_CONTEXT is purely application-defined and the customer is free to define as per the application requirement.
>
> In our example, we needed the context to ftHandle hence we have a pointer to ftHandle within the context.
> However this does not mean that the structure is ftdi defined.
 
So, to me it answers the question so far that there are no other fields from this structure used beside the visible names. So, I can define the structure based on the missing names from the example.

However, I found another example for the callback notification in the package FT600APIUsageDemoApp_v1.3.0.4.
The source FTD3XX_NotificationData.cpp has a definition for the context using a different approach:

Code: [Select]
typedef struct _USER_CONTEXT
{
    CRITICAL_SECTION                    m_hCriticalSection;
    HANDLE                              m_hEventDataAvailable;
    FT_NOTIFICATION_CALLBACK_INFO_DATA  m_tNotificationData;

} USER_CONTEXT, *PUSER_CONTEXT;

May be it works best to create the own software based on the example in  FT600APIUsageDemoApp_v1.3.0.4 instead og the App note code.