/* * libiio - Library for interfacing industrial I/O (IIO) devices * * Copyright (C) 2015 Analog Devices, Inc. * Author: Paul Cercueil * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * */ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace iio { /// class: /// Contains the representation of a channel or device attribute. public abstract class Attr { /// The name of this attribute. public readonly string name; /// The filename in sysfs to which this attribute is bound. public readonly string filename; internal Attr(string name, string filename = null) { this.filename = filename == null ? name : filename; this.name = name; } /// Read the value of this attribute as a string. /// The attribute could not be read. public abstract string read(); /// Set this attribute to the value contained in the string argument. /// The string value to set the parameter to. /// The attribute could not be written. public abstract void write(string val); /// Read the value of this attribute as a bool. /// The attribute could not be read. public bool read_bool() { string val = read(); return (val.CompareTo("1") == 0) || (val.CompareTo("Y") == 0); } /// Read the value of this attribute as a double. /// The attribute could not be read. public double read_double() { return double.Parse(read(), CultureInfo.InvariantCulture); } /// Read the value of this attribute as a long. /// The attribute could not be read. public long read_long() { return long.Parse(read(), CultureInfo.InvariantCulture); } /// Set this attribute to the value contained in the bool argument. /// The bool value to set the parameter to. /// The attribute could not be written. public void write(bool val) { if (val) write("1"); else write("0"); } /// Set this attribute to the value contained in the long argument. /// The long value to set the parameter to. /// The attribute could not be written. public void write(long val) { write(val.ToString(CultureInfo.InvariantCulture)); } /// Set this attribute to the value contained in the double argument. /// The double value to set the parameter to. /// The attribute could not be written. public void write(double val) { write(val.ToString(CultureInfo.InvariantCulture)); } } }