unsigned int ComediSubDeviceDIn::readSequence(unsigned int start_bit, unsigned int stop_bit) const { unsigned int value = 0; if (!myCard) return 0; if ((start_bit > stop_bit) || (stop_bit >= this->nbOfInputs())) { Logger::In in("ComediSubDeviceDIn"); log(Error) << "start_bit should be less than stop_bit" << endlog(); } else { // Read all channels comedi_dio_bitfield(myCard->getDevice()->it, _subDevice, 0x0, &value); // Filter data from these channels unsigned int write_mask = 0; // Can somebody check this cumbersome line please? for (unsigned int i = start_bit; i <= stop_bit ; i++) { write_mask = write_mask | (0x1 << i); } // Erase other bits that we read value = value & write_mask ; // Shift value "start_bit" bits to the right value = value >> start_bit; // Everything is in read mode, so we don't have to call // dio_config here (as in ComediSubDeviceOut.hpp) } return value; }
static void dio_bitfield( void ) { comedi_t *dev = lookup_dev( *sp++ ); unsigned int subdev = *sp++; unsigned int mask = *sp++; unsigned int data = *sp++; int c = comedi_dio_bitfield( dev, subdev, mask, &data ); if( c < 0 ) comedi_perror( "!@dio " ); *--sp = data; }
void do_toggle(void) { #if 1 comedi_insnlist il; comedi_insn insn[3]; lsampl_t data[6]; int mask = 0xff; count++; il.n_insns = 3; il.insns = insn; memset(insn,0,3*sizeof(comedi_insn)); insn[0].insn = INSN_BITS; insn[0].n = 2; insn[0].data = data+0; insn[0].subdev = out_subd; data[0] = mask; //data[1] = count; data[1] = 0xfc; insn[1].insn = INSN_WAIT; insn[1].n = 1; insn[1].data = data+2; data[2] = 100000-1; insn[2].insn = INSN_BITS; insn[2].n = 2; insn[2].data = data+4; insn[2].subdev = out_subd; data[4] = mask; //data[5] = count; data[5] = 0xff; comedi_do_insnlist(device,&il); #else unsigned int data; unsigned int mask = 0xff; count++; data = count; comedi_dio_bitfield(device,out_subd,mask,&data); #endif }
void ComediSubDeviceDOut::setSequence(unsigned int start_bit, unsigned int stop_bit, unsigned int value) { if ((start_bit > stop_bit) || (stop_bit >= channels)) { Logger::In in("ComediSubDeviceDOut"); log(Error)<< "start_bit should be less than stop_bit) and stopbit can be bigger than the number of channels" << endlog(); return; } else { unsigned int write_mask = 0; // FIXME: Can somebody check this cumbersome line please? for (unsigned int i = start_bit; i <= stop_bit ; i++) { write_mask = write_mask | (0x1 << i); } // Shift Value startbits to the left value = value << start_bit; comedi_dio_bitfield(myCard->getDevice()->it, subDevice, write_mask, &value); } }