6602 counters

Hi, I am using comedi (0.7.21) and RTAI (2.4.24-adeos) and I use a 6602
national instruments data adquisition card to deal with
an encoder. I want to work with its counters but I can't make it work. I
use the ni_660x driver as official comedi webpage says.
I tried the same program with a 6035 national instruments card using the
ni_pcimio driver and its counters worked well.
I am using instructions, not commands. Any help?
I use the following functions to deal with counters:

int ComediCounterReset(comedi_t *dev, int subdev, int channel){
comedi_insn insn;
lsampl_t params[]= { GPCT_RESET }; // the config subcommand: reset counter
insn.insn= INSN_CONFIG; // it is a configuration sub-command
insn.n= 1; // the parameter-array contains 1 element
insn.data= params; // pass parameters
insn.subdev= subdev; // which subdevice controls the counter
insn.chanspec= CH(channel); // tell which counter to use
return comedi_do_insn(dev, &insn);
}

int ComediCounterSetZero(comedi_t *dev, int subdev, int channel){
comedi_insn insn;
lsampl_t params[]= {valor_zero}; /* value to start the counter at */
insn.insn = INSN_WRITE;
insn.n = 1;
insn.data = params;
insn.subdev = subdev;
insn.chanspec = CR_PACK (channel, 0, 0 );
return comedi_do_insn (dev,&insn);
}


int ComediCounterSetSource(comedi_t *dev, int subdev, int channel, int
SrcType){
comedi_insn insn;
lsampl_t params[]= { GPCT_SET_SOURCE, SrcType };
// the config subcommand: set source, and the add. param.: type of the
source
insn.insn= INSN_CONFIG; // it is a configuration sub-command
insn.n= 2; // the parameter-array contains 2 elements
insn.data= params; // pass parameters
insn.subdev= subdev; // which subdevice controls the counter
insn.chanspec= CH(channel); // tell which counter to use
return comedi_do_insn(dev, &insn);
}

int ComediCounterSetGate(comedi_t *dev, int subdev, int channel, int
GateType){
comedi_insn insn;
lsampl_t params[]= { GPCT_SET_GATE, GateType };
// the config subcommand: set source, and the add. param.: type of the gate
insn.insn= INSN_CONFIG; // it is a configuration sub-command
insn.n= 2; // the parameter-array contains 2 elements
insn.data= params; // pass parameters
insn.subdev= subdev; // which subdevice controls the counter?
insn.chanspec= CH(channel); // tell which counter to use
return comedi_do_insn(dev, &insn);
}

int ComediCounterSetDirection(comedi_t *dev, int subdev, int channel,
int Direction){
comedi_insn insn;
lsampl_t params[]= { GPCT_SET_DIRECTION, Direction };
// the config subcommand: set direction, and the add. param.: direction
insn.insn= INSN_CONFIG; // it is a configuration sub-command
insn.n= 2; // the parameter-array contains 2 elements
insn.data= params; // pass parameters
insn.subdev= subdev; // which subdevice controls the counter?
insn.chanspec= CH(channel); // tell which counter to use
return comedi_do_insn(dev, &insn);
}

int ComediCounterSetOperation(comedi_t *dev, int subdev, int channel,
int Operation, int OptParam){
comedi_insn insn;
lsampl_t params[]= { GPCT_SET_OPERATION, Operation, OptParam };
// the config subcommand: set source, and the add. param.: operation
insn.insn= INSN_CONFIG; // it is a configuration sub-command
insn.n= OptParam == -1 ? 2 : 3; // the parameter-array contains 2 or 3
elements
insn.data= params; // pass parameters
insn.subdev= subdev; // which subdevice controls the counter?
insn.chanspec= CH(channel); // tell which counter to use
return comedi_do_insn(dev, &insn);
}

int ComediCounterArm(comedi_t *dev, int subdev, int channel){
comedi_insn insn;
lsampl_t params[]= { GPCT_ARM }; // the config subcommand: arm
insn.insn= INSN_CONFIG; // it is a configuration sub-command
insn.n= 1; // the parameter-array contains 1 element
insn.data= params; // pass parameters
insn.subdev= subdev; // which subdevice controls the counter?
insn.chanspec= CH(channel); // tell which counter to use
return comedi_do_insn(dev, &insn);
}

int ComediCounterDisarm(comedi_t *dev, int subdev, int channel){
comedi_insn insn;
lsampl_t params[]= { GPCT_DISARM }; // the config subcommand: disarm
insn.insn= INSN_CONFIG; // it is a configuration sub-command
insn.n= 1; // the parameter-array contains 1 element
insn.data= params; // pass parameters
insn.subdev= subdev; // which subdevice controls the counter?
insn.chanspec= CH(channel); // tell which counter to use

return comedi_do_insn(dev, &insn);
}

int ComediCounterRead(comedi_t *dev, int subdev, int channel, lsampl_t
*data){
comedi_insn insn;
insn.insn= INSN_READ; // it is a read command
insn.n= 1; // the size of the parameter array is 1
insn.data= data; // pass destination "array"
insn.subdev= subdev; // which subdevice controls the counter
insn.chanspec= CH(channel); // tell which counter to use

return comedi_do_insn(dev, &insn);
}

lsampl_t ComediCounterRead(comedi_t *dev, int subdev, int channel)
{
comedi_insn insn;
lsampl_t value= 0;
insn.insn= INSN_READ; // it is a read command
insn.n= 1;
insn.data= &value; // pass destination "array"
insn.subdev= subdev; // which subdevice controls the counter
insn.chanspec= CH(channel); // tell which counter to use
if (comedi_do_insn(dev, &insn) < 0)
printf("[Warning] comedi_do_insn failed.\n ComediCounterRead: returned
value is not valid.\n");
return value;
}

-- 
Rodrigo Pérez Ruiz
Unidad de Ensayo y Control

ENCOPIM S.L.
C/. del Parc, 5 (nave 13)
P.I. Els Pinetons
E-08291 RIPOLLET (Barcelona)
Tel: (+34) 935 94 23 47
Fax: (+34) 935 94 64 15

==========================================================
La informacin contenida en la presente transmisin es confidencial y su uso
nicamente est�permitido a su(s) destinatario(s). Si Ud. no es la persona
destinataria de la presente transmisin, rogamos nos lo comunique de manera
inmediata por tel�ono (+34 935 942 347) y destruya cualquier copia de la
misma (tanto digitales como en papel).

The information contained in this transmission is confidential and is
intended only for the use of the addressee(s). If you are not the designated
recipient of this transmission, please advise us immediately by telephone
(+34 935 942 347) and destroy any copies (digital and paper).
======================================================

Received on 2005-04-29Z10:36:20