Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
parallelPort.cpp
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4
*
5
* This software is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
9
* See the file LICENSE.txt at the root directory of this source
10
* distribution for additional information about the GNU GPL.
11
*
12
* For using ViSP with software that can not be combined with the GNU
13
* GPL, please contact Inria about acquiring a ViSP Professional
14
* Edition License.
15
*
16
* See https://visp.inria.fr for more information.
17
*
18
* This software was developed at:
19
* Inria Rennes - Bretagne Atlantique
20
* Campus Universitaire de Beaulieu
21
* 35042 Rennes Cedex
22
* France
23
*
24
* If you have questions regarding the use of this file, please contact
25
* Inria at visp@inria.fr
26
*
27
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
*
30
* Description:
31
* Example of parallel port management.
32
*/
33
39
40
#include <visp3/core/vpConfig.h>
41
#include <visp3/core/vpDebug.h>
42
43
#if defined VISP_HAVE_PARPORT
44
#include <iostream>
45
#include <signal.h>
46
#include <stdio.h>
47
#include <stdlib.h>
48
49
#include <visp3/io/vpParallelPort.h>
50
#include <visp3/io/vpParseArgv.h>
51
52
// List of allowed command line options
53
#define GETOPTARGS "d:h"
54
55
#ifdef ENABLE_VISP_NAMESPACE
56
using namespace
VISP_NAMESPACE_NAME
;
57
#endif
58
68
void
usage(
const
char
*name,
const
char
*badparam,
unsigned
char
&data)
69
{
70
fprintf(stdout,
"\n\
71
Send a data to the parallel port.\n\
72
\n\
73
SYNOPSIS\n\
74
%s [-d <data>] [-h]\n\
75
"
,
76
name);
77
78
fprintf(stdout,
"\n\
79
OPTIONS: Default\n\
80
-d <data> %d\n\
81
Data to send to the parallel port.\n\
82
Value should be in [0:255].\n\
83
\n\
84
-h\n\
85
Print the help.\n\n"
,
86
data);
87
88
if
(badparam) {
89
fprintf(stderr,
"ERROR: \n"
);
90
fprintf(stderr,
"\nBad parameter [%s]\n"
, badparam);
91
}
92
}
93
105
bool
getOptions(
int
argc,
const
char
**argv,
unsigned
char
&data)
106
{
107
const
char
*optarg;
108
int
c;
109
110
int
value;
111
while
((c =
vpParseArgv::parse
(argc, argv, GETOPTARGS, &optarg)) > 1) {
112
113
switch
(c) {
114
case
'd'
: {
115
value = atoi(optarg);
116
if
((value < 0) || (value > 255)) {
117
usage(argv[0], optarg, data);
118
std::cerr <<
"ERROR: "
<< std::endl;
119
std::cerr <<
" Bad value \"-d "
<< optarg <<
"\""
<< std::endl << std::endl;
120
return
false
;
121
}
122
else
{
123
data
= (
unsigned
char)value;
124
}
125
break
;
126
}
127
case
'h'
:
128
usage(argv[0],
nullptr
, data);
129
return
false
;
130
131
default
:
132
usage(argv[0], optarg, data);
133
return
false
;
134
}
135
}
136
137
if
((c == 1) || (c == -1)) {
138
// standalone param or error
139
usage(argv[0],
nullptr
, data);
140
std::cerr <<
"ERROR: "
<< std::endl;
141
std::cerr <<
" Bad argument "
<< optarg << std::endl << std::endl;
142
return
false
;
143
}
144
145
return
true
;
146
}
147
153
int
main(
int
argc,
const
char
**argv)
154
{
155
// data to send to the parallel port
156
unsigned
char
data
= 0;
157
158
// Read the command line options
159
if
(getOptions(argc, argv, data) ==
false
) {
160
return
EXIT_FAILURE;
161
}
162
try
{
163
164
vpParallelPort
parport;
165
166
printf(
"Send data \"%d\" to the parallel port\n"
, data);
167
parport.
sendData
(data);
168
169
}
170
catch
(
vpParallelPortException
&e) {
171
switch
(
e
.getCode()) {
172
case
vpParallelPortException::opening
:
173
printf(
"Can't open the parallel port\n"
);
174
break
;
175
case
vpParallelPortException::closing
:
176
printf(
"Can't close the parallel port\n"
);
177
break
;
178
}
179
}
180
catch
(
const
vpException
&e) {
181
std::cout <<
"An error occurs: "
<<
e
.getMessage() << std::endl;
182
}
183
return
EXIT_SUCCESS;
184
}
185
#else
186
int
main()
187
{
188
std::cout <<
"vpParallelPort class works only on unix..."
<< std::endl;
189
return
EXIT_SUCCESS;
190
}
191
#endif
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpParallelPortException
Error that can be emitted by the vpParallelPort class and its derivates.
Definition
vpParallelPortException.h:57
vpParallelPortException::closing
@ closing
Definition
vpParallelPortException.h:66
vpParallelPortException::opening
@ opening
Definition
vpParallelPortException.h:65
vpParallelPort
Parallel port management under unix.
Definition
vpParallelPort.h:83
vpParallelPort::sendData
void sendData(unsigned char &data)
Definition
vpParallelPort.cpp:129
vpParseArgv::parse
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition
vpParseArgv.cpp:70
VISP_NAMESPACE_NAME
Definition
vpEigenConversion.h:44
ibvs-four-points.e
e
Definition
ibvs-four-points.py:272
test-serial-read.data
data
Definition
test-serial-read.py:18
example
tools
parallelPort.cpp
Generated by
1.17.0