npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chn-escpos

v1.1.4

Published

Chinese ESC/POS Printer driver for nodejs

Downloads

1

Readme

chn-escpos

介绍

chn-escpos是一个nodejs的window POS机打印程序,使用printer的C组件与打印机通信,使用ESC/POS命令控制打印机

更新日志

2016-04-25 1.1.4 修复钱箱命令在部分打印机不能使用的问题
2016-04-22 1.1.3 修复一个打印二维码的BUG
2016-04-18 1.1.1 修改setSize方法,并修复setSize(1)还原样式错误的问题.增加beep(打印机蜂鸣),qrcode(打印二维码)功能.
2016-03-28 1.1.0 增加开钱箱命令,额外增加一个sendCmd命令,与开钱箱命令配合(print命令会额外发送一个切刀指令和初始化指令).与1.0.*的命令兼容

安装

npm install chn-escpos --save

测试

你可以使用chn-escpos自带的测试程序进行测试

cd node_modules/chn-escpos
npm test

测试程序默认监听2520端口,你可以通过向http://127.0.0.1:2520?action=print&printer=POST raw数据进行打印测试(推荐使用POSTMAN进行测试)

//发送打印指令
POST  HTTP/1.1
Host: 127.0.0.1:2520?action=print
Content-Type: application/javascript
Cache-Control: no-cache
Postman-Token: 3ae7055f-8dd9-5386-3cfe-4355d7b7645a

[
    {
        "id": "1",//打印任务ID
        "group_id": "1",//打印队列ID
        "printer": "XP-80C",//打印机别名
        "content": "<% setAlign:c %>测试居中"
    }
]

//发送钱箱指令
POST  HTTP/1.1
Host: 127.0.0.1:2520?action=cmd
Content-Type: application/javascript
Cache-Control: no-cache
Postman-Token: d04979f1-9e17-3647-90be-defa7430109d

[
    {
        "id": "957",
        "group_id": "322",
        "printer": "XP-80C",
        "content": "<% openCashbox:'' %>"
    }
]

使用方法

var printer=require('chn-escpos'),
printer_name='XP-80C';
new printer(printer_name,function(err,msg){
    //调用this方法进行打印
});

打印方法

####text(text,[inline]) 打印文字内容 string text:打印内容,单行数据,如果超出自动换行
boolen inline:是否自动换行,如果为true,则不会自动换行

this.text('测试打印');

####line(number) 空行
number number:空行数

this.line(2);

####setAlign(align) 设置对齐 string align:C/L/R分别代表居中/居左/居右,不区分大小写

this.setAlign('c').text('这个是居中文字');

###setLineheight(hex) 设置行高 string hex:16进制数字,如'\x05'

this.setLineheight('\x05');

###setStyle(type) 设置样式 string type:B/U/U2/BU/BU2分别代表加粗/下划线/下划线样式2/加粗+下划线/加粗+下划线样式2,不区分大小写

this.setStyle('b').text('加粗');

###setSize(size) 设置文字大小 number size:4/3/2/1/null,x代表x倍字体,1/null均为正常

this.setSize(2).text('大字体');

###qrcode(text,size,lsb,msb) 打印二维码
需要打印机支持QRCODE条码类型,否则会打印乱码,只支持英文字符和URL特殊符号(:/?=&.)
string text:二维码内容
string size:二维码大小,默认'\x06'
string lsb:(text长度+3)%256转16进制后的字符,如'\x01'
string msb:(text长度+3)/256取整转16进制后的字符,如'\x00'

this.qrcode(1,'\x0f','\x04','\x00');

注:compile中16进制参数请使用\转义,如<% qrcode:1,'\\x0f','\\x04','\\x00' %>

###beep(times,interval) 蜂鸣警报
string times:蜂鸣次数,16进制,1-9.默认'\x09'
string interval:蜂鸣间隔,16进制,实际间隔时间为interval*50ms,默认'\x01'

this.beep();

注:compile中16进制参数请使用\转义,如<% beep:'\\x03','\\x01' %>

###compile(string) 编译 string string:编译整个字符串
使用<% 方法名:[参数] %>进行快速设置\n\r表示换行.

this.compile('<% setAlign:c %><% setSize:2 %>这里开始是放大\n<% setSize:1 %>恢复正常大小');

###print(callback) 打印当前内容 function callback:回传err以及msg,当成功时,err为null

this.print(function(err,msg){
   if(err){
    console.log('打印出错,回传信息:');
   }
   console.log(msg);
});

###empty() 清空当前内容

this.empty();

###openCashbox() 发送钱箱脉冲 钱箱脉冲不能同打印命令一同发送(钱箱脉冲命令会执行但不会进行打印)

this.openCashbox();

###sendCmd(callback) 发送打印指令 function callback:回传err以及msg,当成功时,err为null

this.sendCmd(function(err,msg){
   if(err){
    console.log('打印出错,回传信息:');
   }
   console.log(msg);
});