libptouch の更新に追従
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# libptouch(Ruby gem)
|
||||
|
||||
[ptouch_label](../) の **libptouch** を [ffi](https://github.com/ffi/ffi) 経由で使うための Gem です。
|
||||
[ptouch_label](../) の **libptouch** を [ffi](https://github.com/ffi/ffi) 経由で使うための Gem です。C ライブラリと同様、**PT-P900W**(既定 USB PID)、**PT-P750W** / **PT-P710BT** などは `open_usb_vid_pid` または CLI の `-p` で選びます。
|
||||
|
||||
## 前提
|
||||
|
||||
@@ -35,11 +35,15 @@ export LIBPTOUCH_LIB=/usr/local/lib/libptouch.so
|
||||
|
||||
C の `ptouch-print` と同様の流れですが、**PNG 入力のみ**(`-w`/`-H` や 1bit ラスターは扱いません)。`gem install` 後は PATH に `ptouch-print-png` が入ります。
|
||||
|
||||
オプションは C 側に合わせ、**`-p` / `--pid`** で USB 製品 ID(16 進可)を指定できます。省略時は PT-P900W(`Libptouch::USB_PID_PTP900W` = `0x2085`)。例: PT-P750W `0x2062`、PT-P710BT `0x20af`(`libptouch.h` / `Libptouch` 定数と同じ)。
|
||||
|
||||
開発ツリーからそのまま試す例:
|
||||
|
||||
```bash
|
||||
bundle exec ruby -I lib exe/ptouch-print-png --help
|
||||
bundle exec ruby -I lib exe/ptouch-print-png -n -f ../samples/your.png
|
||||
bundle exec ruby -I lib exe/ptouch-print-png --status -p 0x2062
|
||||
bundle exec ruby -I lib exe/ptouch-print-png -f ../samples/your.png -p 0x20af
|
||||
```
|
||||
|
||||
## 使用例
|
||||
@@ -49,8 +53,11 @@ require "libptouch"
|
||||
|
||||
Libptouch::Context.new.tap do |ctx|
|
||||
ctx.open_usb
|
||||
# PT-P750W など別 PID のとき:
|
||||
# ctx.open_usb_vid_pid(Libptouch::USB_VID_BROTHER, Libptouch::USB_PID_PTP750W)
|
||||
p ctx.status_bytes.bytesize # => 32
|
||||
p ctx.status_hash[:tape_kind] # => {:code=>..., :label=>"ラミネートテープ"} など
|
||||
p ctx.status_hash[:model] # => {:code=>..., :name=>"PT-P750W"} など(対応機種のみ名前あり)
|
||||
p ctx.status_hash[:status_kind] # => 状態(ステータス種類)
|
||||
ensure
|
||||
ctx.dispose
|
||||
@@ -64,14 +71,16 @@ PNG からラスターへ:
|
||||
```ruby
|
||||
ctx = Libptouch::Context.new
|
||||
data, w, h = ctx.png_file_to_raster("/path/to/label.png")
|
||||
ctx.open_usb
|
||||
ctx.open_usb_vid_pid(Libptouch::USB_VID_BROTHER, Libptouch::USB_PID_PTP750W)
|
||||
ctx.print_raster(data, width_dots: w, height_dots: h, margin_mm: 0)
|
||||
ctx.dispose
|
||||
```
|
||||
|
||||
**解像度:** P750W / P710BT はラスター幅方向が **180 dpi**、P900W 系は **360 dpi**(C の `libptouch_print` / 各機種ラスター PDF に合わせて画像を用意してください)。
|
||||
|
||||
## API の範囲
|
||||
|
||||
- 実行ファイル `ptouch-print-png` … PNG のみ(`-f`, `-t`, `-n`, `-S`, `-V`, `-h`)。ステータスは JSON(`status_bytes` を `parse_status` したもの、`raw_bytes` 除く)
|
||||
- 実行ファイル `ptouch-print-png` … PNG のみ(`-f`, `-t`, `-p`, `-n`, `-S`, `-V`, `-h`)。ステータスは JSON(`status_bytes` を `parse_status` したもの、`raw_bytes` 除く)
|
||||
- `Libptouch::Context` … `open_usb` / `open_usb_vid_pid` / `close` / `dispose`
|
||||
- `check_raster` / `print_raster` / `png_file_to_raster` / `status_bytes` / `status_hash`
|
||||
- `Libptouch.parse_status(raw)` … 32 バイトを Hash に展開(機種・テープ幅・**テープ種類**・色・**状態(status_kind)**・エラービット・`raw_hex` など)
|
||||
|
||||
Reference in New Issue
Block a user