Param: unsigned int subdevice
Param: unsigned int write_mask
Param: unsigned int * bits
+Status: deprecated
+Description:
+ This function is deprecated. Use comedi_dio_bitfield2() instead.
+
+Function: comedi_dio_bitfield2 -- read/write multiple digital channels
+Retval: int
+Param: comedi_t * device
+Param: unsigned int subdevice
+Param: unsigned int write_mask
+Param: unsigned int * bits
+Param: unsigned int base_channel
Description:
- The function comedi_dio_bitfield() allows multiple channels to
- be read simultaneously from a digital input or digital I/O device.
- The parameter write_mask and the value pointed to by bits
+ The function comedi_dio_bitfield2() allows multiple channels to
+ be read or written together on a digital input, output,
+ or configurable digital I/O device.
+ The parameter <parameter>write_mask</parameter>
+ and the value pointed to by <parameter>bits</parameter>
are interpreted as bit fields, with the least significant bit
- representing channel 0. For each bit in write_mask that is
- set to 1, the cooresponding bit in *bits is written to the digital
+ representing channel <parameter>base_channel</parameter>.
+ For each bit in <parameter>write_mask</parameter> that is
+ set to 1, the cooresponding bit in <parameter>*bits</parameter>
+ is written to the digital
output channel. After writing all the output channels, each
channel is read, and the result placed in the approprate bits in
- *bits. The result of reading an output channel is undefined.
- It is not possible to access channels greater than 31 using this
- function.
+ <parameter>*bits</parameter>. The result of
+ reading an output channel is the last
+ value written to the output channel.
+
+ All the channels may not be read or written at the exact same time.
+ For example, the driver may need to sequentially write to
+ several ports in order to set all the digital channels specified
+ by the <parameter>write_mask</parameter>.
Function: comedi_sv_init -- slowly-varying inputs
Retval: int
int comedi_get_n_subdevices(comedi_t *it);
#define COMEDI_VERSION_CODE(a,b,c) (((a)<<16) | ((b)<<8) | (c))
int comedi_get_version_code(comedi_t *it);
-char *comedi_get_driver_name(comedi_t *it);
-char *comedi_get_board_name(comedi_t *it);
+const char *comedi_get_driver_name(comedi_t *it);
+const char *comedi_get_board_name(comedi_t *it);
int comedi_get_read_subdevice(comedi_t *dev);
int comedi_get_write_subdevice(comedi_t *dev);
unsigned int *bit);
int comedi_dio_write(comedi_t *it,unsigned int subd,unsigned int chan,
unsigned int bit);
-int comedi_dio_bitfield(comedi_t *it,unsigned int subd,
- unsigned int write_mask, unsigned int *bits);
+int comedi_dio_bitfield2(comedi_t *it,unsigned int subd,
+ unsigned int write_mask, unsigned int *bits, unsigned int base_channel);
/* slowly varying stuff */
int comedi_sv_init(comedi_sv_t *it,comedi_t *dev,unsigned int subd,unsigned int chan);
unsigned int n_samples,double *data);
int comedi_get_rangetype(comedi_t *it,unsigned int subdevice,
unsigned int chan);
+int comedi_dio_bitfield(comedi_t *it,unsigned int subd,
+ unsigned int write_mask, unsigned int *bits);
#endif
{
struct stat file_stats;
char *file_path;
- char *board_name, *temp;
- char *driver_name;
+ const char *temp;
+ char *board_name;
+ const char *driver_name;
if( fstat( comedi_fileno( dev ), &file_stats ) < 0 )
{
if(!valid_chan(it,subdev,chan))
return -1;
-
+
s=it->subdevices+subdev;
if(s->type!=COMEDI_SUBD_DIO)
return -1;
if(it->has_insnlist_ioctl){
comedi_insn insn;
lsampl_t data;
-
+
memset(&insn,0,sizeof(insn));
insn.insn = INSN_CONFIG;
insn.n = 1;
comedi_insn insn;
lsampl_t data[2];
int retval;
-
+
if(!valid_chan(it,subdev,chan))
return -1;
-
+
s=it->subdevices+subdev;
if(s->type!=COMEDI_SUBD_DIO)
return -1;
if(it->has_insnlist_ioctl == 0)
return -1;
-
+
memset(&insn,0,sizeof(insn));
insn.insn = INSN_CONFIG;
insn.n = sizeof(data) / sizeof(data[0]);
if(it->has_insnlist_ioctl){
comedi_insn insn;
lsampl_t data;
-
+
memset(&insn,0,sizeof(insn));
insn.insn = INSN_READ;
insn.n = 1;
if(!valid_chan(it,subdev,chan))
return -1;
-
+
s = it->subdevices+subdev;
if(s->type!=COMEDI_SUBD_DIO &&
s->type!=COMEDI_SUBD_DO)
if(it->has_insnlist_ioctl){
comedi_insn insn;
lsampl_t data;
-
+
memset(&insn,0,sizeof(insn));
insn.insn = INSN_WRITE;
insn.n = 1;
}
}
-EXPORT_ALIAS_DEFAULT(_comedi_dio_bitfield,comedi_dio_bitfield,0.7.18);
-int _comedi_dio_bitfield(comedi_t *it,unsigned int subdev,unsigned int mask,unsigned int *bits)
+EXPORT_ALIAS_DEFAULT(_comedi_dio_bitfield2,comedi_dio_bitfield2,0.7.23);
+int _comedi_dio_bitfield2(comedi_t *it, unsigned int subdev, unsigned int mask, unsigned int *bits, unsigned base_channel)
{
int ret;
unsigned int m,bit;
subdevice *s;
- if(!valid_subd(it,subdev))
+ if(!valid_subd(it, subdev))
return -1;
- s=it->subdevices+subdev;
+ s = it->subdevices + subdev;
- if(s->type!=COMEDI_SUBD_DIO && s->type!=COMEDI_SUBD_DO &&
- s->type!=COMEDI_SUBD_DI)
+ if(s->type != COMEDI_SUBD_DIO && s->type != COMEDI_SUBD_DO &&
+ s->type != COMEDI_SUBD_DI)
return -1;
- if(s->has_insn_bits){
+ if(s->has_insn_bits)
+ {
comedi_insn insn;
lsampl_t data[2];
-
+
memset(&insn,0,sizeof(insn));
insn.insn = INSN_BITS;
+ insn.chanspec = base_channel;
insn.n = 2;
insn.data = data;
insn.subdev = subdev;
- data[0]=mask;
- data[1]=*bits;
+ data[0] = mask;
+ data[1] = *bits;
- ret = comedi_do_insn(it,&insn);
+ ret = comedi_do_insn(it, &insn);
- if(ret<0)return ret;
+ if(ret < 0) return ret;
*bits = data[1];
return 0;
}else{
- unsigned int i,n_chan;
-
- n_chan=comedi_get_n_channels(it,subdev);
- if(n_chan>32)n_chan=32;
- for(i=0,m=1;i<n_chan;i++,m<<=1){
- if(mask&m){
- bit=(*bits&m)?1:0;
- ret=comedi_dio_write(it,subdev,i,bit);
+ unsigned i;
+ for(i = 0, m = 1; i < 32; ++i, m <<= 1)
+ {
+ if(mask & m)
+ {
+ bit = (*bits & m) ? 1 : 0;
+ ret = comedi_dio_write(it, subdev, base_channel + i, bit);
}else{
- ret=comedi_dio_read(it,subdev,i,&bit);
- if(bit) *bits|=m;
- else (*bits)&=~m;
+ ret = comedi_dio_read(it, subdev, base_channel + i, &bit);
+ if(bit) *bits |= m;
+ else (*bits) &= ~m;
}
- if(ret<0)return ret;
+ if(ret < 0) return ret;
}
- return (int)n_chan;
+ return 0;
}
}
+EXPORT_ALIAS_DEFAULT(_comedi_dio_bitfield,comedi_dio_bitfield,0.7.18);
+int _comedi_dio_bitfield(comedi_t *it, unsigned int subdev, unsigned int mask, unsigned int *bits)
+{
+ return _comedi_dio_bitfield2(it, subdev, mask, bits, 0);
+}
+
}
EXPORT_ALIAS_DEFAULT(_comedi_get_driver_name,comedi_get_driver_name,0.7.18);
-char* _comedi_get_driver_name(comedi_t *it)
+const char* _comedi_get_driver_name(comedi_t *it)
{
if(!valid_dev(it))
return NULL;
}
EXPORT_ALIAS_DEFAULT(_comedi_get_board_name,comedi_get_board_name,0.7.18);
-char* _comedi_get_board_name(comedi_t *it)
+const char* _comedi_get_board_name(comedi_t *it)
{
if(!valid_dev(it))
return NULL;
if(!valid_dev(it))
return -1;
s = malloc(sizeof(comedi_subdinfo) * it->n_subdevices);
- if(s == NULL)
+ if(s == NULL)
{
__comedi_errno = errno;
return -1;
}
ret = comedi_ioctl(it->fd, COMEDI_SUBDINFO, (unsigned long)s);
- if(ret < 0)
+ if(ret < 0)
{
free(s);
return -1;
v0.7.23 {
global:
comedi_from_physical;
+ comedi_dio_bitfield2;
comedi_dio_get_config;
comedi_get_hardcal_converter;
comedi_get_softcal_converter;