Example #1
0
int io_init(ElevatorType type){

    elevatorType = type;
    
    switch(elevatorType){
    case ET_comedi:
        it_g = comedi_open("/dev/comedi0");
      
        if (it_g == NULL) {
            return 0;
        }

        int status = 0;
        for (int i = 0; i < 8; i++) {
            status |= comedi_dio_config(it_g, PORT_1_SUBDEVICE, i + PORT_1_CHANNEL_OFFSET, PORT_1_DIRECTION);
            status |= comedi_dio_config(it_g, PORT_2_SUBDEVICE, i + PORT_2_CHANNEL_OFFSET, PORT_2_DIRECTION);
            status |= comedi_dio_config(it_g, PORT_3_SUBDEVICE, i + PORT_3_CHANNEL_OFFSET, PORT_3_DIRECTION);
            status |= comedi_dio_config(it_g, PORT_4_SUBDEVICE, i + PORT_4_CHANNEL_OFFSET, PORT_4_DIRECTION);
        }
        return (status == 0);
    
    case ET_simulation:
        //simulation_elevator_start();
        return 1;
        
    default:
        return 0;
    }
}
Example #2
0
int io_init()
{
	int i;
	int res;

	it_g = comedi_open("/dev/comedi0");

	if (it_g == NULL) return -1;

	// init 3 inputs and 3 outputs
	for(i=1; i<4; i++)
	{
		res = comedi_dio_config(it_g, IO_DEV, DI(i), COMEDI_INPUT);
		if (res<0) return res;
		res = comedi_dio_config(it_g, IO_DEV, DO(i), COMEDI_OUTPUT);
		if (res<0) return res;
		res = comedi_dio_write(it_g, IO_DEV, DO(i), 0);
		if (res<0) return res;
	}

	// set outputs to high
	for(i=1; i<4; i++)
	{
		comedi_dio_write(it_g, IO_DEV, DO(i), 1);
	}

	return 1;
}
    void ComediSubDeviceDOut::init(bool all_bits)
    {
        Logger::In in( nameserver.getName( this ).c_str() );
        if (!myCard) {
            log(Error) << "Error creating ComediSubDeviceDOut: null ComediDevice given." <<endlog();
            return;
        }
        if ( ( myCard->getSubDeviceType( subDevice ) != COMEDI_SUBD_DO ) &&
             ( myCard->getSubDeviceType( subDevice ) != COMEDI_SUBD_DIO) )
            {
                Logger::In in("ComediSubDeviceDOut");
                log(Error) << "SubDevice "<< subDevice <<" is not a digital output:";
                log() << "type = " << myCard->getSubDeviceType( subDevice ) << endlog();
                // channels remains '0'.
                return;
            }

        channels = comedi_get_n_channels(myCard->getDevice()->it, subDevice);

        // Only for DIO
        if ( ( myCard->getSubDeviceType( subDevice ) == COMEDI_SUBD_DIO) && all_bits) {
            log(Info) << "Configuring first "<<channels<<" dio channels on subdevice "<<subDevice<<" as output type." << endlog();

            for (unsigned int i=0; i<channels; ++i)
                comedi_dio_config(myCard->getDevice()->it, subDevice, i, COMEDI_OUTPUT);
        } else {
            log(Info) << "Subdevice "<<subDevice<<" is digital output with "<<channels << " channels." << endlog();
        }


    }
