The following example shows how to enable/disable and set GPIO pin parameters, such as direction, output value and read GPIO pin value, when its direction set to input. You can find the complete example in the “..\Program Files\Diolan\DLN\examples\c_cpp\examples\simple
” folder after DLN setup package installation.
#include "..\..\..\common\dln_generic.h" #include "..\..\..\common\dln_gpio.h" #pragma comment(lib, "..\\..\\..\\bin\\dln.lib") int _tmain(int argc, _TCHAR* argv[]) { // Open device HDLN device; DlnOpenUsbDevice(&device); // Configure pin 0 to input with pullup DlnGpioPinPullupEnable(device, 0); DlnGpioPinSetDirection(device, 0, 0); DlnGpioPinEnable(device, 0); // Configure pin 1 to output DlnGpioPinSetDirection(device, 1, 1); DlnGpioPinEnable(device, 1); // Read pin 0 and set its iverted value on pin 1 uint8_t value; DlnGpioPinGetVal(device, 0, &value); DlnGpioPinSetOutVal(device, 1, value ^ 1); // Disable buttons DlnGpioPinDisable(device, 0); DlnGpioPinDisable(device, 0); // Close device DlnCloseHandle(device); return 0; }
Line 1:#include "..\..\..\common\dln_generic.h"
The dln_generic..h
header file declares functions and data structures for the generic interface
Line 2:#include "..\..\..\common\dln_gpio.h"
The dln_gpio.h header file declares functions and data structures for GPIO interface.
Line 3:#pragma comment(lib, "..\\..\\..\\bin\\dln.lib")
Use dln.lib
library while project linking.
Line 10:DlnOpenUsbDevice(&device);
The function establishes the connection with the DLN adapter. This application uses the USB connectivity of the adapter. For additional options, refer to the Device Opening & Identification section.
Line 13:DlnGpioPinPullupEnable(device, 0);
Enable pullup for GPIO pin 0. You can read more about pullups at Pull-up/Pull-down Resistors section.
Line 14:DlnGpioPinSetDirection(device, 0, 0);
Set GPIO pin 0 to input. For more information read Digital Inputs section.
Line 15:DlnGpioPinEnable(device, 0);
Enable GPIO pin 0.
Line 18:DlnGpioPinSetDirection(device, 1, 1);
Set GPIO pin 1 direction to output. For more information read Digital Outputs section.
Line 19:DlnGpioPinEnable(device, 1);
Enable GPIO pin 1.
Line 23:DlnGpioPinGetVal(device, 0, &value);
Get value on GPIO pin 0.
Line 24:DlnGpioPinSetOutVal(device, 1, value ^ 1);
Set output value on the GPIO pin 1, which is opposite to the value variable.
Line 27:DlnGpioPinDisable(device, 0);
Disable GPIO pin 0.
Line 28:DlnGpioPinDisable(device, 1);
Disable GPIO pin 1.
Line 30:DlnCloseHandle(device);
The application closes the handle to the connected DLN-series adapter.