Skip to main content

NiimPrint 精臣打印机Python库

🚀 功能特性

  • 自动连接 NIIMBOT 打印机(指定 COM 端口)
  • 获取设备信息:型号、固件版本、序列号
  • 实时检测纸张状态(有纸/无纸)
  • 读取 RFID 智能标签信息(UUID、条码、序列号、容量等)
  • 打印任意图像(自动转换为 1-bit 黑白图)
  • 支持自定义标签尺寸(单位:毫米)

📦 安装

  • Install from source (Recommend)
cd niimprint
pip install -e .
  • Install from PyPI
pip install niimprint

🚀 快速开始

🖨️ 使用示例

from niimprint import PrinterClient, SerialTransport
from niimprint import InfoEnum

# 1. 连接打印机
transport = SerialTransport(port="COM9")
printer = PrinterClient(transport)

# 2. 获取设备信息
print("设备类型:", printer.get_info(InfoEnum.DEVICETYPE))
print("固件版本:", printer.get_info(InfoEnum.SOFTVERSION))

# 3. 检查耗材状态
status = printer.heartbeat()
if status.get('paperstate') == 0:
    print("✅ 有纸,可打印")

# 4. 打印图像
img = Image.open("test.jpg").resize((384, 160))
printer.print_image(img, density=3)  # density: 1~5

📐 标签尺寸设置

修改以下参数以匹配你的标签纸:

width_mm = 30   # 标签宽度(毫米)
height_mm = 30  # 标签高度(毫米)

程序会自动按 203 dpi 转换为像素尺寸。

⚠️ 注意事项

  • 确保打印机已通过 USB 连接并识别为 COM 端口(如 COM9)
  • 首次使用建议先运行设备信息查询,确认通信正常
  • 图像将被转换为 黑白 1-bit 模式,彩色/灰度图会自动处理
  • 打印浓度 density 范围:1(最浅)~ 5(最深),推荐值:3

🙏 特别声明

本项目基于niimbot的开源项目,核心协议实现参考自 niimprint 。

🔹 本项目仅为个人学习与便捷使用而开发

🔹 所有协议解析与通信逻辑均源自社区贡献

🔹 如官方需要,本人愿意将相关代码与改进交还给官方或原作者

我们尊重 NIIMBOT 官方知识产权,本项目不用于商业分发,仅作为技术探索与自动化打印的实践示例。

📬 反馈与支持

如遇问题,请提供:

  • 打印机具体型号(如 B1、B21 Pro)
  • 标签纸类型(普通/RFID)
  • 错误日志或现象描述
  • 欢迎提交 Issue 或 PR

保持热爱,奔赴星海! 这个世界上唯有两样东西能让我们的心灵感到深深的震撼:一是我们头上灿烂的星空,一是我们内心崇高的道德法则

Metadata

Release files for niimprint 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for niimprint 0.0.1
File Size Uploaded
niimprint-0.0.1.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for niimprint 0.0.1
File Interpreter ABI Platform
niimprint-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.4 kB

Release files / niimprint-0.0.1.tar.gz

Download URL niimprint-0.0.1.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
65867a63e0a30a04d07fa3b7206781ffb0873e50547f090b9348a0f03f8c09e2
BLAKE2b-256 checksum
How to use checksums
48e77d444fc7478ddeceb5c0d3a7901dfa3e4cd89b4f479c756d92cd9e1d0466
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.9.13 Windows/10

Release files / niimprint-0.0.1-py3-none-any.whl

Download URL niimprint-0.0.1-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f17583750a0f639cba573193b6e10948f39c8e2eb50d63fee6cac194419f6ed3
BLAKE2b-256 checksum
How to use checksums
cf97b11a1225e4c80cf12f159d22b02bd801f653649eda72d4061c877f07a087
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.9.13 Windows/10

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page