Send a data to the parallel port.
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpDebug.h>
#if defined VISP_HAVE_PARPORT
#include <iostream>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <visp3/io/vpParallelPort.h>
#include <visp3/io/vpParseArgv.h>
#define GETOPTARGS "d:h"
void usage(const char *name, const char *badparam, unsigned char &data)
{
fprintf(stdout, "\n\
Send a data to the parallel port.\n\
\n\
SYNOPSIS\n\
%s [-d <data>] [-h]\n\
", name);
fprintf(stdout, "\n\
OPTIONS: Default\n\
-d <data> %d\n\
Data to send to the parallel port.\n\
Value should be in [0:255].\n\
\n\
-h\n\
Print the help.\n\n", data);
if (badparam) {
fprintf(stderr, "ERROR: \n");
fprintf(stderr, "\nBad parameter [%s]\n", badparam);
}
}
bool getOptions(int argc, const char **argv, unsigned char &data)
{
const char *optarg;
int c;
int value;
switch (c) {
case 'd': {
value = atoi(optarg);
if ((value < 0) || (value > 255)) {
usage(argv[0], optarg, data);
std::cerr << "ERROR: " << std::endl;
std::cerr << " Bad value \"-d " << optarg << "\"" << std::endl << std::endl;
return false;
} else {
data = (unsigned char)value;
}
break;
}
case 'h':
usage(argv[0], NULL, data);
return false;
break;
default:
usage(argv[0], optarg, data);
return false;
break;
}
}
if ((c == 1) || (c == -1)) {
usage(argv[0], NULL, data);
std::cerr << "ERROR: " << std::endl;
std::cerr << " Bad argument " << optarg << std::endl << std::endl;
return false;
}
return true;
}
int main(int argc, const char **argv)
{
unsigned char data = 0;
if (getOptions(argc, argv, data) == false) {
exit(-1);
}
try {
printf("Send data \"%d\" to the parallel port\n", data);
printf("Can't open the parallel port\n");
break;
printf("Can't close the parallel port\n");
break;
}
std::cout <<
"An error occurs: " << e.
getMessage() << std::endl;
}
return EXIT_SUCCESS;
}
#else
int main()
{
std::cout << "vpParallelPort class works only on unix..." << std::endl;
return EXIT_SUCCESS;
}
#endif