User Tools

Site Tools


zalozeni:logika:init

init()

Jedna se o metodu, ktera by se mela volat pri prechodu do ExperimentuStatus.RUNNING. Existuji celkem 3 metody v ExperimentLogic, ktere k tomu mohou vest: preRun(), postPaused() a postChashed(). V teto metode se inicalizuje vse, co je treba pro bezproblemovy prubeh mereni.

Samotna inicializace se sestava ze dvou kroku

  1. inicializace service
  2. inicializace pristroje

Inicializace service

Tuto inicializaci doporucuji provest v metode setExpInstance. Jedna se o pretypovani instrumentu (ten je definovan jiz v super.setExpInstance(expInstance)), definovani nastaveni pro zvolenou ExperimentInstance, tj. instanceSS a servicu pro ukladani dat k dane ExperimentInstance, tj dataService.

	private DokuwikiInstrument instrument;
	private DokuwikiExpInstanceSettignsService instanceSS;
	private DokuwikiDataService dataService;
 
	@Override
	public void setExpInstance(ExperimentInstance expInstance) {
		super.setExpInstance(expInstance);
 
		instrument = (DokuwikiInstrument) instrument;
		instanceSS = (DokuwikiExpInstanceSettignsService) expInstance.getSettignsService();
		dataService = (DokuwikiDataService) expInstance.getDataService();
	}

Inicializace mereni

Tato inicializace je komplikovanejsi a zpravidla jsem ji umistoval do privatni metody init(). Pokud vse probehno v poradku, mela by vratit ChangingStatusReturnCode.OK. V opacnem pripade vrati ChangingStatusReturnCode.ERROR (chyba s pripojenim k Device nebo behem inicializace jednotlivych DokuwikiRunningSubstatus). Tato metoda provadi

  1. inicializaci jednotlivych observeru
  2. inicializaci intervalu pro vycitan/ukladani udaju a tick s hodnotou posledniho vycteni/ulozeni jako aktualni cas
  3. reset counteru pro consecutive errors
  4. nacteni nastaveni z instanceSS, v tomto pripade startovaci teploty
  5. nacteni aktualni runningSubstatus
  6. pripojeni k jednotlivym Device na instrumentu
  7. v zavislosti na runningSubstatus inicializace prislusne faze mereni (je popsana v dalsim kroce).
	private DokuwikiTempObserver tempObserver;
	private DokuwikiCounterObserver counterObserver;
 
	private long lastReadOutTick;
	private long lastPersistTick;
	private long intervalReadOut;
	private long intervalPersist;
 
	private int consecutiveErrorCount = 0;
	private final static int MAX_CONSECUTIVE_ERRORS = 5;
 
	private double startTemp;
	private DokuwikiRunningSubstatus runningSubstatus;
 
	private ChangingStatusReturnCode init() {
		tempObserver = new DokuwikiTempObserver(expInstance);
		counterObserver = new DokuwikiCounterObserver(expInstance);
 
		lastReadOutTick = System.currentTimeMillis();
		lastPersistTick = System.currentTimeMillis();
 
		intervalReadOut = instanceSS.getIntervalReadOut();
		intervalPersist = instanceSS.getIntervalPersist();
 
		consecutiveErrorCount = 0;
 
		startTemp = instanceSS.getStartT();
		runningSubstatus = instanceSS.getRunningSubstatus();
 
		try {
			instrument.getEurotherm().connect();
		} catch (ConnectException e) {
			LogService.getInstance().error("ConnectException while connecting to Eurothoerm");
			e.printStackTrace();
			return ChangingStatusReturnCode.ERROR;
		} catch (Exception e) {
			LogService.getInstance().error("Unknown Exception while connecting to Eurothoerm");
			e.printStackTrace();
			return ChangingStatusReturnCode.ERROR;
		}
 
		try {
			instrument.getLabjack().connect();
		} catch (ConnectException e) {
			LogService.getInstance().error("ConnectException while connecting to LabJack");
			e.printStackTrace();
			return ChangingStatusReturnCode.ERROR;
		} catch (Exception e) {
			LogService.getInstance().error("Unknown Exception while connecting to LabJack");
			e.printStackTrace();
			return ChangingStatusReturnCode.ERROR;
		}
 
		switch (runningSubstatus) {
		case PREPARATION:
			return initSamplePreparation();
		case RUNNING:
			return initRunning();
		case FINISHED:
			return initFinished();
		default:
			break;
		}
 
		return ChangingStatusReturnCode.OK;
	}
zalozeni/logika/init.txt · Last modified: 2016/08/01 08:59 by jlochman