Вы здесь

Simple Pulse Counter Module Example

This example shows how to setup pulse counter module, read timer and pulse counter values. 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"
#include "..\..\..\common\dln_pls_cnt.h"
#pragma comment(lib, "..\\..\\..\\bin\\dln.lib")


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

	// Set Free Run mode
	DlnPlsCntSetMode(device, 0, DLN_PLS_CNT_MODE_FREE_RUN, 0);
	// Enable counter
	uint16_t conflict;
	DlnPlsCntEnable(device, 0, &conflict);

	// Do some delay
	for (int i = 0; i < 10000; i++);

	// Read counter values
	uint32_t timerValue, counterValue;
	DlnPlsCntGetValue(device, 0, &timerValue, &counterValue);
	printf("Timer Value = %u, Counter Value = %u\n", timerValue, counterValue);

	// 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. In current example this header is used to call DlnOpenUsbDevice() and DlnCloseHandle() functions.

  • Line 2:#include "..\..\..\common\dln_pls_cnt.h"

    The dln_pwm.h header file declares functions and data structures for the PWM interface. In current example this header is used to call DlnPlsCntSetMode(), DlnPlsCntEnable(), DlnPlsCntGetValue() functions.

  • 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:DlnPlsCntSetMode(device, 0, DLN_PLS_CNT_MODE_FREE_RUN, 0);

    The function sets pulse counter mode to “Free run mode”. You can read more about pulse counter modes at Pulse Counter Modes section.

  • Line 16:DlnPlsCntEnable(device, 0, &conflict);

    The function enables pulse counter module.

  • Line 19:for (int i = 0; i < 10000; i++);

    Performing delay for more continuous mode of counter.

  • Line 23:DlnPlsCntGetValue(device, 0, &timerValue, &counterValue);

    The function retrieves timer and pulse counter values.

  • Line 24:printf("Timer Value = %u, Counter Value = %u\n", timerValue, counterValue);

    Printing retrieved timer and pulse counter values to console.

  • Line 27:DlnCloseHandle(device);

    The application closes handle to the DLN adapter.

Rating: 
Голосов пока нет

Языки

Вход на сайт