NAME Printer::Thermal - Interface for Thermal (and some dot-matrix and inkjet) Printers that support ESC/POS specification. VERSION version 0.08 SYNOPSIS use Printer::Thermal; #For Network Printers $port is 9100 in most cases but might differ depending on how you have configured your printer $printer = Printer::Thermal->new(device_ip=>$printer_ip,device_port=>$port); #These commands won't actually send anything to the printer but it will store all the merged data including control codes to send to printer in $printer->print_string variable. $printer->write("Blah Blah \nReceipt Details\nFooter"); $printer->bold_on(); $printer->write("Bold Text"); $printer->bold_off(); $printer->print(); ##Sends the above set of code to the printer. Clears the buffer text in module. #For local printer connected on serial port, check syslog(Usually under /var/log/syslog) for what device file was created for your printer when you connect it to your system(For plug and play printers). my $path = '/dev/ttyACM0'; $printer2 = Printer::Thermal->new(serial_device_path=$path); $printer->write("Blah Blah \nReceipt Details\nFooter"); $printer->bold_on(); $printer->write("Bold Text"); $printer->bold_off(); $printer->print(); #For local printer connected on usb port, check syslog(Usually under /var/log/syslog) for what device file was created for your printer when you connect it to your system(For plug and play printers). my $path = '/dev/usb/lp0'; $printer2 = Printer::Thermal->new(usb_device_path=$path); $printer->write("Blah Blah \nReceipt Details\nFooter"); $printer->bold_on(); $printer->write("Bold Text"); $printer->bold_off(); $printer->print(); DESCRIPTION Some might not find the module name accurate since ESC/P was developed initially for dot matrix and inkjet printers, however today most Thermal Receipt Printers use these codes for control. Most people(i.e. like me when I started looking for Thermal Printer stuff) who look for Thermal Printer codes don't know Thermal Printers use certain set of ESC codes to achieve a bunch of functions, and I didn't want to name it Printer::ESC::P because that would not help people who are new to receipt printers looking for something like this module. This module provides an Object oriented interface for interacting with Thermal Printers. Maybe I will refactor it later with subclasses. I used Moose, I apologize!! For ESC/P codes refer the guide from Epson http://support.epson.ru/upload/library_file/14/esc-p.pdf ATTRIBUTES usb_device_path This variable contains the path for the printer device file when connected as a usb device on UNIX-like systems. I haven't added support for Windows and it probably wont work in doz as a local printer without some modifications. Feel free to try it out and let me know what happens. This must be passed in the constructor serial_device_path This variable contains the path for the printer device file when connected as a serial device on UNIX-like systems. I haven't added support for Windows and it probably wont work in doz as a local printer without some modifications. Feel free to try it out and let me know what happens. This must be passed in the constructor device_ip Contains the IP address of the device when its a network printer. The module creates IO:Socket::INET object to connect to the printer. This can be passed in the constructor. device_port Contains the network port of the device when its a network printer. The module creates IO:Socket::INET object to connect to the printer. This can be passed in the constructor. baudrate When used as a local serial device you can set the baudrate of the printer too. However default should usually work. let me know if it doesn't for you. read_char_time *DECRECATED* read_const_time *DECRECATED* black_threshold Black ink threshold alpha_threshold Black alpha threshold heatTime Heating time to set for Supported Thermal Printers, this affects dot intensity heatInterval heatingDots printer This is the direct device handle to the printer, You must almost never use this. Unless you are hacking through the module. If you are using this you should send a bug report on why you need to use this. print_string This contains the string in the module buffer my $print_string = $printer->print_string METHODS $printer->print(); Sends the accumulated commands to the printer. All commands below need to be followed by a print() to send the data from buffer to the printer. You may call more than one printer command and then call print to send them all to printer together. The following bunch of commands print a text to a printer, move down one line, and cut the receipt paper. $printer->write("hello Printer\n"); $printer->linefeed(); $printer->cutpaper(); $pritner->print(); # Sends the all the commands before this to the printer in one go. $printer->write("some text\n"); Writes a bunch of text that you pass here to the module buffer. Note that this will not be passed to the printer till you call $printer->print() $printer->left_margin($nl,$nh); Sets the left margin code to the printer. takes two single byte parameters, $nl and $nh. To determine the value of these two bytes, use the INT and MOD conventions. INT indicates the integer (or whole number) part of a number, while MOD indicates the remainder of a division operation. For example, to break the value 520 into two bytes, use the following two equations: nH = INT 520/256 nL = MOD 520/256 $printer->reset() Resets the printer $printer->right_side_charachter_spacing($spacing) Takes a one byte number, spacing as a parameter $printer->horiz_tab() $printer->line_spacing($value) $printer->linefeed() $printer->justify($alignment) $alignment can be either 'L','C' or 'R' for left center and right justified printing $printer->bold_off(); $printer->bold_on(); $printer->doublestrike_off(); $printer->doublestrike_on(); $printer->emphasize_off(); $printer->emphasize_on(); $printer->font_size($n); Defined Region 0 ≤ n ≤ 255 However, 1 ≤ vertical direction magnification ratio ≤ 8, 1 ≤ horizontal direction magnification ratio ≤ 8 Initial Value n=0 Function Specifies the character size (magnification ratio in the vertical and horizontal directions). $printer->font_b(); $printer->font_a(); $printer->printmode($font_number, $double_height_mode, $double_width_mode); 0 or 1, $printer->underline_off(); $printer->underline_on(); $printer->inverse_off(); $printer->inverse_on(); $printer->barcode_height($height); $printer->print_barcode($type,$string) $printer->print_text($msg,$chars_per_line); Print some text defined by msg. If chars_per_line is defined, inserts newlines after the given amount. Use normal '\n' line breaks for empty lines. $printer->color_1() Prints in first color for dual color printers $printer->color_2() Prints in second color for dual color printers $printer->cutpaper() Cuts the paper. Most Thermal receipt printers support the facility to cut the receipt using this command once printing is done. $printer->open_cash_drawer() Opens the Cash Drawer connected to the thermal printer. $printer->test() Prints a bunch of test strings to see if your printer is working fine/connected properly. Don't worry if some things like emphasized and double strike looks the same, it happened with my printer too. USAGE * This Module offers a object oriented interface to ESC/POS Printers. * Create a printer object by providing parameters for one of the three types of printers supported. * then call formatting options or write() text to printer object in sequence. * Then call the print() method to dispatch the sequences from the module buffer to the printer. Note: While you may call print() after every single command code, this is not advisable as some printers tend to choke up if you send them too many commands too quickly. SEE ALSO * Device::SerialPort * IO::File * IO::Socket SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through github at . You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. git clone git://github.com/shantanubhadoria/printer-thermal.git AUTHOR Shantanu Bhadoria CONTRIBUTORS * Shantanu Bhadoria * Shantanu Bhadoria * Shantanu Bhadoria * Shantanu Bhadoria COPYRIGHT AND LICENSE This software is copyright (c) 2013 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.