Skip to content

Commit fcfcb75

Browse files
authored
Merge pull request #59 from uyu423/feature/fix-readme
README.md supplement and fix wrong typo
2 parents 8d1fb1e + cd1a435 commit fcfcb75

File tree

1 file changed

+82
-17
lines changed

1 file changed

+82
-17
lines changed

README.md

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ ESC/POS Printer driver for node
66

77
## Installation
88

9-
````
9+
### npm
10+
```bash
1011
$ npm i escpos --save
11-
````
12+
```
13+
14+
### yarn
15+
```bash
16+
$ yarn add escpos
17+
```
1218

1319
if you use usb as an adapter :
1420

@@ -31,50 +37,102 @@ const device = new escpos.USB();
3137
const printer = new escpos.Printer(device);
3238

3339
device.open(function(){
34-
3540
printer
3641
.font('a')
3742
.align('ct')
3843
.style('bu')
3944
.size(1, 1)
4045
.text('The quick brown fox jumps over the lazy dog')
4146
.text('敏捷的棕色狐狸跳过懒狗')
42-
.barcode('12345678', 'EAN8')
47+
.barcode('1234567', 'EAN8')
4348
.qrimage('https://github.com/song940/node-escpos', function(err){
4449
this.cut();
4550
this.close();
4651
});
47-
4852
});
4953
````
54+
- See `./examples` for more examples.
5055

5156
----
57+
## Adapter
58+
59+
### Constructors
60+
61+
You can choose your adapter type as USB, Serial, Network, or Console.
62+
63+
#### USB(vid, pid)
64+
```javascript
65+
const usbDevice = new escpos.USB(0x01, 0xff);
66+
```
67+
vid(Vendor Id) and pid (Product Id) can be checked with the `lsusb` command or `escpos.USB.findPrinter()` method.
68+
69+
#### Serial("port", options)
70+
```javascript
71+
const serialDeviceOnWindows = new escpos.Serial('COM10');
72+
const serialDeviceOnLinux = new escpos.Serial('/dev/usb/lp0', {
73+
bandRate: 14400,
74+
stopBit: 2
75+
});
76+
```
77+
Check the [serialport package documentation](https://github.com/EmergingTechnologyAdvisors/node-serialport#serialportopenoptions--object) for more options.
78+
79+
80+
#### Network(address, port = 9100)
81+
```javascript
82+
const networkDevice = new escpos.Network('localhost', 3000);
83+
```
84+
The default port number is 9100.
5285

86+
#### Console(handler = stdout)
87+
```javascript
88+
const debugDevice = new escpos.Console();
89+
```
5390

54-
## USB Adapter methods
91+
### Methods
5592

56-
### open(function calback)
93+
#### open(function callback)
5794

58-
Claims the current device USB, if the printer is already in use by other process this will fail.
95+
Claims the current device USB (or other device type), if the printer is already in use by other process this will fail.
5996

6097
By default, the USB adapter will set the first printer found .
6198

6299
Triggers the callback function when done.
63100

64-
### close(function callback)
101+
#### close(function callback)
65102

66103
Closes the current device and releases its USB interface.
67104

68105
----
69106

70-
## Printer methods
107+
## Printer
108+
109+
### Constructors
110+
111+
#### Printer(device)
112+
113+
```javascript
114+
const usbDevice = new escpos.USB();
115+
const usbPrinter = new escpos.Printer(usbDevice);
116+
117+
const serialDevice = new escpos.Serial('/dev/usb/lp0');
118+
const serialPrinter = new escpos.Printer(serialDevice);
119+
120+
const networkDevice = new escpos.Network('localhost');
121+
const networkPrinter = new escpos.Printer(networkDevice);
122+
```
123+
124+
### Methods
71125

72126
Escpos inherits its methods to the printers. the following methods are defined:
73127

74-
### text("text")
128+
### text("text", encodeType)
75129

76130
Prints raw text. Raises TextError exception.
77131

132+
For the encode type, see the [iconv-lite wiki document](https://github.com/ashtuchkin/iconv-lite/wiki/Supported-Encodings). Escpos uses `iconv-lite` for encoding.
133+
134+
If the type is undefined, the default type is GB18030.
135+
78136
### control("align")
79137

80138
Carrier feed and tabs.
@@ -94,17 +152,22 @@ Set text properties.
94152

95153
align set horizontal position for text, the possible values are:
96154

97-
+ CENTER
98-
+ LEFT
99-
+ RIGHT
155+
+ CT is the Center alignment
156+
+ LT is the Left alignment
157+
+ RT is the Right alignment
100158

101-
Default: left
159+
Default: LT
102160

161+
### font("type")
103162
font type could be A or B. Default: A
163+
164+
### size(width, heigth)
165+
104166
width is a numeric value, 1 is for regular size, and 2 is twice the standard size. Default: 1
167+
105168
height is a numeric value, 1 is for regular size and 2 is twice the standard size. Default: 1
106169

107-
### barcode("code", "barcode_type", width, height, "position", "font")
170+
### barcode("code", "barcodeType", width, height, "position", "font")
108171

109172
Prints a barcode.
110173

@@ -119,6 +182,8 @@ barcode_type must be one of the following type of codes:
119182
+ ITF
120183
+ NW7
121184

185+
The EAN type automatically calculates the last parity bit. For the EAN13 type, the length of the string is limited to 12, and EAN8 is limited to 7. (#57)
186+
122187
width is a numeric value in the range between (1,255) Default: 64
123188
height is a numeric value in the range between (2,6) Default: 3
124189
position is where to place the code around the bars, could be one of the following values:
@@ -159,7 +224,7 @@ Raises `CashDrawerError()``
159224

160225
## Screencast
161226

162-
![IMG_1031.JPG](./screencasts/IMG_1031.JPG)
227+
![img_1031](https://user-images.githubusercontent.com/8033320/29250339-d66ce470-807b-11e7-89ce-9962da88ca18.JPG)
163228

164229
----
165230

0 commit comments

Comments
 (0)