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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
#! /usr/bin/perl -w
use cleware;
use Data::Dumper;
sub device_id_to_string
{
my $device_type = $_[0];
if ($device_type eq $cleware::POWER_DEVICE)
{
return "Power";
}
if ($device_type eq $cleware::WATCHDOGXP_DEVICE)
{
return "WatchdogXP";
}
if ($device_type eq $cleware::LED_DEVICE)
{
return "LED";
}
if ($device_type eq $cleware::WATCHDOG_DEVICE)
{
return "Watchdog";
}
if ($device_type eq $cleware::AUTORESET_DEVICE)
{
return "Autoreset device";
}
if ($device_type eq $cleware::SWITCH1_DEVICE)
{
return "Switch1";
}
if ($device_type eq $cleware::SWITCH2_DEVICE)
{
return "Switch2";
}
if ($device_type eq $cleware::SWITCH3_DEVICE)
{
return "Switch3";
}
if ($device_type eq $cleware::SWITCH4_DEVICE)
{
return "Switch4";
}
if ($device_type eq $cleware::SWITCH5_DEVICE)
{
return "Switch5";
}
if ($device_type eq $cleware::SWITCH6_DEVICE)
{
return "Switch6";
}
if ($device_type eq $cleware::SWITCH7_DEVICE)
{
return "Switch7";
}
if ($device_type eq $cleware::SWITCH8_DEVICE)
{
return "Switch8";
}
if ($device_type eq $cleware::SWITCHX_DEVICE)
{
return "SwitchX";
}
if ($device_type eq $cleware::TEMPERATURE_DEVICE)
{
return "Temperature sensor";
}
if ($device_type eq $cleware::TEMPERATURE2_DEVICE)
{
return "Temperature 2 sensor";
}
if ($device_type eq $cleware::TEMPERATURE5_DEVICE)
{
return "Temperature 5 sensor";
}
if ($device_type eq $cleware::HUMIDITY1_DEVICE)
{
return "Humidity sensor";
}
if ($device_type eq $cleware::CONTACT00_DEVICE)
{
return "Contact 00 device";
}
if ($device_type eq $cleware::CONTACT01_DEVICE)
{
return "Contact 01 device";
}
if ($device_type eq $cleware::CONTACT02_DEVICE)
{
return "Contact 02 device";
}
if ($device_type eq $cleware::CONTACT03_DEVICE)
{
return "Contact 03 device";
}
if ($device_type eq $cleware::CONTACT04_DEVICE)
{
return "Contact 04 device";
}
if ($device_type eq $cleware::CONTACT05_DEVICE)
{
return "Contact 05 device";
}
if ($device_type eq $cleware::CONTACT06_DEVICE)
{
return "Contact 06 device";
}
if ($device_type eq $cleware::CONTACT07_DEVICE)
{
return "Contact 07 device";
}
if ($device_type eq $cleware::CONTACT08_DEVICE)
{
return "Contact 08 device";
}
if ($device_type eq $cleware::CONTACT09_DEVICE)
{
return "Contact 09 device";
}
if ($device_type eq $cleware::CONTACT10_DEVICE)
{
return "Contact 10 device";
}
if ($device_type eq $cleware::CONTACT11_DEVICE)
{
return "Contact 11 device";
}
if ($device_type eq $cleware::CONTACT12_DEVICE)
{
return "Contact 12 device";
}
if ($device_type eq $cleware::CONTACT13_DEVICE)
{
return "Contact 13 device";
}
if ($device_type eq $cleware::CONTACT14_DEVICE)
{
return "Contact 14 device";
}
if ($device_type eq $cleware::CONTACT15_DEVICE)
{
return "Contact 15 device";
}
if ($device_type eq $cleware::ENCODER01_DEVICE)
{
return "Encoder 01 device";
}
if ($device_type eq $cleware::F4_DEVICE)
{
return "F4 device";
}
if ($device_type eq $cleware::KEYC01_DEVICE)
{
return "Keyc01 device";
}
if ($device_type eq $cleware::KEYC16_DEVICE)
{
return "Keyc16 device";
}
if ($device_type eq $cleware::ADC0800_DEVICE)
{
return "AC0800 device";
}
if ($device_type eq $cleware::ADC0801_DEVICE)
{
return "AC0801 device";
}
if ($device_type eq $cleware::ADC0802_DEVICE)
{
return "AC0802 device";
}
if ($device_type eq $cleware::ADC0803_DEVICE)
{
return "AC0803 device";
}
if ($device_type eq $cleware::COUNTER00_DEVICE)
{
return "Counter device";
}
if ($device_type eq $cleware::BUTTON_NODEVICE)
{
return "Button no device";
}
return "device type not recognized!"
}
$c = cleware::CUSBaccess->new();
$n_devices = cleware::CUSBaccess::OpenCleware($c);
print "Number of devices: $n_devices\n";
my $i;
for($i=0; $i<$n_devices; $i++)
{
my $devType = cleware::CUSBaccess::GetUSBType($c, $i);
my $devTypeStr = device_id_to_string($devType);
my $version = cleware::CUSBaccess::GetVersion($c, $i);
my $serial = cleware::CUSBaccess::GetSerialNumber($c, $i);
print "device: $i, type: $devTypeStr ($devType), version: $version, serial number: $serial\n";
# these two are not neccessary normally for reading temperatures
# they're here as an example
# rc is 0 for failure, 1 for ok
my $rc;
$rc = cleware::CUSBaccess::ResetDevice($c, $i);
$rc = cleware::CUSBaccess::StartDevice($c, $i);
if ($devType eq $cleware::TEMPERATURE_DEVICE || $devType eq $cleware::TEMPERATURE2_DEVICE || $devType eq $cleware::TEMPERATURE5_DEVICE)
{
my $temperature = cleware::CUSBaccess::GetTemperatureSimple($c, $i);
print "\tcurrent temperature: $temperature\n";
}
if ($devType eq $cleware::HUMIDITY1_DEVICE)
{
my $humidity = cleware::CUSBaccess::GetHumiditySimple($c, $i);
print "\tcurrent humidity: $humidity\n";
}
# Note: the "ampel" (traffic light) is also a switch device, with actually 3 switches (one per light)
if ($devType eq $cleware::SWITCH1_DEVICE || $devType eq $cleware::SWITCH2_DEVICE || $devType eq $cleware::SWITCH3_DEVICE || $devType eq $cleware::SWITCH4_DEVICE || $devType eq $cleware::SWITCH5_DEVICE || $devType eq $cleware::SWITCH6_DEVICE || $devType eq $cleware::SWITCH7_DEVICE || $devType eq $cleware::SWITCH8_DEVICE || $devType eq $cleware::SWITCHX_DEVICE)
{
my $switch_nr = 0; # 0...15
my $state = cleware::CUSBaccess::GetSwitch($c, $i, 16 + $switch_nr);
print "\tswitch $switch_nr state: $state\n";
my $new_state = 1; # 0 or 1
$rc = cleware::CUSBaccess::SetSwitch($c, $i, 16 + $switch_nr, $new_state);
}
if ($devType eq $cleware::CUSBaccess::LED_DEVICE)
{
my $led = $cleware::CUSBaccess::LED_0; # 0...3
my $value = 10; # 0...15
$rc = cleware::CUSBaccess::SetLED($c, $i, $led, $value);
}
if ($devType eq $cleware::ADC0800_DEVICE || $devType eq $cleware::ADC0801_DEVICE || $devType eq $cleware::ADC0802_DEVICE || $devType eq $cleware::ADC0803_DEVICE)
{
my $channel = 1; # 0 or 1
$rc = cleware::CUSBaccess::SelectADCChannel($c, $i, $channel);
my $scale = 0; # 0...2 for 5, 13 or 24V
my $voltage = cleware::CUSBaccess::GetADCValue($c, $i, $scale);
print "\tmeasured voltage: $voltage\n";
}
}
|