M.printer

M.printer.write(s)

 

Description: Sends data to the printer. Returns true if successful, false on error.

Syntax: local ok = M.printer.write(s)

Input:  s (string)
Returns: boolean

Supported in MASSO software v5.13 & API Version: 1.0.0

 

Formats & Protocols: 

  • You can send raw data in the printer's native language.
  • **ZPL** (Zebra Programming Language) — common on Zebra thermal label printers.
  • **PCL / PCL5 / PCL XL (PCL6)** — common on HP LaserJet and many office printers.
  • Others, if your device supports them (e.g., ESC/POS, PDF direct, HP?GL/2 within PCL).

 

 

 

CAUTION: You must compose the correct command stream for the target printer. If the printer expects ZPL and receives plain text, nothing will print. Likewise, PCL devices need PCL (or text) unless configured otherwise. 

 

 

ZPL Example — 4x6" label with Title, QR Code, and Fields: 

-- Build a simple 4x6 inch label
local job_id  = "JOB-12345"
local customer = "ACME Pty Ltd"
local part   = "Panel A - Ø6.35"
local url   = "https://docs.masso.com.au/job/JOB-12345"

-- ZPL notes:
-- ^XA ... ^XZ : start/end label
-- ^PW : label width in dots (e.g., 4" at 203dpi = 812)
-- ^LH : label home (origin)
-- ^FOx,y : field origin
-- ^A0 : font A
-- ^FD : field data
-- ^FS : end of field
-- ^BQN,2,10 : QR code, Model 2, mag 10 (tune to printer)
-- ^FDLA,<data> : QR data (LA = Automatic input mode)

local zpl = table.concat({
 "^XA",
 "^PW812",       -- 4" @ 203dpi
 "^LH0,0",

 -- Title
 "^FO50,40^A0N,60,60^FDMASSO Label^FS",

 -- QR Code block
 "^FO520,40",
 "^BQN,2,8",      -- QR: model 2, magnification 8
 "^FDLA,"..job_id.."|"..url.."^FS",

 -- Fields
 "^FO50,140^A0N,40,40^FDJob:^FS",
 "^FO180,140^A0N,40,40^FD"..job_id.."^FS",

 "^FO50,200^A0N,40,40^FDCustomer:^FS",
 "^FO250,200^A0N,40,40^FD"..customer.."^FS",

 "^FO50,260^A0N,40,40^FDPart:^FS",
 "^FO180,260^A0N,40,40^FD"..part.."^FS",

 -- Footer timestamp (from system clock if desired)
 -- e.g., pre-generate with M.sys.get_clock_time()
 "^FO50,340^A0N,30,30^FDRuntime:^FS",
 "^FO200,340^A0N,30,30^FD"..string.format("%02d:%02d:%02d", 0, 12, 33).."^FS",

 "^XZ"
}, "
")

local ok = M.printer.write(zpl)
if not ok then
 M.gui.show_message("Printer", "ZPL send failed")
end

 

 

PCL Example

PCL devices (e.g., HP LaserJet) accept escape sequences. Below is a minimal PCL5 text example. Note that QR codes are not native to PCL5; for 2D codes you can either: (a) render a raster image and embed it, (b) use PCL XL (PCL6) with suitable soft fonts, or (c) print via ZPL on a Zebra. 

M.gui.show_message(“Hello, World!”,”Welcome to MASSO Custom Scripts”)


M.printer.write(“\027%-12345X@PJL ENTER LANGUAGE=PCL \027E \ 027&l26A \027&a15H\027(s1p37v0s0b4099T”)
M.printer.write(“\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nHello, World!\r\n\r\n\r\n\r\n\r\n\r\nWelcome to “)
M.printer.write(“\027(s3BMASSO\027(s0B”)
M.printer.write(“ Custom Scripts”)
M.printer.write(“\027%-12345X”)