Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Virtual POS-80 Network Printer Emulator

A high-fidelity, interactive Virtual ESC/POS 80mm Thermal Printer and development tool built in Go.

It acts as a physical network printer by listening on the standard print port (9100) and serves a beautiful, real-time web-based visualizer dashboard on port 8080.

This tool is designed for POS billing application developers to test receipt layouts, formatting, graphics, and barcodes without needing a physical thermal printer.


🚀 Key Features

  • Zero-Dependency Binary: Single compiled Go executable with embedded frontend assets (embedded using go:embed). Runs fully offline on Windows, macOS, or Linux.
  • LAN Network Support: Binds to 0.0.0.0, allowing billing apps running on other devices (tablets, smartphones, test servers) on the same local network to print directly to it.
  • Dual Inbound Trigger Modes:
    • Connection-Closed: Triggers a print job render immediately when the TCP connection is closed.
    • Inactivity Timeout: Automatically flushes and renders buffered bytes if no new data is received for 500ms (supports persistent connections).
  • High-Fidelity Virtual Visualizer:
    • Matte grey thermal printer chassis mockup with status LEDs.
    • Shrinking paper roll visualizer indicating roll depletion.
    • HTML5 Web Audio API mechanical sound effects (Humming motor, feed clicking, paper tearing).
    • Jagged-edge "Tear-Off" button to split and save receipts.
  • Developer Inspection Tools:
    • Thermal Preview: High-fidelity render resembling physical thermal paper (fading ink, paper texture, custom monospace character spacing).
    • Inspect Grid: Bounding boxes around rows, alignment guides, and padding tags.
    • Syntax-Highlighted Hex Viewer: Dual-pane hex editor showing raw bytes color-coded by print category (Neon purple for control codes like ESC/GS, green for formatting parameters, red for line breaks, white for letters).
    • Console Presets: Quick-print buttons for standard templates (Retail Invoice, Kitchen Order Ticket, Font Formats, Barcode Sheet) and manual custom line injections.
  • History Logs: Save previously printed receipts, export them as PNG images, copy layout HTML, or download raw .bin bytes.

🛠️ How It Works

┌──────────────────────────┐             ┌──────────────────────────┐
│   POS Billing App        │             │   Browser Dashboard      │
│   (Localhost or LAN)     │             │   (Port 8080)            │
└────────────┬─────────────┘             └────────────▲─────────────┘
             │                                        │
     RAW TCP (Port 9100)                     WebSocket Broadcast
             │                                        │
             ▼                                        │
┌─────────────────────────────────────────────────────┴─────────────┐
│                      Go Backend Server                            │
└───────────────────────────────────────────────────────────────────┘
  1. Your billing app sends raw ESC/POS bytes over TCP to Port 9100.
  2. The Go backend TCP socket listener receives the data and buffers it.
  3. Once the connection is closed or inactivity is detected, the Go backend broadcasts the byte array over WebSockets.
  4. The browser's JavaScript engine parses the raw bytes into a virtual layout tree, renders fonts/images/barcodes on the fly, and spools the virtual receipt.

📦 Getting Started

Prerequisites

  • Go (1.20 or newer, only if building from source).

Running the Precompiled Binary (Windows)

Double-click pos80mock.exe or execute it in your terminal:

.\pos80mock.exe

Building and Running from Source

  1. Clone or navigate to the directory:
    git clone https://github.com/your-username/pos-80-mock.git
    cd pos-80-mock
  2. Install dependencies (Gorilla WebSocket library):
    go get github.com/gorilla/websocket
  3. Build and run:
    go run main.go

Command Flags

You can customize the ports by passing flag arguments:

.\pos80mock.exe --tcp-port=9100 --http-port=8080

💻 Connecting Your Billing App

Configure your application's printer settings:

  • Printer Type: Network Printer / Ethernet / RAW TCP
  • IP Address: Your computer's local IP address (e.g., 192.168.1.15 - shown on the dashboard screen) or localhost/127.0.0.1 if running on the same computer.
  • Port: 9100

📟 Supported ESC/POS Commands

Command Hex Bytes Description
LF 0x0A Print and line feed
HT 0x09 Horizontal tab
ESC @ 0x1B 0x40 Initialize printer (resets settings)
ESC ! n 0x1B 0x21 n Select print mode (bold, double-height, double-width, underline)
ESC - n 0x1B 0x2D n Turn underline mode on/off
ESC E n 0x1B 0x45 n Turn emphasized (bold) mode on/off
ESC a n 0x1B 0x61 n Select justification (0: Left, 1: Center, 2: Right)
ESC d n 0x1B 0x64 n Print and feed n lines
ESC * m nL nH d... 0x1B 0x2A ... Select bit-image mode (column graphics)
GS ! n 0x1D 0x21 n Select character size (magnify width/height up to 8x)
GS B n 0x1D 0x42 n Turn white/black reverse printing on/off
GS V m / GS V m n 0x1D 0x56 ... Paper cut (full or partial)
GS v 0 m xL xH yL yH d... 0x1D 0x76 0x30 ... Print raster bit image (row graphics, standard logo printing)
GS k m d... NUL / GS k m n d... 0x1D 0x6B ... Print barcode (rendered as Code 39)
GS ( k pL pH cn fn ... 0x1D 0x28 0x6B ... QR Code data store and print commands

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Virtual ESC/POS 80mm thermal printer mock server and visualizer dashboard in Go and HTML5. Test receipt printing over local network (LAN) on TCP Port 9100.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages