thecore_print_commons 2.1.2 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/api/printer.rb +32 -0
- data/app/models/printer.rb +2 -9
- data/app/workers/print_worker.rb +5 -65
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3d14d2d7122107560e3483a45aaab2f69efb513fae2f2c4368f996e79b61067
|
4
|
+
data.tar.gz: 69c327df788227be6659c6a6dd7ddcfda0af077bc18b82fb177b20ae3046a8f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9841914519bfb9b77f1dd53c2f4ffcc344e411f083830a5104101be69b5ee4821636203d0c9a77cd09a7d39209b43a43098b4965236fa1f823ee6a365501c6f1
|
7
|
+
data.tar.gz: 826d5bd6e22ef43312e244b63ce864b6223b836f0f3ae4612516d555943b6760385b6839735f8445f96f90694bd5390c5980dbf8a42b0be87847b787aa7fc809
|
@@ -41,5 +41,37 @@ module Api::Printer
|
|
41
41
|
::PrintWorker.perform_async(printer.ip, printer.port, text)
|
42
42
|
{ info: "Print job sent in background to #{printer.ip} on port #{printer.port}" }
|
43
43
|
end
|
44
|
+
|
45
|
+
def self.custom_action_printer_status params
|
46
|
+
printer = Printer.find(params[:id])
|
47
|
+
ip = printer.ip
|
48
|
+
port = printer.port
|
49
|
+
begin
|
50
|
+
s = Socket.tcp ip, port, connect_timeout: 0.5
|
51
|
+
# Must create intepolation between item and template
|
52
|
+
# Printer.template può essere anche
|
53
|
+
# una parola di comando epr chiedere lo stato della stampante, solo nel caso sia ok,
|
54
|
+
# Allora mando la stampa
|
55
|
+
s.puts("~hs")
|
56
|
+
# Attende per la risposta (si mette in wait)
|
57
|
+
response = []
|
58
|
+
while (response_text = s.gets)
|
59
|
+
response << response_text
|
60
|
+
break if response.count == 3
|
61
|
+
end
|
62
|
+
s.close
|
63
|
+
# Rails.logger.info "PrintIt: RESPONSE: #{response.inspect}"
|
64
|
+
first = response[0].split(",")
|
65
|
+
second = response[1].split(",")
|
66
|
+
return "HEAD UP" if second[2].to_i == 1
|
67
|
+
return "RIBBON OUT" if second[3].to_i == 1
|
68
|
+
return "PAPER OUT" if first[1].to_i == 1
|
69
|
+
return "PAUSE" if first[2].to_i == 1
|
70
|
+
return "OK"
|
71
|
+
rescue
|
72
|
+
Rails.logger.info "PrintIt: STATUS: UNREACHABLE"
|
73
|
+
return "UNREACHABLE"
|
74
|
+
end
|
75
|
+
end
|
44
76
|
end
|
45
77
|
end
|
data/app/models/printer.rb
CHANGED
@@ -55,18 +55,11 @@ class Printer < ApplicationRecord
|
|
55
55
|
|
56
56
|
def online?
|
57
57
|
begin
|
58
|
-
Socket.tcp(self.ip,
|
58
|
+
Socket.tcp(self.ip, self.port, connect_timeout: 0.5).close
|
59
59
|
rescue
|
60
60
|
return false
|
61
61
|
end
|
62
62
|
true
|
63
63
|
end
|
64
|
-
|
65
|
-
|
66
|
-
# private
|
67
|
-
# def check_if_unique_default
|
68
|
-
# if self.default?
|
69
|
-
# Printer.where.not(id: self.id)
|
70
|
-
# end
|
71
|
-
# end
|
64
|
+
|
72
65
|
end
|
data/app/workers/print_worker.rb
CHANGED
@@ -7,73 +7,13 @@ class PrintWorker
|
|
7
7
|
# ZPL print
|
8
8
|
def perform ip, port, text
|
9
9
|
@pjob = PrintJob.create(printer_id: Printer.find_by(ip: ip), finished: false, iserror: false, total: 0, printed: 0)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
begin
|
14
|
-
streamSock = TCPSocket.new ip, port
|
15
|
-
streamSock.send text, 0
|
16
|
-
streamSock.close
|
17
|
-
print_job_status = true
|
18
|
-
rescue
|
19
|
-
@pjob.update(iserror: true, description: "PRINTER ERROR: TIMEOUT")
|
20
|
-
print_job_status = false
|
21
|
-
end
|
22
|
-
else
|
23
|
-
@pjob.update(iserror: true, description: "PRINTER ERROR: #{status}")
|
24
|
-
print_job_status = false
|
25
|
-
end
|
10
|
+
streamSock = Socket.tcp ip, port, connect_timeout: 0.5
|
11
|
+
streamSock.send text, 0
|
12
|
+
streamSock.close
|
26
13
|
# '~hs alla posizione 56 per 8 caratteri la quantità di etichette rimaste'
|
27
14
|
total = text.scan(/~PQ(\d+)/).last.first.to_i rescue 0
|
28
|
-
@pjob.update(printed:
|
15
|
+
@pjob.update(printed: total) # Se risultato true, allora ha stampato tutto, altrimenti non ha stampato nulla
|
29
16
|
@pjob.update(total: total) # In realtà è inutile, ora manda tutto quello che può alla stampante, solo lei può andare storta
|
30
|
-
@pjob.update(finished:
|
17
|
+
@pjob.update(finished: true)
|
31
18
|
end
|
32
|
-
|
33
|
-
def check_status printer
|
34
|
-
begin
|
35
|
-
s = TCPSocket.new(printer, 9100)
|
36
|
-
# Must create intepolation between item and template
|
37
|
-
# Printer.template può essere anche
|
38
|
-
# una parola di comando epr chiedere lo stato della stampante, solo nel caso sia ok,
|
39
|
-
# Allora mando la stampa
|
40
|
-
s.puts("~hs")
|
41
|
-
# Attende per la risposta (si mette in wait)
|
42
|
-
response = []
|
43
|
-
while (response_text = s.gets)
|
44
|
-
response << response_text
|
45
|
-
break if response.count == 3
|
46
|
-
end
|
47
|
-
s.close
|
48
|
-
Rails.logger.info "PrintIt: RESPONSE: #{response.inspect}"
|
49
|
-
first = response[0].split(",")
|
50
|
-
second = response[1].split(",")
|
51
|
-
return "HEAD UP" if second[2].to_i == 1
|
52
|
-
return "RIBBON OUT" if second[3].to_i == 1
|
53
|
-
return "PAPER OUT" if first[1].to_i == 1
|
54
|
-
return "PAUSE" if first[2].to_i == 1
|
55
|
-
return "OK"
|
56
|
-
rescue
|
57
|
-
Rails.logger.info "PrintIt: STATUS: UNREACHABLE"
|
58
|
-
return "UNREACHABLE"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# This is for cups only
|
63
|
-
# def perform printer_cups_name, text
|
64
|
-
# # if Settings.ns(:printer_commons).cups_server.blank? || ['127.0.0.1', 'localhost'].contains(Settings.ns(:printer_commons).cups_server)
|
65
|
-
# # printer = CupsPrinter.new printer_cups_name
|
66
|
-
# # printer.print_data text, 'text/plain'
|
67
|
-
# # printer.close
|
68
|
-
# # else
|
69
|
-
# print_file = "/tmp/print-#{printer_cups_name}-#{Time.now.strftime '%Y%m%d%H%M%S%L'}"
|
70
|
-
# puts "Creating temp file: #{print_file}"
|
71
|
-
# IO.write(print_file, text)
|
72
|
-
# # CupsPrinter.new printer_cups_name, hostname: Settings.ns(:printer_commons).cups_server
|
73
|
-
# # printer.print_data text, 'text/plain', hostname: Settings.ns(:printer_commons).cups_server
|
74
|
-
# puts "Printing with lp command on #{printer_cups_name} of #{Settings.ns(:printer_commons).cups_server} "
|
75
|
-
# `cupsenable "#{printer_cups_name}";lp -d "#{printer_cups_name}" -h "#{Settings.ns(:printer_commons).cups_server}" -o raw "#{print_file}"`
|
76
|
-
# File.delete print_file
|
77
|
-
# # end
|
78
|
-
# end
|
79
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thecore_print_commons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriele Tassoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thecore_background_jobs
|