Hello,
I am trying to access a device at i2c address 0011110 and I would like to use ADL_SDK's ADL_Display_ReadAndWriteI2c() to do so. I can see that it takes in a iAdapterIndex and an ADLI2C typdef struct pointer. I have successfully compiled on of the sample c programs that adjusts the brightness of the display and it seems to work great. I have altered the code slightly and removed parts to try and implement the i2c functionality instead. it compiles with no errors however the i2c function mentioned above returns -3 code which means that incorrect perameters were fed to it. I got the iAdapterIndex from adapterinfo.iAdapterIndex in much the same way as the sample code. so I believe that at least one of the adapterindexes should be correct. Because of this I am leaning toward the idea the the error is in my ADLI2C data structure or the pointer I am passing. I do not know what I have to do to really initialize this structure and if anyone could help it would be great. I am thinking I need to use malloc like in sample code, however another asker claims to have done this but gets an error of -1. This is my code thus far if anyone could help I would much appreciate it. c is not my native language and I have spent months on this and really this is only a small foot step on what I am ultimately trying to do. Getting caught up on these small things is really time consuming and if anyone can help I can finally make some progress. This is what I have written thus far, basically it is slimed down version of sample code that came with the adl_sdl and adapted more to what I'm trying to do.
typedef int(*ADL_MAIN_CONTROL_CREATE)(ADL_MAIN_MALLOC_CALLBACK, int);
typedef int(*ADL_MAIN_CONTROL_DESTROY)();
typedef int(*ADL_ADAPTER_NUMBEROFADAPTERS_GET) (int*);
typedef int(*ADL_ADAPTER_ADAPTERINFO_GET) (LPAdapterInfo, int);
typedef int(*ADL_DISPLAY_WRITEANDREADI2C)( int, ADLI2C *);
//***********************Memory allocation function********************************************
void* __stdcall ADL_Main_Memory_Alloc(int iSize)
{
void* lpBuffer = malloc(iSize);
return lpBuffer;
}
//*************************Optional Memory de-allocation function******************************
void __stdcall ADL_Main_Memory_Free(void** lpBuffer)
{
if (NULL != *lpBuffer)
{
free(*lpBuffer);
*lpBuffer = NULL;
}
}
//*********************************MAIN********************************************************
int main(int c, char* k[], char* s[])
{
HINSTANCE hDLL; // Handle to DL
ADL_MAIN_CONTROL_CREATE ADL_Main_Control_Create;
ADL_MAIN_CONTROL_DESTROY ADL_Main_Control_Destroy;
ADL_ADAPTER_NUMBEROFADAPTERS_GET ADL_Adapter_NumberOfAdapters_Get;
ADL_ADAPTER_ADAPTERINFO_GET ADL_Adapter_AdapterInfo_Get;
ADL_DISPLAY_WRITEANDREADI2C ADL_Display_WriteAndReadI2C;
LPAdapterInfo lpAdapterInfo = NULL;
LPADLDisplayInfo lpAdlDisplayInfo = NULL;
int i;
int iNumberAdapters;
int iAdapterIndex;
int iDisplayIndex;
int iNumDisplays;
//**********************************LOAD THE DLL***********************************************
hDLL = LoadLibrary("atiadlxx.dll");
if (hDLL == NULL)
// A 32 bit calling application on 64 bit OS will fail to LoadLIbrary.
// Try to load the 32 bit library (atiadlxy.dll) instead
hDLL = LoadLibrary("atiadlxy.dll");
if (NULL == hDLL)
{
printf("ADL library not found!\n");
return 0;
}
//********************************************************************************************
ADL_Main_Control_Create = (ADL_MAIN_CONTROL_CREATE)GetProcAddress(hDLL, "ADL_Main_Control_Create");
ADL_Main_Control_Destroy = (ADL_MAIN_CONTROL_DESTROY)GetProcAddress(hDLL, "ADL_Main_Control_Destroy");
ADL_Adapter_NumberOfAdapters_Get = (ADL_ADAPTER_NUMBEROFADAPTERS_GET)GetProcAddress(hDLL, "ADL_Adapter_NumberOfAdapters_Get");
ADL_Adapter_AdapterInfo_Get = (ADL_ADAPTER_ADAPTERINFO_GET)GetProcAddress(hDLL, "ADL_Adapter_AdapterInfo_Get");
ADL_Display_WriteAndReadI2C = (ADL_DISPLAY_WRITEANDREADI2C)GetProcAddress(hDLL, "ADL_Display_WriteAndReadI2C");
//*********************************************Load the DLL functions************************
if(NULL == ADL_Main_Control_Create ||
NULL == ADL_Main_Control_Destroy ||
NULL == ADL_Adapter_NumberOfAdapters_Get ||
NULL == ADL_Adapter_AdapterInfo_Get ||
NULL == ADL_Display_WriteAndReadI2C )
{
printf("ADL's API is missing!\n");
}
//************************************Initialize the ADL*************************************
if (ADL_OK != ADL_Main_Control_Create(ADL_Main_Memory_Alloc, 1))
{
printf("ADL Initialization Error!\n");
return 0;
}
//************************************Find Number of Adapters********************************
if (ADL_OK != ADL_Adapter_NumberOfAdapters_Get(&iNumberAdapters))
{
printf("Cannot get the number of adapters!\n");
return 0;
}
if (0 < iNumberAdapters)
{
lpAdapterInfo = malloc(sizeof(AdapterInfo) * iNumberAdapters);
memset(lpAdapterInfo, '\0', sizeof(AdapterInfo) * iNumberAdapters);
// Get the AdapterInfo structure for all adapters in the system
ADL_Adapter_AdapterInfo_Get(lpAdapterInfo, sizeof(AdapterInfo) * iNumberAdapters);
}
//*************************************Repeat for all adapters*******************************
for (i = 0; i < iNumberAdapters; i++)
{
//************************ here we test the values for iLine cause we dont know what they should be***
ADLI2C *first;
ADLI2C STUPID;
first = &STUPID;
first -> iAddress = 60;
first -> iOffset = 0;
first -> iAction = 1;
//first -> iSpeed = 400;
//first -> iDataSize = 4;
//first -> iSize = 32;
//first -> iLine = 3;
first -> pcData = 256;
printf("%d", sizeof(first -> pcData));
//****************************************************************************************************
iAdapterIndex = lpAdapterInfo.iAdapterIndex;
printf("made it this far %d", i);
if(ADL_OK == ADL_Display_WriteAndReadI2C(iAdapterIndex, first))
{
printf("IT SEEMS TO HAVE WORKED?");
}
}
return 0;
}