djipco / hpgl

A Node.js library to communicate with HPGL-compatible plotters and printers.
MIT License
38 stars 4 forks source link

Timeout error #2

Closed awdriggs closed 7 years ago

awdriggs commented 7 years ago

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

djipco commented 7 years ago

Your hardware settings are good and the path to the device (/dev/tty.usbserial-A800I9VI) is most likely right (otherwise you wouldn't see that file inside /dev).

The error you are getting means that the device did not answer the library's initialization request (or that it took too long).

You could try to increase the delay. Go inside node_modules/hpgl/hpgl.js. You will find a block similar to this one around line 517. Change the value to a higher number and see if it works.

Object.defineProperty(this, "DEVICE_INIT_DELAY", {
  enumerable: true,
  writable: false,
  value: 150
});
awdriggs commented 7 years ago

Ok. I increased to 1000. Didn't help...

I'm also getting this error...

Error: Error: Resource busy, cannot open /dev/tty.usbserial-A800I9VI
    at Error (native)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Error: Resource busy, cannot open /dev/tty.usbserial-A800I9VI
    at Error (native)
 ~/code/nodeplot    

Currently the "error" light on the printer is flashing as soon as I turn it on if it is plugged into my usb.

awdriggs commented 7 years ago

One more try for the day. I installed an FTDI Driver.

I was able to get a new error now...

Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
Warning: Bad communication with the device. Attempting once more.
(node:17418) Warning: Possible EventEmitter memory leak detected. 11 data listeners added. Use emitter.setMaxListeners() to increase limit

Does that change anything?

Adam

djipco commented 7 years ago

You definitely need to install the driver that came with your USB-to-serial cable. The error you are now getting (Warning: Bad communication with the device. Attempting once more.) means that the device is not answering buffer size request from the library.

It's hard to tell from here what's going on. I have the same device (HP 7475A) and it works fine.

awdriggs commented 7 years ago

So I'm thinking I need a different cable. Can't remember where this one came from and what driver to use. We'll see if that fixes the problem! I'll let you know.

djipco commented 7 years ago

Okay. I'll close this issue for now. You can always open a new one later.

awdriggs commented 7 years ago

Thanks for all your help. I really appreciate the project.

What type of cable are you using?

djipco commented 7 years ago

What type of cable are you using?

This is the cable I bought. I got it on Amazon. It was sold under the IOCrest brand but it's the same cable. It uses the Prolific USB-to-Serial chip. You can download the driver on the product's page under download.

By the way, I uploaded a new version which may fix your issue. Try it out before buying a new cable.