Kyle Emmons > Net-PJLink-1.01 > Net::PJLink

Download:
Net-PJLink-1.01.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  1
Stalled  1
View/Report Bugs
Module Version: 1.01   Source   Latest Release: Net-PJLink-1.02

NAME ^

Net::PJLink - PJLink protocol implementation

VERSION ^

Version 1.01 - Fix

SYNOPSIS ^

Net::PJLink is a pure perl implementation of the PJLink protocol (http://pjlink.jbmia.or.jp/english/) version 1.00, Class 1. This is a standard protocol for communicating with network-capable projectors. Net::PJLink uses an object-oriented style, with an object representing a group of one or more projectors. An object has methods corresponding to the commands in the PJLink protocol specification.

        use Net::PJLink;

        my $prj = Net::PJLink->new(
                host       => [ '10.0.0.1', '10.0.0.2' ],
                keep_alive => 1,
        );

        $prj->set_power(1); # turn on projectors

        $prj->set_audio_mute(1); # mute sound

        # retreive the current input being used
        my $input = $prj->get_input();
        if ($input->{'10.0.0.1'}->[0] == Net::PJLink::INPUT_RGB) {
                print "RGB input number " . $input->{'10.0.0.1'}->[1];
                print " is active on projector 1.";
        }

        # close network connections to the projectors
        $prj->close_all_connections;

EXPORTS ^

Net::PJLink uses constants to represent status codes sent to and recevied from projectors. These constants can be used like Net::PJLink::ERR_COMMAND, or imported into the local namespace by using the Exporter tag :RESPONSES.

        use Net::PJLink qw( :RESPONSES );

        my $prj = Net::PJLink->new(
                host => '192.168.1.10'
        );
        if ($prj->get_power() == POWER_ON) {
                print "Projector is on.";
        }

The two lists below describe each symbol that is exported by the :RESPONSES tag.

Command Response Constants

These are general status codes that are common to many projector commands.

Status Responses

These values are returned from commands that request information from the projector. Which values can be returned from which commands is specified in the documentation for each command.

UTILITY METHODS ^

new(...)

        use Net::PJLink;

        # Send commands to two hosts (batch mode),
        # don't close the connection after each command,
        # if a host cannot be contacted then remove it,
        # wait up to 1 second for a connection to be opened
        my $prj = Net::PJLink->new(
                host            => ['10.0.0.1', '10.0.0.2'],
                try_once        => 1,
                keep_alive      => 1,
                connect_timeout => 1.0,
        );

Constructor for a new PJLink object. It requires at least the host option to indicate where commands should be sent. The full list of arguments:

set_auth_password($pass)

Set the authentication password. This will only apply to newly established connections.

        $prj->set_auth_password('secret');

Returns 1 if successful, 0 otherwise (password is too long).

close_connection($host)

Manually close the connection to one host, specified by hostname or IP address. Returns 1 if the connection was found and closed, returns 0 otherwise.

close_all_connections()

Manually close all open connections that are managed by this instance. This is usually used when the object has been created with the keep_alive option.

add_hosts($host1, ...)

Takes arguments of the same form as the host option to the new constructor. These hosts will be appended to the list of hosts that commands will be sent to. Batch mode is enabled if appropriate.

remove_hosts($host1, ...)

Takes arguments of the same form as the host option to the new constructor. These hosts will be removed from the list of hosts that commands will be sent to. Batch mode is not changed by this function in order to avoid a surprise change in output format.

PROJECTOR COMMAND METHODS ^

These methods are all frontends for projector commands; calling them will issue the corresponding command immediately. The actual return value of these functions depends on whether batch mode is enabled (it is automatically enabled when more than one host has been added). If enabled, the return value of these functions will always be a hash reference, with the keys being hostnames or IP addresses and the values being the response received from that host. To illustrate:

        $prj = Net::PJLink->new(host => '10.0.0.1');

        $prj->set_power(1);
        # => 0

        $prj->add_hosts('10.0.0.2');

        $prj->set_power(1);
        # => { '10.0.0.1' => 0, '10.0.0.2' => 0 }

The return values described below for each method are the return values for each host.

set_power($state)

Turn power on or off. If the single argument is true, turn on; if argument is false, turn off. Returns one of OK, ERR_PARAMETER, ERR_UNAVL_TIME, ERR_PRJT_FAIL.

get_power()

Get the power status. Returns one of POWER_OFF, POWER_ON, POWER_COOLING, POWER_WARMUP, ERR_UNAVL_TIME, or ERR_PRJT_FAIL.

set_input($input_type, $number)

Set the active input. The first argument is the input type, which can be specified using one of the provided values:

The second argument specifies which of the inputs of that type should be used. For example, to use the second video input:

        $prj->set_input(Net::PJLink::INPUT_VIDEO, 2);

See the get_input_list() method for information on available inputs. Returns one of OK, ERR_PARAMETER, ERR_UNAVL_TIME, or ERR_PRJT_FAIL.

get_input()

Get the current active input. An array reference is returned, with the first value being the input type and the second value indicating which input of that type. Example:

        $prj->get_input();
        # => [ 3, 1 ]

The example response indicates that the first INPUT_DIGITAL source is active.

set_audio_mute($state)

Set audio mute on or off. Returns one of OK, ERR_PARAMETER, ERR_UNAVL_TIME, or ERR_PRJT_FAIL.

set_video_mute($state)

Set video mute on or off. Returns one of OK, ERR_PARAMETER, ERR_UNAVL_TIME, or ERR_PRJT_FAIL.

get_av_mute()

Get the current status of audio and video mute. An array reference is returned, with the first value being audio mute and the second being video mute. If the command failed, ERR_UNAVL_TIME or ERR_PRJT_FAIL may be returned.

get_status()

Get the health status of various parts of the projector. A hash reference is returned, with the keys being the name of the part.

        $prj->get_status();
        # => {
        #       'fan'   => 0,
        #       'lamp'  => 0,
        #       'temp'  => 0,
        #       'cover' => 0,
        #       'filter'=> -7,
        #       'other' => 0,
        # }

The example response indicates that the projector's filter is in a WARNING state, and all other areas are OK.

The values will be one of OK, WARNING, or ERROR.

get_lamp_info()

Get the status of the lamp(s). The return value is a data structure like:

        [
                [ $status, $hours ],
                ... # each lamp
        ]

For consistency, this structure is used even if the projector only has one lamp.

$status indicates whether the lamp is on or off (1 or 0). $hours is an integer indicating the total number of hours the lamp has been on. If the command was not successful, ERR_UNAVL_TIME or ERR_PRJT_FAIL may be returned.

get_input_list()

Get a list of all available inputs. The return value is a data structure like:

        [
                [ $type, $index ],
                ... # each input
        ]

$type corresponds to one of the 5 input types. $index is the number of that type (i.e. [3, 3] indicates the third digital input). If the command was not successful, ERR_UNAVL_TIME or ERR_PRJT_FAIL may be returned.

get_name()

Get the projector name. Returns a string. If the command was not successful, ERR_UNAVL_TIME or ERR_PRJT_FAIL may be returned.

get_manufacturer()

Get the manufacturer name. Returns a string. If the command was not successful, ERR_UNAVL_TIME or ERR_PRJT_FAIL may be returned.

get_product_name()

Get the product name. Returns a string. If the command was not successful, ERR_UNAVL_TIME or ERR_PRJT_FAIL may be returned.

get_product_info()

Get "other information". Returns a string. If the command was not successful, ERR_UNAVL_TIME or ERR_PRJT_FAIL may be returned.

get_class()

Get information on supported PJLink Class. Returns a single digit. For example, returning "2" indicates that the projector is compatible with the PJLink Class 2 protocol. The PJLink v.1.00 Class 1 specification only defines return values "1" and "2". If the command was not successful, ERR_UNAVL_TIME or ERR_PRJT_FAIL may be returned.

AUTHOR ^

Kyle Emmons, <kemmons at tma-0.net>

BUGS ^

This module has only been tested on Panasonic PTFW100NTU projectors.

The code for opening network connections may not work reliably for a large (~200) number of hosts. This is due to network connections timing out before all hosts have been contacted. If you encounter this problem, adjusting the connect_timeout and receive_timeout arguments may help.

Please report any bugs or feature requests to bug-net-pjlink at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-PJLink. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Net::PJLink

You can also look for information at:

LICENSE AND COPYRIGHT ^

Copyright 2010 Kyle Emmons.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

The PJLink name is a trademark of Japan Business Machine and Information System Industries Association (JBMIA).

syntax highlighting: