-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.rb
42 lines (34 loc) · 919 Bytes
/
demo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'escpos'
require 'escpos/Helpers'
require 'serialport' # use Kernel::require on windows, works better.
require 'escpos/image'
while true do
@printer = Escpos::Printer.new
#@printer.Helpers.encode(1)
#@printer.write Escpos::Helpers.encode("日本語能力試験-JLPT/N3")
@printer.write gets
#@printer.write "\n"
#@printer.cut!
data = @printer.to_escpos
# require 'rubyserial'
# serialport = Serial.new 'COM3', 115200, 8, :none, 1
# serialport.write(data)
# serialport.close
#params for serial port
# port_str = "COM4" #may be different for you
# baud_rate = 115200
# data_bits = 8
# stop_bits = 1
# parity = SerialPort::NONE
#
# sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
# sp.sync = true
# sp.write(data)
open('testfile', 'w') { |f|
f.puts data
}
open('history.txt', 'w+') { |f|
f.puts data
}
system('print /D:"\\\DESKTOP-T84DD2P\Thermal Printer (USB)" testfile')
end