-
Notifications
You must be signed in to change notification settings - Fork 0
/
VoltageReader.cs
34 lines (30 loc) · 1.13 KB
/
VoltageReader.cs
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
using System;
using Phidget22;
using Phidget22.Events;
namespace PhidgetBridgeReader
{
public class VoltageReader
{
private event Action<double> NewVoltage;
private VoltageRatioInput input;
private int dataIntervalMs;
public VoltageReader(int channel, Action<double> onNewVoltage, int dataIntervalMs = 10) {
this.dataIntervalMs = dataIntervalMs;
this.NewVoltage += onNewVoltage;
input = new VoltageRatioInput();
input.Channel = channel;
input.Close();
input.Open();
input.Attach += OnAttach;
}
private void OnAttach(object sender, AttachEventArgs e) {
input.DataInterval = this.dataIntervalMs;
input.VoltageRatioChangeTrigger = 0;
Console.WriteLine("Attached on channel " + input.Channel + " data interval " + input.DataInterval + "ms");
input.VoltageRatioChange += OnVoltageChange;
}
private void OnVoltageChange(object sender, VoltageRatioInputVoltageRatioChangeEventArgs e) {
NewVoltage?.Invoke(input.VoltageRatio);
}
}
}