diff -r cfc898fd62f1 -r 9c3e112933ae lib/Quancom.pm --- a/lib/Quancom.pm Tue Dec 16 16:08:43 2008 +0100 +++ b/lib/Quancom.pm Wed Dec 17 23:31:39 2008 +0100 @@ -2,9 +2,10 @@ use strict; use warnings; +use Carp; use IO::Socket::INET; + use Quancom::Result; -use Carp; our $VERSION = 0.1; @@ -24,7 +25,7 @@ ); $self->{job} = 0; - $self->{ok} = undef; + $self->{ok} = undef; return $self; } @@ -57,27 +58,9 @@ my $self = shift; local $/ = "\r"; # CR is the delimiter - my $r = $self->{socket}->getline; # now it's a line - chomp($r); # we do not need the delimiter - - $self->{last_result} = new Quancom::Result; - - # decode the status - if (($self->{last_result}{error_code}) = $r =~ /^E(.)/) { - $self->{last_result}{ok} = 0; - } - elsif (my ($jobid, $data, $csum) = $r =~ /^[DO](..)(.*)(..)$/) { - $self->{last_result}{ok} = 1; - $self->{last_result}{result} = defined $data ? $data : ""; - } - else { - die "unknown response $r"; - } - - return $r; + $self->{last_result} = new Quancom::Result($self->{socket}->getline); } - 1; __END__ @@ -90,9 +73,11 @@ use Quancom; - my $q = new Quancom 172.16.0.22; - my $r = $q->cmd("xxxxxx") - or die $r->error_message; + my $quancom = new Quancom 172.16.0.22; + my $result = $q->cmd("xxxxxx"); + if ($result->error) { die $result->error_message } + else { print $result->data } + =head1 METHODS @@ -103,19 +88,33 @@ This method returns a new Quancom object if the connection was successfully established. -=item B( I ) +=item B( I ) Send a Quancom string to the device. The string here should be B the leading STX and Jobid as well without the trailing CR. +It returns a L object. -It returns TRUE on success, FALSE otherwise. +The only tested I is currently "WB0101FF", which should set +all bits on the first relais. Some other (untested) string for setting +just the lowest bit on the first relais should be "WB010001". =item B( ) This returns an object containing the last result. +See L for more information. =back +=head1 MORE EXAMPLES + + use Quancom; + my $quancom = new Quancom(172.20.20.1); + die "Sorry" if $quancom->cmd("xxxx")->error; + +=head1 SEE ALSO + +L + =head1 AUTHOR Maik Schueller