Device-TLSPrinter

 view release on metacpan or  search on metacpan

lib/Device/TLSPrinter.pm  view on Meta::CPAN

    ic_printer_status   => {
        string => "A",  expect =>  9,  filter => \&ic_filter_printer_status
    },
    ic_toggle_pause     => { string => "B",  expect =>  0 },
    ic_cancel_job       => { string => "C",  expect =>  0 },
    ic_batch_quantity   => { string => "E",  expect =>  5 },
);

for my $cmd (keys %ic_cmds) {
    no strict 'refs';
    *$cmd = sub {
        my ($self) = @_;
        my ($rc, $raw, @data) = (FC_UNDEF);
        DEBUG(" >>> $cmd()");

        if ($self->immediate_cmds) {
            ($rc, $raw) = $self->exec_command(
                cmd      => SOH.$ic_cmds{$cmd}{string}, 
                expect   => $ic_cmds{$cmd}{expect},
                feedback => 0, 
            );
            $rc = FC_OK;

            # pass the raw result to the filter if it's defined
            if (defined $raw and ref $ic_cmds{$cmd}{filter} eq "CODE") {
                @data = $ic_cmds{$cmd}{filter}->($raw)
            }
        }
        else {
            $rc = FC_IMMEDIATE_COMMANDS_DISABLED
        }

        return wantarray ? ($rc, $raw, @data) : $rc
    }
}


#
# ic_disable_immediate_cmds()
# -------------------------
sub ic_disable_immediate_cmds {
    my ($self) = @_;
    $self->exec_command(cmd => SOH."D");
    $self->immediate_cmds(0);
}


#
# ic_filter_printer_status()
# ------------------------
sub ic_filter_printer_status {
    my ($raw) = @_;

    # decode the status
    my @chars = split //, $raw;
    my %status = (
        printhead_open   => $chars[0] eq "Y" ? 1 : 0,
        out_of_labels    => $chars[1] eq "Y" ? 1 : 0,
        out_of_ribbon    => $chars[2] eq "Y" ? 1 : 0,
        printing_batch   => $chars[3] eq "Y" ? 1 : 0,
        busy_printing    => $chars[4] eq "Y" ? 1 : 0,
        printer_paused   => $chars[5] eq "Y" ? 1 : 0,
        touch_cell_error => $chars[6] eq "Y" ? 1 : 0,
        low_battery      => $chars[7] eq "Y" ? 1 : 0,
    );

    return %status
}


# ========================================================================
# System commands
#

my %sc_cmds = (
    sc_heat_setting_offset          => { string => "b%+02.2d" },
    sc_disable_feed_to_cut_position => { string => "C" },
    sc_enable_feed_to_cut_position  => { string => "c" },
    sc_quantity_for_stored_labels   => { string => "E%04d" },
    sc_form_feed                    => { string => "F" },
    sc_set_form_stop_position       => { string => "f%+02.2d" },
    sc_print_last_label_format      => { string => "G" },
    sc_set_printer_to_metric        => { string => "m" },
    sc_set_printer_to_inches        => { string => "n" },
    sc_set_start_of_print_offset    => { string => "O+02.2d" },
    sc_set_horizontal_align_offset  => { string => "o+02.2d" },
    sc_set_continuous_label_length  => { string => "P%04d" },
    sc_clear_all_memory             => { string => "Q" },
    sc_set_continuous_label_spacing => { string => "S%04d" },
    sc_print_test_label             => { string => "T" },
    sc_get_touch_cell_data_binary   => {
        string => "t",  expect => 32
    },
    sc_replace_label_format_field   => { string => "U%02d%s".CR },
    sc_get_touch_cell_data_ascii    => {
        string => "V",    expect => 32*2,  filter => \&sc_filter_touch_cell_data_ascii
    },
    sc_firmware_version             => {
        string => "v",    expect => 25,    filter => \&sc_filter_chomp
    },
    sc_memory_information           => { 
        string => "W%s",  expect => 255,   filter => \&sc_filter_memory_info
    },
    sc_delete_file                  => { string => "x%s%s" },
    sc_pack_memory                  => { string => "z" },
);

for my $cmd (keys %sc_cmds) {
    no strict 'refs';
    *$cmd = sub {
        my ($self, @args) = @_;
        my @data;
        DEBUG(" >>> $cmd(@args)");

        # execute the command
        my ($rc, $raw) = $self->exec_command(
            cmd      => sprintf(STX.$sc_cmds{$cmd}{string}, @args),
            expect   => $sc_cmds{$cmd}{expect}, 
            feedback => 1,
        );



( run in 0.659 second using v1.01-cache-2.11-cpan-39bf76dae61 )