summaryrefslogtreecommitdiff
path: root/src/bindings/csharp/Trigger.cs
blob: 4614143bcb03b1b6540a832be9f480008c907cc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * libiio - Library for interfacing industrial I/O (IIO) devices
 *
 * Copyright (C) 2015 Analog Devices, Inc.
 * Author: Paul Cercueil <paul.cercueil@analog.com>
 *
 * 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.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace iio
{
    /// <summary><see cref="iio.Trigger"/> class:
    /// Contains the representation of an IIO device that can act as a trigger.</summary>
    public class Trigger : Device
    {
        internal Trigger(Context ctx, IntPtr ptr) : base(ctx, ptr) { }

        /// <summary>Configure a new frequency for this trigger.</summary>
        /// <exception cref="System.Exception">The new frequency could not be set.</exception>
        public void set_rate(ulong rate)
        {
            foreach (Attr each in attrs)
                if (each.name.Equals("frequency"))
                {
                    each.write((long) rate);
                    return;
                }
            throw new Exception("Trigger has no frequency?");
        }

        /// <summary>Get the currently configured frequency of this trigger.</summary>
        /// <exception cref="System.Exception">The configured frequency could not be obtained.</exception>
        public ulong get_rate()
        {
            foreach (Attr each in attrs)
                if (each.name.Equals("frequency"))
                    return (ulong) each.read_long();
            throw new Exception("Trigger has no frequency?");
        }

        public new void set_trigger(Trigger trig)
        {
            throw new InvalidComObjectException("Device is already a trigger");
        }

        public new Trigger get_trigger()
        {
            throw new InvalidComObjectException("Device is already a trigger");
        }
    }
}