You are here

command.exe

This program sends asynchronous command to USB-IO Interface Adapter. The GPIO command should be provided as command line parameter in a form of 8 hexadecimal numbers separated by spaces. For example, to configure C.0 pin for pulse width modulation (PWM) you can run the following:

command.exe 01 00 2 01 00 00 00 02

Use transaction application if you want to send synchronous messages (get the device response before application exits).

You can launch command.exe application from scripting languages (like Perl, ASP, bash, etc.).

Application can also be used as good SW example of interfacing USB-IO adapter from C++ language:

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

#include <string>

int main(int argc, char* argv[])
{
	if (argc != GPIO_COMMAND_LENGTH + 1)
	{
		printf("8-byte command has to be provided\r\n");
		return -1;
	}
	GPIO_COMMAND cmd;
	for (int i = 0; i < GPIO_COMMAND_LENGTH; i++)
	{
		char* end;
		errno  = 0;
		unsigned long value = strtoul(argv[i+1], &end, 16);
		if ((*end) || (errno != 0) || (value > 0xFF))
		{
			printf("Invalid parameter: \"%s\"\r\n", argv[i+1]);
			return -1;
		}
		cmd.command[i] = (unsigned char) value;
	}

	GPIO_NOTIFICATION notification;
	GPIO_RESULT pc;
	HGPIO device;


	notification.type = ntNoNotification;
	if (GPIO_FAILED((pc = GPIO_Init(notification))))
	{
		printf("Failed to initialize library, Error = %d\r\n", pc);
		return pc;
	}
	if (GPIO_FAILED((pc = GPIO_OpenDevice(0, &device))))
	{
		printf("Failed to open device, Error = %d\r\n", pc);
		GPIO_Uninit();
		return pc;
	}
	if (GPIO_FAILED((pc = GPIO_SendCommand(device, cmd))))
	{
		printf("Failed to send command, Error = %d\r\n", pc);
		GPIO_CloseDevice(device);
		GPIO_Uninit();
		return pc;
	}
	GPIO_CloseDevice(device);
	GPIO_Uninit();
	return pc;
}