NAME
Printer::ESCPOS::Profiles::Generic - Generic Profile for Printers for Printer::ESCPOS. Most common functions are included here.
VERSION
version 0.003
METHODS
init
Initializes the Printer. Clears the data in print buffer and resets the printer to the mode that was in effect when the power was turned on.
enable
Enables/Disables the printer with a '_ESC =' command (Set peripheral device). When disabled, the printer ignores all commands except enable() or other real-time commands pass 1 to enable, pass 0 to disable
$device->printer->enable(0) # disabled
$device->printer->enable(1) # enabled
printAreaWidth
Sets the Print area width specified by nL and NH. The width is calculated as ( nL + nH * 256 ) * horiz_motion_unit
A pre-requisite line feed is automatically executed before printAreaWidth method.
$device->printer->printAreaWidth( nL => 0, nH =>0 );
tabPositions
Sets horizontal tab positions for tab stops. Upto 32 tab positions can be set in most receipt printers.
$device->printer->tabPositions( 5, 9, 13 );
* Default tab positions are usually in intervals of 8 chars (9, 17, 25) etc.
tab
moves the cursor to next horizontal tab position like a "\t". This command is ignored unless the next horizontal tab position has been set.
lf
line feed. This method will most likely not be used since you can simply insert a \n in your print string for write function to substitute for this function e.g. :
This
$device->printer->write("blah blah");
$device->printer->lf();
$device->printer->write("blah2 blah2");
is same as this
$device->printer->write("blah blah\nblah2 blah2");
ff
When in page mode, print data in the buffer and return back to standard mode
cr
Print and carriage return
When automatic line feed is enabled this method works the same as lf , else it is ignored.
cancel
Cancel (delete) page data in page mode
font
Set Font style, you can pass 'a', 'b' or 'c'. Many printers don't support style 'c' and only have two supported styles.
emphasized
Set emphasized mode 0 for off and 1 for on
doubleStrike
Set double-strike mode 0 for off and 1 for on
justification
Set Justification. Options 'left', 'right' and 'center'
$self->printer->justification('right');
upsideDown
Sets Upside Down Printing on/off (pass 0 or 1)
$self->printer->upsideDownPrinting(1);
height
Set font height. Only supports 0 or 1 for printmode set to 1, supports values 0 to 7 for non-printmode state (default)
width
Set font height. Only supports 0 or 1 for printmode set to 1, supports values 0 to 7 for non-printmode state (default)
underline
set underline, 0 for off, 1 for on and 2 for double thickness
invert
Reverse white/black printing mode pass 0 for off and 1 for on
$device->printer->invert(0);
charSpacing
Sets charachter spacing takes a value between 0 and 255
$device->printer->charSpacing(5);
$device->printer->write("Blah Blah Blah\n");
$device->printer->print();
lineSpacing
$device->printer->lineSpacing($spacing)
* 0 <= spacing <= 255
selectDefaultLineSpacing
Revert to default Line spacing for the printer
printPosition
Sets the distance from the beginning of the line to the position at which characters are to be printed. $device->printer->printPosition( $length, $height );
* 0 <= $length <= 255 * 0 <= $height <= 255
drawerKickPulse
Trigger drawer kick
$device->printer->drawerKickPulse( $pin, $time );
* $pin is either 0( for pin 2 ) and 1( for pin5 ) default value is 0 * $time is a value between 1 to 8 and the pulse duration in multiples of 100ms. default value is 8
For default values use without any params to kick drawer pin 2 with a 800ms pulse
$device->printer->drawerKickPulse();
cutPaper
Cuts the paper, if feed is set to 0 then printer doesnt feed paper to cutting position before cutting it. The default behavior is that the printer doesn't feed paper to cutting position before cutting. One pre-requisite line feed is automatically executed before paper cut.
$device->printer->cutPaper( feed => false )
printNVImage
Prints bit image stored in Non-Volatile (NV) memory of the printer. This function also writes the buffer data to the printer before printing the bit image.
$self->printer->printNVImage($flag);
* $flag = 0 # Normal width and Normal Height * $flag = 1 # Double width and Normal Height * $flag = 2 # Normal width and Double Height * $flag = 3 # Double width and Double Height
printImage
Prints bit image stored in Volatile memory of the printer. This image gets erased when printer is reset. This function also writes the buffer data to the printer before printing the bit image.
$self->printer->printImage($flag);
* $flag = 0 # Normal width and Normal Height * $flag = 1 # Double width and Normal Height * $flag = 2 # Normal width and Double Height * $flag = 3 # Double width and Double Height
printerStatus
Returns printer status in a hashref.
return { drawer_pin3_high => $flags[5], offline => $flags[4], waiting_for_online_recovery => $flags[2], feed_button_pressed => $flags[1], };
offlineStatus
Returns a hashref for paper cover closed status, feed button pressed status, paper end stop status, and a aggregate error status either of which will prevent the printer from processing a printing request.
return {
cover_is_closed => $flags[5],
feed_button_pressed => $flags[4],
paper_end => $flags[2],
error => $flags[1],
};
errorStatus
Returns hashref with error flags for auto_cutter_error, unrecoverable error and auto-recoverable error
return {
auto_cutter_error => $flags[4],
unrecoverable_error => $flags[2],
autorecoverable_error => $flags[1],
};
paperSensorStatus
Gets printer paper Sensor status. Returns a hashref with four sensor statuses. Two paper near end sensors and two paper end sensors for printers supporting this feature. The exact returned status might differ based on the make of your printer. If any of the flags is set to 1 it implies that the paper is out or near end.
return {
paper_roll_near_end_sensor_1 => $flags[5],
paper_roll_near_end_sensor_2 => $flags[4],
paper_roll_status_sensor_1 => $flags[2],
paper_roll_status_sensor_2 => $flags[1],
};
inkStatusA
Only available for dot-matrix and other ink consuming printers. Gets printer ink status for inkA(usually black ink). Returns a hashref with ink statuses.
return {
ink_near_end => $flags[5],
ink_end => $flags[4],
ink_cartridge_missing => $flags[2],
cleaning_in_progress => $flags[1],
};
inkStatusB
Only available for dot-matrix and other ink consuming printers. Gets printer ink status for inkB(usually red ink). Returns a hashref with ink statuses.
return {
ink_near_end => $flags[5],
ink_end => $flags[4],
ink_cartridge_missing => $flags[2],
};
barcode
my $hripos = 'above';
my $font = 'a';
my $height = 100;
my $system = 'UPC-A';
$device->printer->barcode(
HRIPosition => $hripos, # Position of Human Readable characters
# 'none','above','below','aboveandbelow'
font => $font, # Font for HRI characters. 'a' or 'b'
height => $height, # no of dots in vertical direction
system => $system, # Barcode system
width => 2 # 2:0.25mm, 3:0.375mm, 4:0.5mm, 5:0.625mm, 6:0.75mm
barcode => '123456789012', # Check barcode systems for allowed value
);
$device->printer->barcode(
system => 'CODE39',
HRIPosition => 'above',
barcode => '*1-I.I/ $IA*',
);
$device->printer->barcode(
system => 'CODE93',
HRIPosition => 'above',
barcode => 'Shan',
);
#Default barcode printed in code93 width 2 and HRI Chars below the barcode
$device->printer->barcode(
barcode => 'SHANTANU BHADORIA',
);
Available systems:
* UPC-A * UPC-C * JAN13 * JAN8 * CODE39 * ITF * CODABAR * CODE93 * CODE128
AUTHOR
Shantanu Bhadoria (shantanu@cpan.org)
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by Shantanu Bhadoria.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.