{"id":13650229,"url":"https://github.com/rhalkyard/plotadapter","last_synced_at":"2025-04-22T18:31:07.664Z","repository":{"id":149618987,"uuid":"491322525","full_name":"rhalkyard/plotadapter","owner":"rhalkyard","description":"Serial-GPIB converter for HP plotters","archived":false,"fork":false,"pushed_at":"2022-05-12T01:20:33.000Z","size":11,"stargazers_count":21,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-08-03T02:03:50.638Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhalkyard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-05-12T01:20:11.000Z","updated_at":"2024-07-01T06:08:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"6676ecb0-754d-4f14-8e1e-1f7eab53b548","html_url":"https://github.com/rhalkyard/plotadapter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhalkyard%2Fplotadapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhalkyard%2Fplotadapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhalkyard%2Fplotadapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhalkyard%2Fplotadapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhalkyard","download_url":"https://codeload.github.com/rhalkyard/plotadapter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223903071,"owners_count":17222485,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T02:00:35.102Z","updated_at":"2024-11-10T01:30:37.994Z","avatar_url":"https://github.com/rhalkyard.png","language":"C++","readme":"# PlotAdapter: Serial-GPIB converter for HP Plotters\n\n## Introduction\n\nOlder Hewlett-Packard pen plotters usually had an RS232 interface, but they were\nalso available with GPIB (a.k.a. HP-IB, a.k.a. IEEE-488), a popular interface\nfor laboratory equipment, also seen on HP's own 9800 series of computers.\n\nWhile GPIB interfaces are still available, both as (expensive) commercial\nproducts and as open-source hardware, they are not well-suited to the task of\ncontrolling a plotter - most PC software expects to talk to a plotter over a\nserial port, not the VISA APIs typically used by GPIB adapters. Additonally,\nmany of the serial-port-based GPIB adapters are more suited to\ninstrument-control applications - sending and receiving short commands and\nresponses - and as such lack the flow-control mechanisms needed for successful\nplotter operation.\n\nFurthermore, HP's RS232 plotters supported a wide range of serial handshaking\noptions, and implemented an additional set of escape sequences to configure\nthis. Many applications send these escape sequences before and during plotting,\nand expect the plotter to respond accordingly - for example, HPGL plots\ngenerated by Autocad contain escape sequences to put the plotter into\n`XON`/`XOFF` handshaking mode.\n\nPlotAdapter aims to emulate this extended command set, allowing a GPIB plotter\nto be 'converted' to an RS232 interface and used by software that expects to\ncommunicate with an RS232-connected plotter.\n\n## Getting Started\n\n### Hardware\n\nYou will need:\n\n* An HPGL plotter with a GPIB interface (e.g. a 7470A with Option 002)\n\n* An AVR-based Arduino with 5 volt IO and 14 available pins (I am using a Mega\n  2560)\n\n* A GPIB cable with some way of connecting it to the Arduino\n\n* (optional) a USB-serial interface with support for serial handshaking (see\n  \"Flow Control Limitations\" section below for details)\n\n### Software\n\nIt is crucial to use some form of flow control when sending data to the plotter.\nMany plotter operations are time-consuming, and without flow control, it is very\nlikely that a buffer overrun will occur. This is complicated by the fact that\nthe driver for the Arduino's USB-serial interface does not handle `XON`/`XOFF`\nflow-control correctly.\n\nThe best way to send data to the plotter is to use a dedicated program that is\naware of the plotter's escape sequences, and can set up a workable flow-control\nconfiguration itself. I wrote [hpplot](https://github.com/rhalkyard/hpplot) for\nthis purpose.\n\n### Building `plotadapter`\n\n1. Open `plotadapter.ino` in any recent version of the Arduino IDE\n\n2. Using the Library Manager (Tools ➡ Manage Libraries...), install the\n   \"FreeRTOS\" library\n\n3. Open `config.h` and edit the pin definitions, plotter address, and other\n   parameters to suit your setup.\n\n## Notes\n\n### Plotter Models\n\nI wrote this project for my HP 7470A, but there is no reason this shouldn't work\nfor other similar plotters in the series.\n\n### Software Architecture\n\n`plotadapter` is implemented as a pair of tasks running on FreeRTOS -\n`serial_task` reads bytes from the serial port, handles escape sequences, and\ninserts received data into a ring buffer. `gpib_task` reads data from the ring\nbuffer, and transmits it via a very crude bit-banged GPIB implementation.\n\n`gpib_task` also monitors the data stream for HPGL commands that are known to\ngenerate output (any command beginning with `O` - `OI`, `OE`, `OD`, etc.). When\nan output command has been sent, it sends a GPIB `TALK` command to the plotter\nand waits for a response, which it sends to the serial port.\n\nIf a GPIB operation times out (the timeout is configurable as `GPIB_TIMEOUT` in\n`config.h.`, default is 30 seconds), the bus is reset by asserting `IFC`, the\ncommand buffer is purged, and `gpib_thread` is restarted. This also occurrs if\nthe \"Abort Output\" escape sequence `ESC . K` is received.\n\nIn hindsight, FreeRTOS is probably overkill for a simple project such as this,\nand it could be rewritten using [protothreads](http://dunkels.com/adam/pt/) or\neven just as a plain event loop. However, implementing GPIB and serial IO as two\nindependent tasks made it easier to reason about their interactions, and allowed\nthe GPIB implementation to be a simple piece of procedural code, rather than a\nconvoluted state machine. I regret nothing.\n\n### Features\n\nThe following RS232 interface features are supported:\n\n* DTR flow control (when using an external serial adapter)\n\n* Echo mode setting with `ESC . @` (echo off, immediate echo, echo when character\n  processed)\n\n* Reporting available buffer space with `ESC . B`\n\n* Reporting total buffer size with `ESC . L`\n\n* Software low control (either `ENQ`/`ACK` or `XON`/`XOFF`) using Handshake\n  Modes 1 (`ESC . H`) or 2 (`ESC . I`) - see section below on limitations\n\n* Output-initiator and output-terminator characters\n\nThe following features are NOT supported due to architectural limitations:\n\n* Reporting plotter status with `ESC . O` (querying plotter would interrupt HPGL\n  command stream - returns status byte of `0` instead)\n\n* Plotter enable/disable with `ESC . (` and `ESC . )`\n\nThe following features could be supported but I'm too lazy right now\n\n* Inter-character and turnaround delay\n\n* Echo-terminator and output-trigger characters\n\n* Reporting RS232 error status with `ESC . E` (currently always returns `0`)\n\n* Emulation of Circle and Arc HPGL commands that are present on RS232-equipped\n  7470As, but not on GPIB models.\n\n### Flow-Control Limitations\n\nThe driver for the onboard USB-Serial converter appears to ignore `XON`/`XOFF`\nflow-control. Since we cannot use DTR flow control either, this needs to be\nworked around by either:\n\n* Attaching an external USB-serial interface (with funcitoning flow control) to\n  the Arduino's serial pins\n\n* Configuring/rewriting the application to use an alternate form of flow control\n  (either `ENQ`/`ACK` or by checking available buffer space with `ESC . B`\n  before sending)\n\n### GPIB Bus limitations\n\nThis is *not* a fully-compliant GPIB implementation by any means - it works OK\nif the plotter is the only device on the bus, but it will probably not be able\nto drive a longer bus, and may not coexist well with other devices anyway.\n","funding_links":[],"categories":["Hardware"],"sub_categories":["Accessories and Adapters"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhalkyard%2Fplotadapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhalkyard%2Fplotadapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhalkyard%2Fplotadapter/lists"}