1 /***********************************************************************
2 Copyright (C) 2007 Francois Poulain, <fpoulain AT gmail DOT com>
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software Foundation,
15 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 ***********************************************************************/
20 #include <comedilib.h>
23 #define PERIOD 250000000.0 /* in nanoseconds */
24 #define TIME 2.0 /* in seconds */
29 comedi_insn instruction;
30 lsampl_t data[MF624_ENC_DATA_SIZE], dataReaded;
31 int subdev = MF624_ENC_SUBDEV;
35 char filename[] = "/dev/comedi0";
38 struct timespec tempo;
40 tempo.tv_sec = PERIOD/1e9;
41 tempo.tv_nsec = PERIOD - tempo.tv_sec*1e9;
43 data[0] = MF624_ENC_MODE_RISING; /* Encoder mode */
44 data[1] = MF624_ENC_COUNT_ENABLE; /* Encoder counting */
45 data[2] = MF624_ENC_RESET_ENABLE_BYINPUT; /* Encoder reset */
46 data[3] = MF624_ENC_FILTER_ON; /* Encoder filtering */
48 instruction.insn = INSN_CONFIG;
49 instruction.n = MF624_ENC_DATA_SIZE;
50 instruction.data = data;
51 instruction.subdev = subdev;
52 instruction.chanspec=CR_PACK(chan,range,aref);
54 // comedi_loglevel(4);
56 /* Open comedi device */
57 device = comedi_open(filename);
59 comedi_perror(filename);
63 comedi_do_insn(device , &instruction);
65 while(toc++ < TIME/(PERIOD/1000000000)){
66 comedi_data_read(device, subdev, chan, range, aref, &dataReaded);
67 printf("retour : %x\n", dataReaded);
68 nanosleep(&tempo, NULL);