Simple Generic Module Example

The following example shows how to open DLN device, get its main parameters (hardware version, identifier and serial number), print them to console and close device. You can find the complete example in the “..\Program Files\Diolan\DLN\examples\c_cpp\examples\simple” folder after DLN setup package installation.

C/C++
#include "..\..\..\common\dln_generic.h"
#pragma comment(lib, "..\\..\\..\\bin\\dln.lib")

int main(int argc, char* argv[])
{
	// Open device
	HDLN device;
	DlnOpenUsbDevice(&device);

	// Get device parameters
	DLN_VERSION version;
	uint32_t sn, id;
	DlnGetVersion(device, &version);
	DlnGetDeviceSn(device, &sn);
	DlnGetDeviceId(device, &id);

	// Print it
	printf("Device HwType = 0x%x, SN = 0x%x, ID = 0x%x\n", version.hardwareType,
sn, id);

	// 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:#pragma comment(lib, "..\\..\\..\\bin\\dln.lib")

    Use dln.lib library while project linking.

  • Line 8: 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:DlnGetVersion(device, &version);

    This function assigns device parameters to the DLN_VERSION type structure variable.

  • Line 14:DlnGetDeviceSn(device, &sn);

    This function assigns device serial number to the provided pointer to 32-bit integer type variable. Serial number is unchangeable for each device and assigned once during device production.

  • Line 15:DlnGetDeviceId(device, &id);

    This function assigns device id to the provided pointer to 32-bit integer type variable. Id number can be assigned by user by calling DlnSetDeviceId() function.

  • Line 18:printf("Device HwType = 0x%x, SN = 0x%x, ID = 0x%x\n", version.hardwareType, sn, id);

    Printing the results. In the console you will see hardware type, serial number and id of the connected device.

  • Line 21:DlnCloseHandle(device);

    Closing handle to the previously opened DLN-series adapter.

Rating: 
Average: 1 (1 vote)