1 /*
2  * libiio - Library for interfacing industrial I/O (IIO) devices
3  *
4  * Copyright (C) 2015 Analog Devices, Inc.
5  * Author: Paul Cercueil <paul.cercueil@analog.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * */
18 
19 using System;
20 using System.Collections.Generic;
21 using System.Linq;
22 using System.Runtime.InteropServices;
23 using System.Text;
24 using System.Threading.Tasks;
25 
26 namespace iio
27 {
28     /// <summary><see cref="iio.Trigger"/> class:
29     /// Contains the representation of an IIO device that can act as a trigger.</summary>
30     public class Trigger : Device
31     {
Trigger(Context ctx, IntPtr ptr)32         internal Trigger(Context ctx, IntPtr ptr) : base(ctx, ptr) { }
33 
34         /// <summary>Configure a new frequency for this trigger.</summary>
35         /// <exception cref="System.Exception">The new frequency could not be set.</exception>
set_rate(ulong rate)36         public void set_rate(ulong rate)
37         {
38             foreach (Attr each in attrs)
39             {
40                 if (each.name.Equals("frequency"))
41                 {
42                     each.write((long) rate);
43                     return;
44                 }
45             }
46             throw new Exception("Trigger has no frequency?");
47         }
48 
49         /// <summary>Get the currently configured frequency of this trigger.</summary>
50         /// <exception cref="System.Exception">The configured frequency could not be obtained.</exception>
get_rate()51         public ulong get_rate()
52         {
53             foreach (Attr each in attrs)
54             {
55                 if (each.name.Equals("frequency"))
56                 {
57                     return (ulong) each.read_long();
58                 }
59             }
60             throw new Exception("Trigger has no frequency?");
61         }
62 
63         /// <summary>Set Trigger.</summary>
set_trigger(Trigger trig)64         public new void set_trigger(Trigger trig)
65         {
66             throw new InvalidComObjectException("Device is already a trigger");
67         }
68 
69         /// <summary>Get trigger.</summary>
get_trigger()70         public new Trigger get_trigger()
71         {
72             throw new InvalidComObjectException("Device is already a trigger");
73         }
74     }
75 }
76