Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpParallelPort.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Parallel port management.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
38 
39 #include <visp3/core/vpConfig.h>
40 
41 #ifdef VISP_HAVE_PARPORT
42 
43 # include <sys/types.h>
44 # include <sys/stat.h>
45 # include <fcntl.h>
46 # include <sys/ioctl.h>
47 # include <unistd.h>
48 
49 # include <visp3/io/vpParallelPort.h>
50 
58 static unsigned char vpParallelPortData;
59 
73 vpParallelPort::vpParallelPort() : fd(0), device()
74 {
75  sprintf(device, "/dev/parport0");
76 
77  this->open();
78 
79  unsigned char data = 0;
80  this->sendData(data);
81 }
82 
90 {
91  this->close();
92 }
93 
103 void vpParallelPort::open()
104 {
105  fd = ::open("/dev/parport0", O_WRONLY);
106  if (fd < 0) {
107  printf("Can't open /dev/parport0\n");
108  printf("Check if you have write access to /dev/parport0\n");
109  perror("Open parallel port");
111  "Can't open /dev/parport0")) ;
112  }
113 
114  int i;
115 
116  ioctl(fd, PPCLAIM);
117  i = PARPORT_MODE_COMPAT;
118  ioctl(fd, PPSETMODE, & i);
119  i = IEEE1284_MODE_COMPAT;
120  ioctl(fd, PPNEGOT, & i);
121 }
122 
140 void vpParallelPort::sendData(unsigned char &data)
141 {
142  ioctl(fd, PPWDATA, & data);
143 
144  // Memorise the last sended data to the static variable
145  vpParallelPortData = data;
146 }
147 
153 unsigned char vpParallelPort::getData()
154 {
155  return vpParallelPortData;
156 }
157 
165 void vpParallelPort::close()
166 {
167  ioctl(fd, PPRELEASE);
168 
169  int err;
170  err = ::close(fd);
171 
172  if (err !=0) {
173  printf("Can't close the parallel port\n");
175  "Can't close the parallel port")) ;
176  }
177 
178 
179 }
180 
181 #elif !defined(VISP_BUILD_SHARED_LIBS)
182 // Work arround to avoid warning: libvisp_core.a(vpParallelPort.cpp.o) has no symbols
183 void dummy_vpParallelPort() {};
184 #endif
185 
unsigned char getData()
void sendData(unsigned char &data)
Error that can be emited by the vpParallelPort class and its derivates.