Hello.

I need some help in understanding why the first

    my ($Count,$Saw)=$self->{_Portobj}->read(1);

is executed without any problem , however the second identical statement
inside the while loop fails with the error

    Can't call method "read" on an undefined value at wt800.pm line 121

The idea behind this coding is to be able to use any object providing a
"write" and a "read" method inside my object. (i.e.
messageDevice::SerialPort)

I'm using Perl 2.7 on a OpenSuSE 13.2 system.

Any hint?

Tnx

Marco


sub get_answer {

        my ($self,$Orig_ref)  = @_;

        print $self,"\n";

        my $stat=$self->{_Portobj}->write("aaaa") or die "pippo";
        my ($Count,$Saw)=$self->{_Portobj}->read(1);

        my $Count=9999;
        my $Saw="";
        my @Resp;

        print $self,"\n";

        while (($Saw == chr(10)) or ($Count == 0)) {
                print $self,"\n";
                my ($Count,$Saw)=$self->{_PortObj}->read(1); # will read
1 char
                push(@Resp,ord($Saw));
                print ord $Saw,"\n";
        }

}

_Portobj is initialized in myObject as:

sub new {

        my $class = shift;
        my $Tpobj = shift;

        my $self = {
                _Portobj => $Tpobj,
                ....

And the main () is

    my $PortObj = new Device::SerialPort ($Portname, $Quiet)
                or die "Can't open device $Portname: $!\n";

    my $Object = new myObject($Portobj);



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to