npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hpgl

v0.8.7-12

Published

A Node.js library to communicate with HPGL-compatible devices such as plotters and printers.

Downloads

162

Readme

hpgl

A Node.js library to control HPGL-compatible plotters

npm npm Beerpay

About

The hpgl library makes it possible to interact with plotters that support the Hewlett-Packard Graphics Language (a.k.a. hpgl). This language is the de facto standard for most plotters.

Warning: This library is still in early stages of development. It should not be used in production.

Compatibility

This library relies on external modules for serial communication. To use it in a pure Node.js, environment, you will need to install and use the serialport module. If you want to use this library inside Chrome Apps or NW.js applications, you will need to install the browser-serialport module instead (version 2.1.0 or greater).

Note: it is possible to use node-serialport within NW.js and Electron projects but it needs to be specifically recompiled for those environment.

So far, the library has only beed tested with HP 7475A and HP 7440A plotters. If you have success with other makes or models, let me know. Beware that some HP plotters are only equipped with a proprietary HPIB or GPIB interface. To use this library, your plotter must have a serial interface (RS-232-C).

Coordinate System

The plotting coordinate system is anchored in the top-left corner, just like a computer screen. This means positive x goes right and positive y goes down. By default, plotters usually work differently, but I find it easier to stick with the computer screen standard.

Getting Started

To get started, you will need a few pieces of hardware:

  • HPGL-compatible plotter with a serial interface;
  • USB-to-Serial adapter (unless your computer has a serial port);
  • Male DB-25 to female DB-9 cable (a.k.a. null modem cable);
  • Pens that fit your plotter;
  • Paper.

Your plotter needs to be set to a line speed of 9600 baud with 8-N-1 settings. Chances are high this is already the case. If not, you may need to adjust some dip switches on your device. Refer to the manufacturers's documentation.

Example

The first thing you need to do to get plotting is instantiate the object used for serial communication. If you are working on a Node.js project using the serialport module, this is how you would do it:

// Import the 'serialport' module and instantiate it. Do not forget to set 'autoOpen' to false in 
// the options.
const SerialPort = require("serialport");
var transport = new SerialPort("/dev/tty.usbserial", {autoOpen: false});

If you are working on a Chrome or NW.js application, the procedure is slightly different:

// Import the 'browser-serialport' module and instantiate it. Pass 'false' as the third parameter of
// the SerialPort constructor so no automatic connection attempt is made.
const SerialPort = require("browser-serialport").SerialPort;
var transport = new SerialPort("/dev/tty.usbserial", {}, false);

Once the transport variable is ready, the remainining of the code is exactly the same no matter which transport you use. For example, here is the code necessary to draw "Hello, World!".


// Import the 'Plotter' class and instantiate it
const Plotter = require("hpgl").Plotter;
var plotter = new Plotter();

// Connect the device and add a callback to draw some text.
plotter.connect(transport, {}, function(error) {

  if (error) {
    console.log(error);
    return;
  }

  this
    .moveTo(1, 1)
    .drawText("Hello, World!");

});

As you can see above, you first need to create a Plotter object and call its connect() method passing in the transport variable, some optionnal settings and a function to trigger once the device is ready. Note that this is bound to the Plotter object and that plotting methods are chainable.

Using Multiple Plotteres

This library can be used to connect several plotters to the same host. However, not all USB-to-Serial chipsets support this.

For example, the Prolific 2303 driver crashes my computer when I try use more than one adapter. On the other hand, the Texas Instrument/TI driver works beautifully with multiple devices.

Documentation

I will try to maintain an up-to-date API documentation. A good place to start is the Plotter class. If you find errors, please file an issue on GitHub.

Support the Project

If you find this library useful, you can buy me a drink as a token of your appreciation. This would automatically make you even more awesome than you already are!

Beerpay

Cheers!