Wiki

Clone wiki

Pipsta / Pipsta Printer Character Set

Overview

This bulletin describes how a user can access the diacritics (e.g. characters with accents), shading and line drawing characters that are available in the Pipsta printer's character set.

Background

The Pipsta printer's standard character set has printable characters in the range: * 0x20 to 0xFF (hex) * 32 to 255 (decimal)

The full character set can be printed by a double-press of the feed button (the button next to the printer's LED). It can be seen that not all of these characters are available on keyboards. A method of accessing these characters is presented below.

Example

Using BasicPrint.py as a basis, the following script has been produced:

#!python
# ASCIIPrint.py
# Copyright (c) 2015 Able Systems Limited. All rights reserved.
'''This simple code example is provided as-is, and is for demonstration
purposes only. Able Systems takes no responsibility for any system
implementations based on this code.

This very simple python script establishes USB communication with the Pipsta
printer and sends a series of characters, along with their ASCII codes to be
printed

Copyright (c) 2015 Able Systems Limited. All rights reserved.
'''
import argparse
import platform
import sys
import time

import usb.core
import usb.util

FEED_PAST_CUTTER = b'\n' * 5
USB_BUSY = 66

# NOTE: The following section establishes communication to the Pipsta printer
# via USB. YOU DO NOT NEED TO UNDERSTAND THIS SECTION TO PROGRESS WITH THE
# TUTORIALS! ALTERING THIS SECTION IN ANY WAY CAN CAUSE A FAILURE TO COMMUNICATE
# WITH THE PIPSTA. If you are interested in learning about what is happening
# herein, please look at the following references:
#
# PyUSB: http://sourceforge.net/apps/trac/pyusb/
# ...which is a wrapper for...
# LibUSB: http://www.libusb.org/
#
# For full help on PyUSB, at the IDLE prompt, type:
# >>> import usb
# >>> help(usb)
# 'Deeper' help can be trawled by (e.g.):
# >>> help(usb.core)
#
# or at the Linux prompt, type:
# pydoc usb
# pydoc usb.core
PIPSTA_USB_VENDOR_ID = 0x0483
PIPSTA_USB_PRODUCT_ID = 0xA053


def main():
    """The main loop of the application.  Wrapping the code in a function
    prevents it being executed when various tools import the code.
    """
    if platform.system() != 'Linux':
        sys.exit('This script has only been written for Linux')

    # Find the Pipsta's specific Vendor ID and Product ID
    dev = usb.core.find(idVendor=PIPSTA_USB_VENDOR_ID,
                        idProduct=PIPSTA_USB_PRODUCT_ID)
    if dev is None:  # if no such device is connected...
        raise IOError('Printer  not found')  # ...report error

    try:
        # Linux requires USB devices to be reset before configuring, may not be
        # required on other operating systems.
        dev.reset()

        # Initialisation. Passing no arguments sets the configuration to the
        # currently active configuration.
        dev.set_configuration()
    except usb.core.USBError as ex:
        raise IOError('Failed to configure the printer', ex)

    # The following steps get an 'Endpoint instance'. It uses
    # PyUSB's versatile find_descriptor functionality to claim
    # the interface and get a handle to the endpoint
    # An introduction to this (forming the basis of the code below)
    # can be found at:

    cfg = dev.get_active_configuration()  # Get a handle to the active interface

    interface_number = cfg[(0, 0)].bInterfaceNumber
    # added to silence Linux complaint about unclaimed interface, it should be
    # release automatically
    usb.util.claim_interface(dev, interface_number)
    alternate_setting = usb.control.get_interface(dev, interface_number)
    interface = usb.util.find_descriptor(
        cfg, bInterfaceNumber=interface_number,
        bAlternateSetting=alternate_setting)

    usb_endpoint = usb.util.find_descriptor(
        interface,
        custom_match=lambda e:
        usb.util.endpoint_direction(e.bEndpointAddress) ==
        usb.util.ENDPOINT_OUT
    )

    if usb_endpoint is None:  # check we have a real endpoint handle
        raise IOError("Could not find an endpoint to print to")

    # Now that the USB endpoint is open, we can start to send data to the
    # printer.
    # The following opens the text_file, by using the 'with' statemnent there is
    # no need to close the text_file manually.  This method ensures that the
    # close is called in all situation (including unhandled exceptions).

    for n in xrange(128, 256, 1): #Loop through characters 128 to 255
        usb_endpoint.write(str(n)), # Print the value to put in chr(n)
        usb_endpoint.write(': '),   # Print a colon and space (for formatting only)
        usb_endpoint.write(chr(n))  # Print the ASCII character for chr(n)
        usb_endpoint.write(', ')    # Print a colon and space (for formatting only)
        if n%3==1:  # Send a carriage return every third character
            usb_endpoint.write(chr(0x0d))

    usb_endpoint.write(FEED_PAST_CUTTER)
    usb.util.dispose_resources(dev)

# Ensure that ASCIIPrint is run in a stand-alone fashion (as intended) and not
# imported as a module. Prevents accidental execution of code.
if __name__ == '__main__':
    main()

Modifications

1) The above script does not require command-line arguments as the print job is deterministic. parse_arguments() has thus been removed.

2) The print job takes the form of a tabulated list of ASCII characters starting at 0x80 (hex) 128 (decimal) along with their character codes. This is particularly useful as an index for those wishing to use these ordinarily inaccessible characters.

Other Character Sets

The Pipsta printer can be upgraded with other character sets. If you have such a requirement, please contact Pipsta Support, ideally with an indication of your required Code Page.

[End of Document]

Updated