Thread CPU ausgelastet bei RS232-listening (11 answers)
Opened by MajorTwip at 2009-09-04 12:02

MajorTwip
 2009-09-04 12:02
#125434 #125434
User since
2009-09-04
3 Artikel
BenutzerIn
[default_avatar]
Hi @ all

Ich hab zuhause ein Riesenprojekt bei dem ich übers www die Wohnung ansteuern kann. Quasi smarthome.
Klappt ganz gut...
Auf dem Webserver (openBSD) läuft ein Script das Daten vom Com empfängt (/dev/cua00)
Klappt auch. Doch vorhin hab ich mal wieder ein ps auxw gestartet, und oh Schreck, das Script nutzt alle verfügbare CPU-Power, also 98.7% vorhin...

Ich weiss, katastrophal:)

Kein Plan wie ich ein Do-Loop mache, drum musste eine verarschte For-Schleife hinhalten...

Durch das "sleep" dachte ich, ich hätte das CPU-Problem im griff...scheinbar nicht.

help...

Grüsse, MT

Code (perl): (dl )
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
#!/usr/bin/perl -w

# Requires Device-Serial per module.
use Device::SerialPort 0.05;

my $RS232 = "/dev/cua00";
my $return;
my $device = "";
my $value = "";
my $dummy;

# Constructor & Basic Values

my $ob = Device::SerialPort->new ($RS232) || die "Can.t open $RS232:$!";

$ob->baudrate (9600) || die "fail setting baudrate";
$ob->parity ("none") || die "fail setting parity";
$ob->databits (8) || die "fail setting databits";
$ob->stopbits (1) || die "fail setting stopbits";
$ob->handshake ("none") || die "fail setting handshake";
$ob->dtr_active (1) || die "fail setting dtr_active";

$ob->write_settings || die "no settings";
print "device loaded";
system "echo $$ > ./PIDrec";

for ($dummy=1; $dummy<11; $dummy++)
{
$return = $ob->input;
sleep (0.2);
unless ($return eq "")
        {
        print $return;
        ($device, $value) = split (/:/, $return, 2);
        print "New State on $device, State: $value\n";
        system "echo $value > ./sl$device";
        system "echo New State on $device, State: $value >> ./log";
        $return = "";
        }
if ($dummy>7)
{
$dummy=0;
}
}
undef $ob;

View full thread CPU ausgelastet bei RS232-listening