import comedi.ComediOptions;
import comediJNI.Comedi;
import comediJNI.ComediDef;
import comediJNI.ComediJNIException;

import otherSupport.SettingsManager;

/*
 * Digital I/O example
 * Part of Comedilib
 *
 * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
 *
 * This file may be freely modified, distributed, and combined with
 * other software, as long as proper attribution is given in the
 * source code.
 */
/*
 * Requirements:  A board with a digital I/O subdevice.  Not just
 *    a 'digital input' or 'digital output' subdevice, but one in
 *    which the channels can be configured between input and output.
 */

public class dio {
	static { new SettingsManager("minerva", true); 	}

	public static void main(String[] args) {
	
		int ret;
		int stype;
		long dev;
		
		ComediOptions options = new ComediOptions();

		//init_parsed_options(&options);
		//parse_options(&options, argc, argv);
		options.fileName = "/dev/comedi0_subd2";
		options.subdevice = 2;
		options.n_chan = 1;		
		options.channel = 1;
		options.value = 1; //output
		
		//options.range = 0;
		//options.aref = ComediDef.AREF_GROUND;
		//options.n_scan = 1000;
		//options.freq = 1000.0;
		//options.physical = true;

		dev = Comedi.open(options.fileName);
		if(dev == 0)
			throw new ComediJNIException("comedi_open");
		

		stype = Comedi.get_subdevice_type(dev, options.subdevice);
		if(stype != ComediDef.COMEDI_SUBD_DIO)
			throw new RuntimeException(options.subdevice + " is not a digital I/O subdevice");
			

		System.out.print("configuring pin " + options.channel + " on subdevice " + options.subdevice);
		if(options.value != 0) {
			System.out.println(" for output.");
			ret = Comedi.dio_config(dev, options.subdevice, options.channel, ComediDef.COMEDI_OUTPUT);
			
		}else {
			System.out.println(" for input.");
			ret = Comedi.dio_config(dev, options.subdevice, options.channel, ComediDef.COMEDI_INPUT);
		}
	}

}
