3 functions for setting calibration
5 Copyright (C) 2003 Frank Mori Hess <fmhess@users.sourceforge.net
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation, version 2.1
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <comedilib.h>
27 #include <libinternal.h>
29 static int ph_extract_element( const char *file_path, const char *element,
30 char *result, unsigned int result_size )
32 char perl_prog[ 1024 ];
36 snprintf( perl_prog, sizeof( perl_prog ),
43 "eval \"\\$cal = $hash;\";"
48 perl_stdout = popen( perl_prog, "r");
49 if( perl_stdout == NULL )
51 fprintf( stderr, "popen() failed in ph_extract_element()\n" );
55 if( fgets( result, result_size, perl_stdout ) == NULL )
57 fprintf( stderr, "fgets() returned NULL in ph_extract_element()\n" );
61 retval = pclose( perl_stdout );
64 fprintf( stderr, "perl returned error %i\n in ph_extract_element()", retval );
71 //EXPORT_SYMBOL(comedi_set_calibration,0.7.20);
72 int comedi_set_calibration( comedi_t *dev, const char *cal_file_path,
73 unsigned int subdev, unsigned int channel, unsigned int range, unsigned int aref )
75 struct stat file_stats;
79 cal_file = fopen( cal_file_path, "r" );
84 if( fstat( comedi_fileno( dev ), &file_stats ) < 0 )
86 fprintf( stderr, "failed to get file stats of comedi device file\n" );
90 asprintf( &file_path, "/etc/comedi/calibrations/%s_0x%lx",
91 comedi_get_board_name( dev ),
92 ( unsigned long ) file_stats.st_ino );
93 cal_file = fopen( file_path, "r" );
97 if( cal_file == NULL )
99 fprintf( stderr, "failed to open calibration file\n" );