ViSP  2.8.0
vpParallelPort.cpp
1 /****************************************************************************
2  *
3  * $Id: vpParallelPort.cpp 4317 2013-07-17 09:40:17Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Parallel port management.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 
42 
43 #include <visp/vpConfig.h>
44 
45 #ifdef VISP_HAVE_PARPORT
46 
47 # include <sys/types.h>
48 # include <sys/stat.h>
49 # include <fcntl.h>
50 # include <sys/ioctl.h>
51 # include <unistd.h>
52 
53 # include <visp/vpParallelPort.h>
54 
62 static unsigned char vpParallelPortData;
63 
78 {
79  sprintf(device, "/dev/parport0");
80 
81  this->open();
82 
83  unsigned char data = 0;
84  this->sendData(data);
85 }
86 
94 {
95  this->close();
96 }
97 
107 void vpParallelPort::open()
108 {
109  fd = ::open("/dev/parport0", O_WRONLY);
110  if (fd < 0) {
111  printf("Can't open /dev/parport0\n");
112  printf("Check if you have write access to /dev/parport0\n");
113  perror("Open parallel port");
115  "Can't open /dev/parport0")) ;
116  }
117 
118  int i;
119 
120  ioctl(fd, PPCLAIM);
121  i = PARPORT_MODE_COMPAT;
122  ioctl(fd, PPSETMODE, & i);
123  i = IEEE1284_MODE_COMPAT;
124  ioctl(fd, PPNEGOT, & i);
125 }
126 
144 void vpParallelPort::sendData(unsigned char &data)
145 {
146  ioctl(fd, PPWDATA, & data);
147 
148  // Memorise the last sended data to the static variable
149  vpParallelPortData = data;
150 }
151 
157 unsigned char vpParallelPort::getData()
158 {
159  return vpParallelPortData;
160 }
161 
169 void vpParallelPort::close()
170 {
171  ioctl(fd, PPRELEASE);
172 
173  int err;
174  err = ::close(fd);
175 
176  if (err !=0) {
177  printf("Can't close the parallel port\n");
179  "Can't close the parallel port")) ;
180  }
181 
182 
183 }
184 
185 
186 #endif
187 
unsigned char getData()
void sendData(unsigned char &data)
Error that can be emited by the vpParallelPort class and its derivates.