This manual documents HS-POS PrinterSDK for Windows / C++, aligned with Android 1.6.3.
Version: 1.6.3-windows-cpp
Platform: Windows 10 / 11, C++17 (CMake / MSVC or MinGW)
Namespace:hspos
Last updated: 2026-07-18
Android counterpart PDFs:PrinterSDK_User_Manual.pdf,PrinterSDK_使用说明书.pdf
Companion docs: PrinterSDK_API_Documentation.md, PrinterSDK_API_说明文档.md, PrinterSDK_Windows_CPP_API对照表.mdImportant (C++):
FeedPaper(conn, n)feeds dots (ESC J). For lines, usePrintAndFeedLines. PreferFeedAndCutPaperto finish receipts.
PrinterSDK (Windows C++) is a native C++17 implementation of HS-POS PrinterSDK, aligned with Android package com.hspos.printerSDK 1.6.3 and the Windows C# SDK. It supports ESC/POS receipt printing and JPL label printing through one façade class: PrinterSdk.
| Feature | Description |
|---|---|
| Multi-channel | USB, Bluetooth SPP, TCP/IP (port 9100), Serial (COM), Parallel (LPT) |
| Standard POS | Text, 1D barcode, QR, PDF417, double QR, raster images, cut, cash drawer, beep, self-test |
| Page mode | Coordinate drawing for text / barcode / QR / line / rectangle |
| Label mode | JPL page begin/print, text, barcode, QR, PDF417, images, shapes |
| Encodings | PrintTextInUtf8 / PrintTextInGbk; other encodings via SetDoubleByteEncoding |
| Status | DLE EOT / GS r helpers: online, paper, cover |
| No managed runtime | Pure native library (no .NET dependency) |
#include "hspos/HsposPrinterSdk.hpp"
using namespace hspos;
auto& sdk = PrinterSdk::GetInstance();
| Type | Role |
|---|---|
PrinterSdk |
Singleton façade |
PrinterConstants |
Shared constants (PrinterConstants::AlignmentCenter) |
IPrinterConnection |
Connection interface, held as std::shared_ptr |
Naming vs Android: PrinterSDK → PrinterSdk; camelCase → PascalCase; PrinterConnection → shared_ptr<IPrinterConnection>.
| Item | Requirement |
|---|---|
| OS | Windows 10 / 11 (x64) |
| Language | C++17 |
| Build | CMake 3.20+ |
| Compiler | MSVC (VS 2022) or MinGW-w64 (MSYS2 UCRT64) |
| Image decode | Windows WIC (windowscodecs, ole32) |
cd "C:\Windows Project\PrinterAPI_CPP"
cmake -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DHSPOS_BUILD_SHARED=OFF
cmake --build build -j
Artifacts: libHspos.PrinterSdk.a (or DLL), win_demo.exe, console_demo.exe.
Also see docs/如何编译.md and docs/如何运行.md.
PrinterAPI_CPP/
├── include/hspos/ # public headers (HsposPrinterSdk.hpp umbrella)
├── src/ # implementation
├── samples/console_demo/ # CLI demos
├── samples/win_demo/ # GUI test tool
└── docs/ # this manual + API handbooks
Your Windows C++ application
│
▼
PrinterSdk::GetInstance()
├── Connection / POS / Page / Label / Status
│
▼
std::shared_ptr<IPrinterConnection>
USB / BT / Network / Serial / Parallel
│
▼
Physical printer
Always verify connection && connection->IsConnected() before printing.
#include "hspos/HsposPrinterSdk.hpp"
using namespace hspos;
int main() {
auto& sdk = PrinterSdk::GetInstance();
auto conn = sdk.ConnectNetworkPrinter("192.168.1.100", 9100);
if (!conn || !conn->IsConnected()) return 1;
sdk.InitPrinter(conn);
sdk.SetChineseMode(conn);
sdk.SetDoubleByteEncoding(conn, PrinterConstants::DoubleByteEncodingGbk);
sdk.SetAlignment(conn, PrinterConstants::AlignmentCenter);
sdk.PrintTextInGbk(conn, "Hello PrinterSdk\n");
sdk.FeedAndCutPaper(conn);
sdk.DisconnectPrinter(conn);
sdk.Release();
return 0;
}
Windows has no Android-style runtime permission model. Device access depends on drivers and Device Manager.
| Channel | Notes |
|---|---|
| Serial | Match baud/parity/flow; confirm COM name in Device Manager |
| Parallel | LPT1–3; usually write-only |
| USB | USB printing support / vendor driver; reopen after SDK upgrades |
| Bluetooth | Pair in Windows Settings or PairBluetoothDevice; discovery is blocking |
| Network | Same LAN, TCP 9100, firewall allow outbound |
Android-only APIs not present: hasUsbPermission, requestUsbPermission, onRequestPermissionsResult, getCommunicationManager.
Failed connects return an empty shared_ptr.
auto devices = PrinterSdk::GetUsbDevices();
if (!devices.empty()) auto c = sdk.ConnectUsbPrinter(devices[0]);
auto c2 = sdk.ConnectUsbPrinter("USB001");
auto paired = PrinterSdk::GetBluetoothPairedDevices();
auto found = PrinterSdk::DiscoverBluetoothDevices(true); // blocking
if (!paired.empty()) auto c = sdk.ConnectBluetoothPrinter(paired[0]);
PrinterSdk::StopBluetoothDiscovery();
auto c = sdk.ConnectNetworkPrinter("192.168.1.100", 9100);
Async connect is not implemented yet; call from a worker thread in UI apps.
SerialPortSettings s;
s.portName = "COM3";
s.baudRate = 115200;
auto c = sdk.ConnectSerialPrinter(s);
auto ports = PrinterSdk::ListSerialPorts();
auto c = sdk.ConnectParallelPrinter("LPT1");
sdk.DisconnectPrinter(c);
InitPrinter / ResetPrinter
PrintText / PrintTextInUtf8 / PrintTextInGbk / PrintTextLineLeftRight
Magnification: SetTextScale(widthScale, heightScale) (0–7).
Alignment, bold, underline, reverse, line spacing, Chinese mode / double-byte encoding, print area width/margin.
PrintBarcode / PrintQrCode / PrintQrCodeStandard / PrintPdf417 / PrintDoubleQrCode
PrintRasterImageFromPixels / FromFile / FromData (GS v 0; WIC for files).
Widths: PaperWidth58Mm (384) / PaperWidth80Mm (576).
| API | Unit / meaning |
|---|---|
FeedLine |
LF |
FeedPaper(n) |
dots (ESC J) |
PrintAndFeedLines(n) |
lines (ESC d) |
CutPaper |
CutPartial=ESC m, CutFull=ESC i |
FeedAndCutPaper |
feed then one partial cut (recommended) |
OpenCashDrawer / Beep / SelfTest / SendCommand
Flow: SelectPageMode / SelectPageModeEx → draw → PagePrintPage → ExitPageMode.
Includes UTF-8/GBK text, centered/right/left-right helpers, barcode (+ centered HRI), QR, line, rectangle, estimators.
Flow: EnableLabelMode → LabelPageBegin → draw → LabelPagePrint → DisableLabelMode.
Supports text, barcode, QR, PDF417, images, lines, rectangles, boxes, back-paper.
| API | Role |
|---|---|
QueryRtStatus |
DLE EOT |
QueryTransmitStatus |
GS r |
GetPrinterStatus |
Combined flags |
IsPrinterOnline / HasPaper / IsCoverOpen |
Convenience |
See PrinterConstants.hpp and the API handbook constants section (alignment, cut, paper widths, barcode/QR, status bits, encodings, page directions, raster modes).
auto& sdk = PrinterSdk::GetInstance();
auto c = sdk.ConnectNetworkPrinter("192.168.1.100", 9100);
sdk.InitPrinter(c);
sdk.SetAlignment(c, PrinterConstants::AlignmentCenter);
sdk.PrintTextInGbk(c, "收银小票\n");
sdk.PrintQrCodeStandard(c, "https://example.com", 6, 1, PrinterConstants::QrEccLevelM);
sdk.FeedAndCutPaper(c);
sdk.DisconnectPrinter(c);
sdk.EnableLabelMode(c);
sdk.LabelPageBegin(c, 0, 0, 400, 300, 0);
sdk.PrintLabelTextGbk(c, "标签", 20, 20);
sdk.PrintLabelQrCode(c, "ABC123", 20, 80);
sdk.LabelPagePrint(c, 1);
sdk.DisableLabelMode(c);
Demos: win_demo.exe, console_demo.exe receipt58 <ip> 9100.
| Symptom | Hint |
|---|---|
| Garbled Chinese | GBK mode + PrintTextInGbk |
| Cut too close | FeedAndCutPaper; cutter offset ~10–20mm |
| Cut twice | Send only one cut command |
| USB status wrong | Reopen read/write; reconnect |
| BT discovery freezes UI | Use a worker thread |
| Topic | Android | C# Windows | C++ Windows |
|---|---|---|---|
| Runtime | ART + permissions | .NET 8 | Native C++17 |
| Handle | PrinterConnection |
IPrinterConnection |
shared_ptr<IPrinterConnection> |
FeedPaper |
see Android docs | often lines overload | dots (ESC J) |
| Parallel port | ❌ | ✅ | ✅ |
| Async network | ✅ | ✅ | ❌ (pending; documented as placeholder) |
| USB permission APIs | ✅ | N/A | N/A |
API completeness: Implemented methods are in PrinterSDK_API_Documentation.md. Android APIs not yet in C++ (and Android-only APIs) are listed there under Not Yet Implemented / Android-only placeholders with planned signatures and workarounds. See also Android_API覆盖对照.md.
Aligned with Android PDFs under PrintertestAPP\DOC\:
| Doc | Language |
|---|---|
| PrinterSDK_使用说明书.md | ZH user manual |
| PrinterSDK_User_Manual.md | EN user manual |
| PrinterSDK_API_说明文档.md | ZH API |
| PrinterSDK_API_Documentation.md | EN API |
| Version | Date | Notes |
|---|---|---|
| 1.6.3-windows-cpp | 2026-07-18 | First Windows C++ docs/SDK package aligned with Android 1.6.3 handbook structure |