我有这个简单的 Perl 软件来监控我的家庭自动化总线的活动,并在灯改变其状态时“说”。我想使用 Xcode 游乐场使用 Swift 语言来实现它。有什么解决方案可以尝试吗?
#!/usr/bin/perl -w
#
use strict;
use IO::Socket::INET;
my $mh200ip = "10.0.1.82";
my $ownport = "20000";
my $frames;
my $socket = IO::Socket::INET->new(
PeerAddr => $mh200ip,
PeerPort => $ownport,
Proto => "tcp",
Type => SOCK_STREAM
);
die "Could not create socket: $!\n" unless $socket;
$socket->send("*99*1##"); # Sending OPEN ACK
while (1) {
$socket->recv( $frames, 128 );
if ( $frames ne '' ) {
print "$frames\n";
my $data = ($frames);
my @values = split( '##', $data );
if ( $data eq "*1*0*53##" ) {
`say "light off"`;
}
if ( $data eq "*1*1*53##" ) {
`say "light on"`;
}
} else {
print "server closed connection";
exit 1;
}
}