I'm trying to develop a program in c++ that allows reading and setting the logical value of the input and output of the adam 6050.
A practical example: I want the code to read the logical value of DI4 and if it is 1, it sets the logical value of DO4 to 1.
What library do I need to include?
What code do I have to write?
I tried to compile this example code from Adam .net class library samples:
// Adam50XXDIO.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include "ADSDIO.h"
#include <string.h>
//////////////////////////////////////////////
//Take ADAM-5056 for example
//Slot : 0
//Reverse channel 0 value
USHORT iSlot = 0;
USHORT iChannel = 0;
//////////////////////////////////////////////
int ADV_SUCCESS = 0;
LONG myprocHandle;
int OpenLib()
{
myprocHandle = NULL;
//OpenDeviceLib
if(ADAMDrvOpen(&myprocHandle) == ADV_SUCCESS)
return ADV_SUCCESS;
else
return -99;
}
void CloseLib()
{
//Close device library
if(myprocHandle!=NULL)
ADAMDrvClose(&myprocHandle);
}
int main(int argc, char* argv[])
{
int iRet;
ULONG dVal;
bool bValue = false;
bool setValue = true;
printf("/*** Adam50XXDIO Sample ***/ \n");
iRet = OpenLib();
if(iRet == ADV_SUCCESS)
{
//Get dio module values
if((DI_GetValues(myprocHandle, iSlot, &dVal)) == ADV_SUCCESS)
{
printf("GetValues: %lx\n", dVal);
bValue = ((dVal & (0x00000001<<iChannel)) > 0);
if(bValue)
{
printf("Ch%d:True\n", iChannel);
setValue = false;
}
else
{
printf("Ch%d:False\n", iChannel);
setValue = true;
}
//Set DO value
if((DO_SetValue(myprocHandle, iSlot, iChannel, setValue) == ADV_SUCCESS))
{
printf("SetValue done.\n", dVal);
//Check value
if((DI_GetValues(myprocHandle, iSlot, &dVal)) == ADV_SUCCESS)
{
printf("GetValues: %lx\n", dVal);
bValue = ((dVal & (0x00000001<<iChannel)) > 0);
if(bValue)
printf("Ch%d:True\n", iChannel);
else
printf("Ch%d:False\n", iChannel);
}
}
else
printf("SetValue() failed.");
}
else
printf("GetValues() failed.");
}
else
printf("OpenLib(%d) failed.\n", iRet);
CloseLib();
printf("/*** END ***/ \n");
getchar();
return 0;
}
But I get this message:
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\bin\ld.exe
cannot open output file C:\Program Files (x86)\Advantech\AdamApax.NET Class Library\Sample Code\ADAM\Win32\CPlusPlus\ADAM-PAC-Sample\Adam50XX_DIO\Adam50XX_DIO.exe: Permission denied
Then I changed the path, and now pop these messages:
C:\Users\JOOLOP~1\AppData\Local\Temp\cc5WBolj.o Adam50XX_DIO.cpp:(.text+0x18): undefined reference to `ADAMDrvOpen'
C:\Users\JOOLOP~1\AppData\Local\Temp\cc5WBolj.o Adam50XX_DIO.cpp:(.text+0x51): undefined reference to `ADAMDrvClose'
C:\Users\JOOLOP~1\AppData\Local\Temp\cc5WBolj.o Adam50XX_DIO.cpp:(.text+0xb3): undefined reference to `DI_GetValues'
C:\Users\JOOLOP~1\AppData\Local\Temp\cc5WBolj.o Adam50XX_DIO.cpp:(.text+0x17a): undefined reference to `DO_SetValue'
C:\Users\JOOLOP~1\AppData\Local\Temp\cc5WBolj.o Adam50XX_DIO.cpp:(.text+0x1c5): undefined reference to `DI_GetValues'
C:\practice\Adam50XX_DIO\collect2.exe [Error] ld returned 1 exit status
What I can do now?