You are here

tracer.exe

This program monitors events and responses sent by USB-IO Interface Adapter. All events are formatted and printed on console. You can use this application to monitor events during your SW development.

You can also redirect tracer output and collect GPIO events and responses in log file as:

tracer.exe > gpio.log

Tracer application exits when you press any key.

This application demonstrates how to use event object notification type:

#include <windows.h>
#include <stdio.h>
#include "../common/gpio_24.h"
#include "../common/reports.h"
#include "../common/format.h"
#pragma comment (lib, "../bin/gpio_24.lib")

/*!
Opens all USB-IO Adapters currently connected to PC.
\retval GPIO_S_SUCCESS If all USB-IO Adapters were successfully open.
*/
GPIO_RESULT open()
{
	GPIO_RESULT pc;
	long count;
	HGPIO device;

	if (GPIO_FAILED((pc = GPIO_GetDeviceCount(&count))))
	{
		printf("GPIO_GetDeviceCount failed, Error = %s\r\n", 
			gpio_error(pc).c_str());
		return pc;
	}

	for (long i = 0; i < count; i++)
	{
		if (GPIO_FAILED((pc = GPIO_OpenDevice(i, &device))))
		{
			printf("Failed to open device, Error = %s\r\n", 
				gpio_error(pc).c_str());
			return pc;
		}
	}
	return GPIO_S_SUCCESS;
}


int main(int argc, char* argv[])
{
	GPIO_RESULT pc;
	GPIO_NOTIFICATION notification;
	notification.type = ntEvent;
	notification.event = CreateEvent(NULL, FALSE, FALSE, NULL);

	if (GPIO_FAILED((pc = GPIO_Init(notification))))
	{
		printf("Failed to initialize library, Error = %s\r\n", 
			gpio_error(pc).c_str());
		return pc;
	}

	if (GPIO_FAILED((pc = open())))
	{
		GPIO_CloseAllDevices();
		GPIO_Uninit();
		return pc;
	}


	HANDLE console =  GetStdHandle(STD_INPUT_HANDLE);
	SetConsoleMode(console, ENABLE_PROCESSED_INPUT);
	HANDLE handles[2];
	handles[0] = console;
	handles[1] = notification.event;
	bool trace = true;
	while (trace)
	{
		DWORD wait_result;
		wait_result = WaitForMultipleObjects(2, handles, FALSE, INFINITE);
		switch (wait_result)
		{
		case WAIT_OBJECT_0: // console event
			{
				INPUT_RECORD input;
				DWORD events_number;
				BOOL test = ReadConsoleInput(console, &input, 1, 
					&events_number);
				if (events_number && (input.EventType == KEY_EVENT))
					trace = false;
				break;
			}
		case WAIT_OBJECT_0 + 1: // GPIO event
			{
				// GPIO event arrived 
				GPIO_RESULT pc;
				GPIO_EVENT event;
				while(GPIO_SUCCEEDED((pc = GPIO_GetEvent(HGPIO_ALL_DEVICES, &event))))
				{
					printf("%27s – %-27s %02X %02X %02X %02X %02X %02X %02X\r\n",
						handle_to_string(event.device).c_str(),
						event_to_string(event.event[0]).c_str(),
						event.event[1], event.event[2], 
						event.event[3], event.event[4], 
						event.event[5], event.event[6], 
						event.event[7]);
					switch (event.event[0])
					{
					case GPIO_EV_DEVICE_REMOVED:
						pc = GPIO_CloseDevice(event.device);
						break;
					case GPIO_EV_DEVICE_ADDED:
						pc = open();
					}
					if (GPIO_FAILED(pc))
						break;
				}
				if (pc != GPIO_E_EVENT_ABSENT)
					printf("Error – %s\r\n", gpio_error(pc).c_str());
				break;
			}
		}
	}

	GPIO_CloseAllDevices();
	GPIO_Uninit();
	CloseHandle(console);
	CloseHandle(notification.event);
	return 0;
}