@cutos/device-receipt-printer
v4.1.0
Published
CUTOS 4.0 Receipt Printer Capability SDK
Readme
@cutos/device-receipt-printer
CUTOS 4.0 Receipt Printer Capability SDK.
- Package:
@cutos/device-receipt-printer - Version:
4.1.0 - Capability:
capability.device.receipt-printer - Runtime dependency:
@cutos/core >= 4.0.8
The SDK defines vendor-neutral receipt-printing operations. Hardware access and vendor DLLs belong to a concrete Provider and are not included in this package.
Install
npm install @cutos/core @cutos/device-receipt-printerQuick start
import { CoreAPI } from "@cutos/core"
import { DeviceCapabilityReceiptPrinter } from "@cutos/device-receipt-printer"
await CoreAPI.init("localhost")
const printer = new DeviceCapabilityReceiptPrinter()
await printer.init()
printer.onData(event => console.log("data", event))
printer.onStatus(status => console.log("status", status))
printer.onError(error => console.error("error", error))
await printer.connect()
console.log(await printer.readDeviceInfo())
console.log(await printer.getStatus())
await printer.printText({
text: "Hello CUTOS",
alignment: "center",
width: 2,
height: 2,
bold: true
})
await printer.feed({ dots: 240 })
await printer.backFeed({ dots: 40 })
await printer.printQrCode({
content: "https://www.cut-os.com",
size: 6,
leftMargin: 0
})
await printer.feed({ dots: 240 })
await printer.cut({ mode: "partial" })
await printer.disconnect()Connection
The default connection and supported transports are Provider-specific.
await printer.connect() // use Provider defaults
await printer.connect({ connection: "usb" }) // USB auto detection
await printer.connect({ connection: "usb", port: "USB001" })
await printer.connect({ connection: "serial", port: "COM1", baudRate: 115200 })Supported baud rates are 9600, 38400, and 115200.
Printing
printText(params)
await printer.printText({
text: "Receipt line",
alignment: "left", // left | center | right
width: 1, // 1-8
height: 1, // 1-8
bold: false,
lineFeed: true
})Formatting belongs to this operation and is not shared as mutable SDK state. The result is { success: true } when the Provider accepts the operation.
printQrCode(params)
await printer.printQrCode({
content: "https://www.cut-os.com",
size: 6, // 1-8
leftMargin: 0 // 0-27 mm
})feed(params)
await printer.feed({ dots: 240 })dots ranges from 0 to 250. On the MS-MA90 Provider one dot is 0.125 mm, so 240 dots advances approximately 30 mm.
Printing text or a QR code does not implicitly advance paper to the outlet. Call feed() explicitly when the application needs additional paper movement.
backFeed(params)
await printer.backFeed({ dots: 40 })Reverse-feeds paper by 0 to 250 dots. This operation requires a Provider and printer that support reverse paper movement. The MS-MA90 Provider maps it to the vendor SDK's PrintBackDot() function. Start with a small value such as 40 dots when testing hardware.
cut(params)
await printer.cut({ mode: "partial" }) // partial | fullgetStatus()
Returns:
{
code: number
state: "ready" | "offline" | "head-open" | "cutter-error" |
"temperature-error" | "blackmark-error" | "paper-out" |
"paper-low" | "unknown"
ready: boolean
message: string
}Base Device API
DeviceCapabilityReceiptPrinter inherits the standard Device Capability methods:
init()connect()disconnect()readDeviceInfo()onData(listener)onStatus(listener)onError(listener)dispose()
Keep the unsubscribe function returned by each event method and call dispose() when the LWA no longer uses the device.
