<commit_before><commit_msg>Added handling of modbus outputs<commit_after>package com.ptoceti.osgi.modbusdevice.impl;

import java.util.Date;
import java.util.Vector;

import org.osgi.util.measurement.State;

import com.ptoceti.osgi.control.Switch;

public class ModbusSwitch extends ModbusData {


	public ModbusSwitch(String identification, String scope, int adress, int lenght ){
		
		dataIdentification = identification;
		dataScope = scope;
		this.adress = adress;
		this.length = lenght;
		
	}

	public ModbusSwitch(Vector switchSettings) throws Exception {
	
		try {
		
			dataIdentification = (String)(switchSettings.get(0));
			dataScope = (String)(switchSettings.get(1));
			adress = ((Integer)(switchSettings.get(2))).intValue();
			length = ((Integer)(switchSettings.get(3))).intValue();
			
		} catch (ArrayIndexOutOfBoundsException e ) {
			Exception ne = new Exception("Error reading settings parameters.");
			throw(ne);
		}
	}
	
	public Object getValue() {
	
		int data = bufferDelegate.read( adress, length);
		
		Switch switchData = new Switch(data > 0 ? true : false);
		
		return switchData;
	}

	@Override
	public void setValue(Object value) {
		bufferDelegate.write(adress, length, ((Switch) value).getState() == true ? 1 : 0);
	}
}
{'fraction_non_alphanumeric': 0.12121212121212122, 'fraction_numerical': 0.005582137161084529, 'mean_word_length': 4.4094827586206895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3756299', 'n_tokens_mistral': 433, 'n_tokens_neox': 378, 'n_words': 90}