Giter Club home page Giter Club logo

hpgl's Introduction

hpgl

A Node.js library to control HPGL-compatible plotters

npm npm

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, HP 7440A and Roland DXY-1300 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 Plotters

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 ๐Ÿ’œ sponsor the project as a token of your appreciation. This would automatically make you even more awesome than you already are!

Cheers!

hpgl's People

Contributors

cotejp avatar djipco avatar jmcgill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hpgl's Issues

Timeout error

I was struggling to get chiplotle working when I thought I would see if anyone had been working on a node implementation of hpgl, this is project is awesome.

I'm running through the readme, trying to get your sample code working. Getting a few errors.

Here is my setup...
-HP 7475A Plotters with RS-323 serial port
-RS-323 is being converted to usb with a cable, i'm assuming it is a ftdi cable.
-I set the pins like this
image
-I'm on a mac, OSX 10.12.4
-Running Node v6.10.2

Here is my code, taken from your readme

// 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});

// 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!");
 
});

When I run node test.js, I get the following error.

Error: Error: No such file or directory, cannot open /dev/tty.usbserial
    at Error (native)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Error: No such file or directory, cannot open /dev/tty.usbserial
    at Error (native)

So I look inside the dev folder. True there is no file. But there is a file called dev/tty.usbserial-A800I9VI

So I altered the transport to reflect this file
var transport = new SerialPort("/dev/tty.usbserial-A800I9VI", {autoOpen: false});

And now when I run the file I get a different error...

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Device initialization timed out.
    at Timeout.setTimeout (/Users/awdriggs/code/nodeplot/node_modules/hpgl/hpgl.js:837:16)
    at ontimeout (timers.js:380:14)
    at tryOnTimeout (timers.js:244:5)
    at Timer.listOnTimeout (timers.js:214:5)

Then the error light starts flashing and I have to toggle the power to try again.

Any ideas? Could it be a cable issue? Any help would be greatly appreciated.

Adam

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.