-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvedicom600_1000.php
66 lines (58 loc) · 1.35 KB
/
vedicom600_1000.php
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
<?php
/*
*
*p-0000.2
*p-0000.2
*p-0000.2
*P+0108.6
*P+0108.6
*P+0108.6
**/
$tmpl = "<?xml version='1.0' encoding='UTF-8' ?>" .
"<monitor>" .
"<Devices>" .
"<item>" .
"<Name>D19</Name>" .
"<Entries>" .
"<item>" .
"<Unit>KG</Unit>" .
"<ID>20</ID>" .
"<Value>[#0.000#]</Value>" . // UNSTABLE, NO_CONNECTION, PORT_BUSSY
"<Name>ElectronicScale1</Name>" .
"</item>" .
"</Entries>" .
"</item>" .
"</Devices>" .
"</monitor>";
define ('DEVICE', '/dev/ttyUSB0');
//define ('DEVICE', '/dev/ttyS0');
clearstatcache();
$fp = fopen(DEVICE,'r');
//stream_set_blocking($fp, 0);
$value = $res = "";
// четем 4 пъти, търсим 2 последователни равни стринга за стабилно състояние /всеки 2-ри 3 празен стринг/
for ($i=1; $i<=4; $i++ ) {
$res = trim(fgets($fp));
if (!empty(trim($res))) {
preg_match_all("/[+-]?([0-9]*[.])?[0-9]+/", $res, $resV);
if ($value == $resV[0][0] && is_numeric($value)) {
$value = str_replace("+", "", $value);
$value = str_replace("-", "", $value);
break;
} else {
$value = $resV[0][0];
}
}
}
fclose($fp);
$weight = 0;
if (is_numeric($value)) {
$weight = $value;
} else {
$err = true;
}
if (!$err) {
$tmpl = str_replace('[#0.000#]', $weight, $tmpl);
} else {
$tmpl = str_replace('[#0.000#]', 'PORT_BUSSY', $tmpl);
}