-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriListSerializer.cs
More file actions
39 lines (35 loc) · 1.66 KB
/
TriListSerializer.cs
File metadata and controls
39 lines (35 loc) · 1.66 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharpPro;
namespace Crestron_TCP_Buttons {
public class TriListSerializer {
private static String repr(Sig sig) {
String direction = sig.IsInput ? "INPUT" : "OUTPUT";
switch(sig.Type) {
case eSigType.Bool:
return "DIGITAL_" + direction + "<" + sig.Number + ">=(" + sig.BoolValue + ")";
case eSigType.UShort:
return "ANALOG_" + direction + "<" + sig.Number + ">=(" + sig.UShortValue + ")";
case eSigType.String:
return "SERIAL_" + direction + "<" + sig.Number + ">=(" + sig.StringValue + ")";
default:
throw new Exception("Could not represent unknown signal type.");
}
}
public static String summarize(BasicTriList triList) {
StringBuilder sb = new StringBuilder();
foreach(Sig sig in triList.BooleanInput) { sb.Append(repr(sig) + "\n"); }
foreach(Sig sig in triList.BooleanOutput) { sb.Append(repr(sig) + "\n"); }
foreach(Sig sig in triList.UShortInput) { sb.Append(repr(sig) + "\n"); }
foreach(Sig sig in triList.UShortOutput) { sb.Append(repr(sig) + "\n"); }
foreach(Sig sig in triList.StringInput) { sb.Append(repr(sig) + "\n"); }
foreach(Sig sig in triList.StringOutput) { sb.Append(repr(sig) + "\n"); }
sb.Append("\n");
return sb.ToString();
}
}
}