Example #4
0
bool ComediDigitalInput::initialise()
{
	// set as input channel
	if(!(comedi_dio_config(m_device,m_subdevice,m_channels[0],COMEDI_INPUT))==0)
		Logger(Critical, "ComediDigitalInput::initialise() - Config error: %s.\n",comedi_strerror(comedi_errno()));
	return true;	

}
Example #5
0
File: sigio.c Project: jbetten/rtxi
void config_output(void)
{
	int i;

	for(i=0;i<8;i++){
		comedi_dio_config(device,out_subd,i,COMEDI_OUTPUT);
	}
}
Example #6
0
int io_init()
{
	int i, status = 0;

	it_g = comedi_open("/dev/comedi0");
  
	if (it_g == NULL)
		return 0;

	for (i = 0; i < 8; i++) {
		status |= comedi_dio_config(it_g, PORT1, i, COMEDI_INPUT);
		status |= comedi_dio_config(it_g, PORT2, i, COMEDI_OUTPUT);
		status |= comedi_dio_config(it_g, PORT3, i+8, COMEDI_OUTPUT);
		status |= comedi_dio_config(it_g, PORT4, i+16, COMEDI_INPUT);
	}

	return (status == 0);
}
Example #7
0
int io_init(void) {

    it_g = comedi_open("/dev/comedi0");

    if (it_g == NULL) {
        return 0;
    }

    int status = 0;
    for (int i = 0; i < 8; i++) {
        status |= comedi_dio_config(it_g, PORT_1_SUBDEVICE, i + PORT_1_CHANNEL_OFFSET, PORT_1_DIRECTION);
        status |= comedi_dio_config(it_g, PORT_2_SUBDEVICE, i + PORT_2_CHANNEL_OFFSET, PORT_2_DIRECTION);
        status |= comedi_dio_config(it_g, PORT_3_SUBDEVICE, i + PORT_3_CHANNEL_OFFSET, PORT_3_DIRECTION);
        status |= comedi_dio_config(it_g, PORT_4_SUBDEVICE, i + PORT_4_CHANNEL_OFFSET, PORT_4_DIRECTION);
    }

    return (status == 0);
}
Example #8
0
static void dio_config( void )
{
	comedi_t *dev = lookup_dev( *sp++ );
	unsigned int subdev = *sp++;
	unsigned int chan = *sp++;
	unsigned int data = *sp++;
	int c = comedi_dio_config( dev, subdev, chan, data );
	if( c < 1 ) comedi_perror( "<dio> " );
}
Example #9
0
int main(int argc, char *argv[])
{
	int ret;
	int stype;
	int i;
	struct parsed_options options;

	init_parsed_options(&options);
	options.subdevice = -1;
	parse_options(&options, argc, argv);

	device = comedi_open(options.filename);
	if(!device){
		comedi_perror(options.filename);
		exit(-1);
	}
	if(options.subdevice < 0)
	{
		options.subdevice = comedi_find_subdevice_by_type(device, COMEDI_SUBD_DIO, 0);
		if(options.subdevice < 0){
			fprintf(stderr,"No dio subdevice found.\n");
			exit(-1);
		}
	}
	stype = comedi_get_subdevice_type(device, options.subdevice);
	if(stype != COMEDI_SUBD_DIO){
		printf("%d is not a digital I/O subdevice\n", options.subdevice);
		exit(-1);
	}

	printf("configuring pin %d for output...\n", chan_dat);
	ret = comedi_dio_config(device, options.subdevice, chan_dat, COMEDI_OUTPUT);

	printf("configuring pin %d for output...\n", chan_clk);
	ret = comedi_dio_config(device, options.subdevice, chan_clk, COMEDI_OUTPUT);

	for(i = 0; i < 0x100; i++){
		write_bits(options.subdevice, i);
	}
	//write_bits(0xa5);

	return 0;
}
void __po_hi_c_driver_exarm_ni_6071e_digital_init (__po_hi_device_id device_id)
{
   int ret;

   po_hi_driver_exarm_ni_6071e_digital_it = comedi_open("/dev/comedi0");

   ret = comedi_dio_config(po_hi_driver_exarm_ni_6071e_digital_it, 2, 1, COMEDI_INPUT);

   if (ret == -1)
   {
      __DEBUGMSG ("Error when invoking comedi_dio_config()");
   }

   ret = comedi_dio_config(po_hi_driver_exarm_ni_6071e_digital_it, 2, 0, COMEDI_INPUT);

   if (ret == -1)
   {
      __DEBUGMSG ("Error when invoking comedi_dio_config()");
   }

   return;
}
Example #11
0
int main(int argc, char *argv[])
{
	int ret;
	int stype;
	struct parsed_options options;

	init_parsed_options(&options);
	parse_options(&options, argc, argv);

	device = comedi_open(options.filename);
	if(!device){
		comedi_perror(options.filename);
		exit(-1);
	}

	stype = comedi_get_subdevice_type(device, options.subdevice);
	if(stype != COMEDI_SUBD_DIO){
		printf("%d is not a digital I/O subdevice\n", options.subdevice);
		exit(-1);
	}

	printf("configuring pin %d on subdevice %d ", options.channel, options.subdevice);
	if(options.value)
	{
		printf("for output.\n");
		ret = comedi_dio_config(device, options.subdevice, options.channel, COMEDI_OUTPUT);
	}else
	{
		printf("for input.\n");
		ret = comedi_dio_config(device, options.subdevice, options.channel, COMEDI_INPUT);
	}
	if(ret < 0){
		comedi_perror("comedi_dio_config");
		exit(-1);
	}
	return 0;
}
Example #12
0
bool ComediDigitalOutput::initialise()
{
	// set as output
	
	if(!(comedi_dio_config(m_device, m_subdevice, m_channels[0],COMEDI_OUTPUT))==0) {
		Logger(Critical, "ComediDigitalOutput::initialise() - Config error: %s.\n",comedi_strerror(comedi_errno()));
		return false;
	}
	if(!(comedi_set_routing(m_device, m_subdevice, m_channels[0], NI_PFI_OUTPUT_PFI_DO))==0) {
		Logger(Critical, "ComediDigitalOutput::initialise() - Routing error: %s.\n",comedi_strerror(comedi_errno()));
		return false;
	}
	return true;	

}
extern uchar init(char* dev) {
    uint i, nchan;
    ni = comedi_open(dev);
    if (ni == NULL) {
        printf("Error opening device\n");
        return -1;
    }
    nchan = comedi_get_n_channels(ni, 0);
    printf("found comedi system with %d channels\n", nchan);
    for (i=0; i < nchan; i++) {
        if (comedi_dio_config(ni, 0, i, COMEDI_OUTPUT) < 0)
            return -1;
    }
    return 0;
}
Example #14
0
/** set this to a write (output) device -- note that this only does something for DIO chans in non-daq-task mode.  
  */
void ComediChan::setDIOOutput()
{
  if (m_isdio && !daq)
    comedi_dio_config(m_dev, m_subdev, m_chan, COMEDI_OUTPUT);
}
Example #15
0
int set_dio_input(int chan) {
    return comedi_dio_config(it,
            subdev_dio,
            chan,
            COMEDI_INPUT);
}
Example #16
0
 bool ComediSubDeviceDIn::useBit( unsigned int bit )
 {
     return comedi_dio_config(myCard->getDevice()->it, _subDevice, bit, COMEDI_INPUT) == 0;
 }