print_client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/config_printer +6 -0
- data/bin/default_printer +6 -0
- data/bin/print_labels +6 -0
- data/bin/test_template +6 -0
- data/lib/print_client/version.rb +3 -0
- data/lib/print_client.rb +158 -0
- data/print_client.gemspec +20 -0
- data/virtusprinter.sample.yml +8 -0
- metadata +113 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 Leopoldo Ramírez
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# PrintClient
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'print_client'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install print_client
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
TODO: Write usage instructions here
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
1. Fork it
|
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/config_printer
ADDED
data/bin/default_printer
ADDED
data/bin/print_labels
ADDED
data/bin/test_template
ADDED
data/lib/print_client.rb
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
require "print_client/version"
|
|
2
|
+
require 'serialport'
|
|
3
|
+
require 'nokogiri'
|
|
4
|
+
require 'logger'
|
|
5
|
+
require 'benchmark'
|
|
6
|
+
require 'virtusprinter'
|
|
7
|
+
|
|
8
|
+
module PrintClient
|
|
9
|
+
ACK = 6
|
|
10
|
+
XOFF = 19
|
|
11
|
+
|
|
12
|
+
class DefaultPrinter
|
|
13
|
+
def initialize
|
|
14
|
+
config = YAML::load_file("./virtusprinter.yml")
|
|
15
|
+
@vp_port = config['virtusprinter']['port']
|
|
16
|
+
end
|
|
17
|
+
def default
|
|
18
|
+
port = SerialPort.new(@vp_port, 9600, 8, 1)
|
|
19
|
+
port.write "^default\n"
|
|
20
|
+
port.close
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class ConfigPrinter
|
|
25
|
+
def initialize
|
|
26
|
+
config = YAML::load_file("./virtusprinter.yml")
|
|
27
|
+
@vp_port = config['virtusprinter']['port']
|
|
28
|
+
end
|
|
29
|
+
def config
|
|
30
|
+
port = SerialPort.new(@vp_port, 9600, 8, 1)
|
|
31
|
+
port.write "xa\nI8,A,003\n"
|
|
32
|
+
port.close
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class PrintLabels
|
|
37
|
+
def initialize
|
|
38
|
+
config = YAML::load_file("./virtusprinter.yml")
|
|
39
|
+
@vp_computer = config['virtusprinter']['computer']
|
|
40
|
+
end
|
|
41
|
+
def start
|
|
42
|
+
virtus_printer = VirtusPrinter.new
|
|
43
|
+
log = Logger.new('log.txt', shift_age = 5, shift_size = 6048576)
|
|
44
|
+
log.level = Logger::DEBUG
|
|
45
|
+
log.debug 'Started logging'
|
|
46
|
+
while true
|
|
47
|
+
begin
|
|
48
|
+
sleep 1
|
|
49
|
+
result = false
|
|
50
|
+
data = {}
|
|
51
|
+
time = Benchmark.realtime do
|
|
52
|
+
result, data = virtus_printer.get_labels(@vp_computer)
|
|
53
|
+
end
|
|
54
|
+
log.debug "Time spent in virtusprinter: #{time}"
|
|
55
|
+
unless result
|
|
56
|
+
print " #{virtus_printer.error} "
|
|
57
|
+
next
|
|
58
|
+
end
|
|
59
|
+
print '.'
|
|
60
|
+
|
|
61
|
+
xml_doc = Nokogiri::XML(data)
|
|
62
|
+
labels = xml_doc.css("labels label")
|
|
63
|
+
next if labels.count == 0
|
|
64
|
+
|
|
65
|
+
# Open all required ports
|
|
66
|
+
ports = {}
|
|
67
|
+
labels.each do |l|
|
|
68
|
+
port = l.at_css('port').content
|
|
69
|
+
unless ports.include?(port)
|
|
70
|
+
ports[port] = SerialPort.new(port, 9600, 8, 1)
|
|
71
|
+
# Wait forever to receive printer response
|
|
72
|
+
ports[port].read_timeout = 0
|
|
73
|
+
# Enable error reporting
|
|
74
|
+
ports[port].write "US"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Print labels
|
|
79
|
+
labels.each do |l|
|
|
80
|
+
label_id = l.at_css('id').content
|
|
81
|
+
port = l.at_css('port').content
|
|
82
|
+
epl = l.at_css('epl').content
|
|
83
|
+
print 'p'
|
|
84
|
+
if epl.nil? || epl == ''
|
|
85
|
+
next
|
|
86
|
+
else
|
|
87
|
+
epl.encode!('ISO-8859-1')
|
|
88
|
+
ports[port].write(epl)
|
|
89
|
+
while true
|
|
90
|
+
byte = ports[port].getbyte
|
|
91
|
+
# The label was printed successfully
|
|
92
|
+
break if byte == ACK
|
|
93
|
+
# There was an error, read all error bytes
|
|
94
|
+
break if byte == XOFF
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Update labels
|
|
100
|
+
labels.each do |l|
|
|
101
|
+
label_id = l.at_css('id').content
|
|
102
|
+
print 'u'
|
|
103
|
+
result = virtus_printer.update_label label_id, 'PRINTED'
|
|
104
|
+
puts virtus_printer.error if result == false
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Close all ports
|
|
108
|
+
ports.each_value{ |port| port.close}
|
|
109
|
+
|
|
110
|
+
rescue Interrupt => e
|
|
111
|
+
log.error e
|
|
112
|
+
exit
|
|
113
|
+
rescue SystemCallError => e
|
|
114
|
+
log.error e
|
|
115
|
+
puts e
|
|
116
|
+
rescue SocketError => e
|
|
117
|
+
log.error e
|
|
118
|
+
print ' SocketError '
|
|
119
|
+
rescue Exception => e
|
|
120
|
+
log.error e
|
|
121
|
+
puts e.class
|
|
122
|
+
puts e
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
class TestTemplate
|
|
129
|
+
def initialize
|
|
130
|
+
config = YAML::load_file("./virtusprinter.yml")
|
|
131
|
+
@vp_template = config['virtusprinter']['template']
|
|
132
|
+
@vp_port = config['virtusprinter']['port']
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def start
|
|
136
|
+
template_name = @vp_template
|
|
137
|
+
port = @vp_port
|
|
138
|
+
|
|
139
|
+
puts "#{template_name} => #{port}"
|
|
140
|
+
|
|
141
|
+
virtus_printer = VirtusPrinter.new
|
|
142
|
+
result, data = virtus_printer.test_template(template_name, port)
|
|
143
|
+
|
|
144
|
+
xml_doc = Nokogiri::XML(data)
|
|
145
|
+
labels = xml_doc.css("labels label")
|
|
146
|
+
|
|
147
|
+
labels.each do |l|
|
|
148
|
+
port = l.at_css('port').content
|
|
149
|
+
epl = l.at_css('epl').content
|
|
150
|
+
epl.encode!('ISO-8859-1')
|
|
151
|
+
puts port
|
|
152
|
+
puts epl
|
|
153
|
+
sp = SerialPort.new(port, 9600, 8, 1)
|
|
154
|
+
sp.write epl
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path('../lib/print_client/version', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.authors = ['Hector Sansores', 'Leopoldo Ramírez del Prado']
|
|
6
|
+
gem.email = ['hector.sansores@virtus.com.mx', 'leopoldo.ramirez@virtus.com.mx']
|
|
7
|
+
gem.description = 'Downloads labels from virtusprinter server and sends them to a serial printer'
|
|
8
|
+
gem.summary = 'Print client for virtusprinter'
|
|
9
|
+
gem.homepage = 'http://rubygems.org/gems/printclient'
|
|
10
|
+
|
|
11
|
+
gem.files = `git ls-files`.split($\)
|
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
14
|
+
gem.name = "print_client"
|
|
15
|
+
gem.require_paths = ["lib"]
|
|
16
|
+
gem.version = PrintClient::VERSION
|
|
17
|
+
gem.add_runtime_dependency 'virtusprinter', ['0.2.0.beta1']
|
|
18
|
+
gem.add_runtime_dependency 'serialport', ['1.1.0']
|
|
19
|
+
gem.add_runtime_dependency 'nokogiri', ['1.5.5']
|
|
20
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: print_client
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Hector Sansores
|
|
9
|
+
- Leopoldo Ramírez del Prado
|
|
10
|
+
autorequire:
|
|
11
|
+
bindir: bin
|
|
12
|
+
cert_chain: []
|
|
13
|
+
date: 2012-10-10 00:00:00.000000000 Z
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: virtusprinter
|
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
|
+
none: false
|
|
19
|
+
requirements:
|
|
20
|
+
- - '='
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 0.2.0.beta1
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
none: false
|
|
27
|
+
requirements:
|
|
28
|
+
- - '='
|
|
29
|
+
- !ruby/object:Gem::Version
|
|
30
|
+
version: 0.2.0.beta1
|
|
31
|
+
- !ruby/object:Gem::Dependency
|
|
32
|
+
name: serialport
|
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
|
34
|
+
none: false
|
|
35
|
+
requirements:
|
|
36
|
+
- - '='
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: 1.1.0
|
|
39
|
+
type: :runtime
|
|
40
|
+
prerelease: false
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
43
|
+
requirements:
|
|
44
|
+
- - '='
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 1.1.0
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: nokogiri
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - '='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 1.5.5
|
|
55
|
+
type: :runtime
|
|
56
|
+
prerelease: false
|
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
58
|
+
none: false
|
|
59
|
+
requirements:
|
|
60
|
+
- - '='
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: 1.5.5
|
|
63
|
+
description: Downloads labels from virtusprinter server and sends them to a serial
|
|
64
|
+
printer
|
|
65
|
+
email:
|
|
66
|
+
- hector.sansores@virtus.com.mx
|
|
67
|
+
- leopoldo.ramirez@virtus.com.mx
|
|
68
|
+
executables:
|
|
69
|
+
- config_printer
|
|
70
|
+
- default_printer
|
|
71
|
+
- print_labels
|
|
72
|
+
- test_template
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- .gitignore
|
|
77
|
+
- Gemfile
|
|
78
|
+
- LICENSE
|
|
79
|
+
- README.md
|
|
80
|
+
- Rakefile
|
|
81
|
+
- bin/config_printer
|
|
82
|
+
- bin/default_printer
|
|
83
|
+
- bin/print_labels
|
|
84
|
+
- bin/test_template
|
|
85
|
+
- lib/print_client.rb
|
|
86
|
+
- lib/print_client/version.rb
|
|
87
|
+
- print_client.gemspec
|
|
88
|
+
- virtusprinter.sample.yml
|
|
89
|
+
homepage: http://rubygems.org/gems/printclient
|
|
90
|
+
licenses: []
|
|
91
|
+
post_install_message:
|
|
92
|
+
rdoc_options: []
|
|
93
|
+
require_paths:
|
|
94
|
+
- lib
|
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
|
+
none: false
|
|
97
|
+
requirements:
|
|
98
|
+
- - ! '>='
|
|
99
|
+
- !ruby/object:Gem::Version
|
|
100
|
+
version: '0'
|
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
|
+
none: false
|
|
103
|
+
requirements:
|
|
104
|
+
- - ! '>='
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
version: '0'
|
|
107
|
+
requirements: []
|
|
108
|
+
rubyforge_project:
|
|
109
|
+
rubygems_version: 1.8.24
|
|
110
|
+
signing_key:
|
|
111
|
+
specification_version: 3
|
|
112
|
+
summary: Print client for virtusprinter
|
|
113
|
+
test_files: []
|