1
|
//------------------------------------------------------------------------------
|
2
|
// Main Function
|
3
|
//------------------------------------------------------------------------------
|
4
|
void main(string argument){
|
5
|
|
6
|
// SAMPLE //
|
7
|
|
8
|
IMySolarPanel solar = GridTerminalSystem.GetBlockWithName("Solar Panel Name") as IMySolarPanel;
|
9
|
|
10
|
SolarPanelInfoGetter solarInfo = new SolarPanelInfoGetter(solar);
|
11
|
|
12
|
// get max output
|
13
|
float max = solarInfo.GetMaxOutput();
|
14
|
|
15
|
// get current output
|
16
|
float cur = solarInfo.GetCurrentOutput();
|
17
|
|
18
|
}
|
19
|
|
20
|
//------------------------------------------------------------------------------
|
21
|
// SolarPanelInfoGetter Class
|
22
|
//------------------------------------------------------------------------------
|
23
|
class SolarPanelInfoGetter {
|
24
|
|
25
|
IMySolarPanel mySolar;
|
26
|
|
27
|
//--------------------------------------------------------------------------
|
28
|
SolarPanel(IMySolarPanel solarPanel){
|
29
|
mySolar = solarPanel;
|
30
|
}
|
31
|
|
32
|
//--------------------------------------------------------------------------
|
33
|
public float GetMaxOutput(){
|
34
|
return GetKiloWatt(mySolar.DetailedInfo).Split(new string[] {"\n"}, StringSplitOptions.None)[1];
|
35
|
}
|
36
|
|
37
|
//--------------------------------------------------------------------------
|
38
|
public float GetCurrentOutput(){
|
39
|
return GetKiloWatt(mySolar.DetailedInfo).Split(new string[] {"\n"}, StringSplitOptions.None)[2];
|
40
|
}
|
41
|
|
42
|
//--------------------------------------------------------------------------
|
43
|
private float GetKiloWatt(string infoText){
|
44
|
float value = Convert.ToSingle(infoText.Split(' ')[2]);
|
45
|
string unit = infoText.Split(' ')[3];
|
46
|
|
47
|
if(unit == "W"){
|
48
|
value /= 1000;
|
49
|
}
|
50
|
else if(unit == "MW"){
|
51
|
value *= 1000;
|
52
|
}
|
53
|
|
54
|
return value;
|
55
|
}
|
56
|
|
57
|
//--------------------------------------------------------------------------
|
58
|
|
59
|
}
|
60
|
|
61
|
|
62
|
|
63
|
|
64
|
|