-
Notifications
You must be signed in to change notification settings - Fork 0
/
Multiple Digital Diagnostic Send.usp
135 lines (118 loc) · 3.7 KB
/
Multiple Digital Diagnostic Send.usp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*******************************************************************************************
SIMPL+ Module Information
*******************************************************************************************/
/*
# MIT License
#
# Copyright (c) 2024 Michael Caldwell-Waller (@chipguyhere)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# This copyright notice and this permission notice are not required to appear in the
# binary (executable/object/compiled) copy of a project.
*/
/*******************************************************************************************
Compiler Directives
*******************************************************************************************/
// #ENABLE_DYNAMIC
// #SYMBOL_NAME ""
// #HINT ""
// #DEFINE_CONSTANT
// #CATEGORY ""
// #PRINT_TO_TRACE
// #DIGITAL_EXPAND
// #ANALOG_SERIAL_EXPAND
// #OUTPUT_SHIFT
// #HELP_PDF_FILE ""
#DEFAULT_NONVOLATILE
#ENABLE_STACK_CHECKING
#ENABLE_TRACE
// #ENCODING_ASCII
// #ENCODING_UTF16
// #ENCODING_INHERIT_FROM_PARENT
// #ENCODING_INHERIT_FROM_PROGRAM
/*
#HELP_BEGIN
(add additional lines of help lines)
#HELP_END
*/
DIGITAL_INPUT Enable;
DIGITAL_INPUT Send[48];
// ANALOG_INPUT
STRING_PARAMETER _SKIP_, StringToSend[48][200];
// BUFFER_INPUT
// DIGITAL_OUTPUT
// ANALOG_OUTPUT
STRING_OUTPUT Output;
INTEGER Deferred[48];
INTEGER HasHadInput[48];
INTEGER HasStartedUp;
INTEGER LastSent;
// LONG_INTEGER
// SIGNED_INTEGER
// SIGNED_LONG_INTEGER
// STRING
/*******************************************************************************************
Functions
*******************************************************************************************/
Function OnWaitExpired()
{
INTEGER X;
if (Enable=0) return;
if (LastSent=48) return;
LastSent = LastSent + 1;
FOR (X = LastSent TO 48) {
if (IsSignalDefined(Send[X]) && Deferred[X]=1) {
Output = ":" + StringToSend[X] + "=" + ItoA(Send[X]) + "\r\n";
LastSent = X;
WAIT(Random(5,35)) OnWaitExpired();
return;
}
}
LastSent = 48;
}
/*******************************************************************************************
Event Handlers
*******************************************************************************************/
PUSH Enable
{
INTEGER X;
FOR (X = 1 TO 48) Deferred[X]=1;
LastSent=0;
WAIT (100 + Random(0,400)) OnWaitExpired();
}
RELEASE Enable
{
CANCELALLWAIT();
}
PUSH Send
RELEASE Send
{
INTEGER InputSelect;
InputSelect = GetLastModifiedArrayIndex();
HasHadInput[InputSelect]=1;
Deferred[InputSelect]=0;
Output = "!" + StringToSend[InputSelect] + "=" + ItoA(Send[InputSelect]) + "\r\n";
}
Function Main()
{
INTEGER X;
WaitForInitializationComplete();
HasStartedUp=1;
}