Diff of /trunk/d-logg/d-logg.library.md [000000] .. [r3]  Maximize  Restore

Switch to unified view

a b/trunk/d-logg/d-logg.library.md
1
---
2
3
~~~ST
4
FUNCTION_BLOCK DLogg
5
VAR_INPUT
6
    udtInput: IoDrvInput;
7
    udtConfig: IoDrvConfig;
8
END_VAR
9
VAR_OUTPUT
10
    udtOutput: IoDrvOutput;
11
END_VAR
12
VAR
13
    stream: SerialStream;
14
    i: LINT;
15
    byByte: BYTE;
16
    nRead: UDINT;
17
    nWrote: ULINT;
18
    dwState: DWORD;
19
    udiNumDL: UDINT;
20
    audtSensor: ARRAY [..] OF ;
21
    audtSolar1: ARRAY [..] OF ;
22
    audtSolar2: ARRAY [..] OF ;
23
    byChecksum: BYTE;
24
    Delay: TON;
25
END_VAR
26
27
~~~
28
~~~ST
29
// Execute the FB only every second
30
// Quicker sampling is not supported by the logger
31
Delay(IN:=TRUE, PT:=T#1S);
32
IF NOT(Delay.Q) THEN
33
    RETURN;
34
END_IF
35
Delay(IN:=FALSE);
36
37
// Start with the state machine
38
CASE dwState OF
39
    0:  stream.Open(1, 115200);
40
        next();
41
    // Read number of data loggers
42
    1:  nWrote := stream.WriteByte(16#81);
43
        IF nWrote = 1 THEN  
44
            next();
45
        END_IF
46
    2:  IF stream.Length >= 1 THEN
47
            stream.Read(ADR(byByte), 1);
48
            CASE byByte OF
49
                16#A8: udiNumDL := 1;
50
                16#D1: udiNumDL := 2;
51
            END_CASE
52
            next();
53
        END_IF
54
    // Read Data-Logger Type (also polls for new data)
55
    3:  nWrote := stream.WriteByte(16#AB);
56
        IF nWrote = 1 THEN  
57
            next();
58
        END_IF
59
    4:  IF stream.Length >= 1 THEN
60
            byByte := stream.ReadByte();
61
            CASE byByte OF
62
                16#AB: reset(); // no new data
63
                16#80: next(); // UVR1611
64
                16#90: next(); // UVR61-3
65
            END_CASE
66
        END_IF
67
    // Read sensor data
68
    5:  IF stream.Length >= (39 + 16 + 1) * udiNumDL THEN
69
            FOR i:=0 TO udiNumDL-1 DO
70
                stream.Read(ADR(audtSensor[i]), 39);
71
                stream.Read(ADR(audtSolar1[i]), 8);
72
                stream.Read(ADR(audtSolar2[i]), 8);
73
                byChecksum := stream.ReadByte();
74
            END_FOR
75
            next();
76
        END_IF
77
    // Convert RAW data to temperatures and boolean actor data
78
    6:  udtInput.C0_S1  := THIS^.raw2temp(audtSensor[0].auiTemperature[0]);
79
        udtInput.C0_S2  := THIS^.raw2temp(audtSensor[0].auiTemperature[1]);
80
        udtInput.C0_S3  := THIS^.raw2temp(audtSensor[0].auiTemperature[2]);
81
        udtInput.C0_S4  := THIS^.raw2temp(audtSensor[0].auiTemperature[3]);
82
        udtInput.C0_S5  := THIS^.raw2temp(audtSensor[0].auiTemperature[4]);
83
        udtInput.C0_S6  := THIS^.raw2temp(audtSensor[0].auiTemperature[5]);
84
        udtInput.C0_S7  := THIS^.raw2temp(audtSensor[0].auiTemperature[6]);
85
        udtInput.C0_S8  := THIS^.raw2temp(audtSensor[0].auiTemperature[7]);
86
        udtInput.C0_S9  := THIS^.raw2temp(audtSensor[0].auiTemperature[8]);
87
        udtInput.C0_S10 := THIS^.raw2temp(audtSensor[0].auiTemperature[9]);
88
        udtInput.C0_S11 := THIS^.raw2temp(audtSensor[0].auiTemperature[10]);
89
        udtInput.C0_S12 := THIS^.raw2temp(audtSensor[0].auiTemperature[11]);
90
        udtInput.C0_S13 := THIS^.raw2temp(audtSensor[0].auiTemperature[12]);
91
        udtInput.C0_S14 := THIS^.raw2temp(audtSensor[0].auiTemperature[13]);
92
        udtInput.C0_S15 := THIS^.raw2temp(audtSensor[0].auiTemperature[14]);
93
        udtInput.C0_S16 := THIS^.raw2temp(audtSensor[0].auiTemperature[15]);
94
        udtInput.C1_S1  := THIS^.raw2temp(audtSensor[1].auiTemperature[0]);
95
        udtInput.C1_S2  := THIS^.raw2temp(audtSensor[1].auiTemperature[1]);
96
        udtInput.C1_S3  := THIS^.raw2temp(audtSensor[1].auiTemperature[2]);
97
        udtInput.C1_S4  := THIS^.raw2temp(audtSensor[1].auiTemperature[3]);
98
        udtInput.C1_S5  := THIS^.raw2temp(audtSensor[1].auiTemperature[4]);
99
        udtInput.C1_S6  := THIS^.raw2temp(audtSensor[1].auiTemperature[5]);
100
        udtInput.C1_S7  := THIS^.raw2temp(audtSensor[1].auiTemperature[6]);
101
        udtInput.C1_S8  := THIS^.raw2temp(audtSensor[1].auiTemperature[7]);
102
        udtInput.C1_S9  := THIS^.raw2temp(audtSensor[1].auiTemperature[8]);
103
        udtInput.C1_S10 := THIS^.raw2temp(audtSensor[1].auiTemperature[9]);
104
        udtInput.C1_S11 := THIS^.raw2temp(audtSensor[1].auiTemperature[10]);
105
        udtInput.C1_S12 := THIS^.raw2temp(audtSensor[1].auiTemperature[11]);
106
        udtInput.C1_S13 := THIS^.raw2temp(audtSensor[1].auiTemperature[12]);
107
        udtInput.C1_S14 := THIS^.raw2temp(audtSensor[1].auiTemperature[13]);
108
        udtInput.C1_S15 := THIS^.raw2temp(audtSensor[1].auiTemperature[14]);
109
        udtInput.C1_S16 := THIS^.raw2temp(audtSensor[1].auiTemperature[15]);
110
        
111
        udtInput.C0_A0 := audtSensor[0].abyDOUT[0];
112
        udtInput.C0_A1 := audtSensor[0].abyDOUT[1];
113
        udtInput.C1_A0 := audtSensor[1].abyDOUT[0];
114
        udtInput.C1_A1 := audtSensor[1].abyDOUT[1];
115
        
116
        next();
117
    // End
118
    7:  reset();
119
            
120
END_CASE
121
122
~~~
123
---
124
~~~ST
125
METHOD raw2temp: REAL
126
VAR_INPUT
127
    raw: WORD;
128
END_VAR
129
VAR
130
    tmp: INT;
131
END_VAR
132
133
~~~
134
~~~ST
135
tmp := WORD_TO_INT(raw AND 16#8000);
136
tmp := SHR(tmp, 3);
137
tmp := UINT_TO_INT(WORD_TO_UINT(raw AND 16#0FFF) OR INT_TO_UINT(tmp));
138
raw2temp := tmp / 10;
139
140
~~~
141
VAR_GLOBAL
142
    cClassID: DWORD;
143
    cDriverName: string;
144
    cDeviceName: string;
145
    cVendorName: string;
146
    cModuleType: WORD;
147
END_VAR