star_ethernet 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.
@@ -0,0 +1,46 @@
1
+ require 'socket'
2
+
3
+ require 'star_ethernet/status'
4
+
5
+ module StarEthernet
6
+ class Printer
7
+ RAW_SOCKET_PRINT_PORT = 9100
8
+ STATUS_ACQUISITION_PORT = 9101
9
+
10
+ attr_reader :status
11
+
12
+ def initialize(host)
13
+ @host = host
14
+ @status = StarEthernet::Status.new
15
+ end
16
+
17
+ def print(data)
18
+ socket = socket(RAW_SOCKET_PRINT_PORT)
19
+ nbs_status = socket.read(11)
20
+ @status.set_status(nbs_status)
21
+ socket.print(data)
22
+ socket.close_write
23
+ socket.close
24
+ end
25
+
26
+ def current_status
27
+ @status.current_status
28
+ end
29
+
30
+ def fetch_status
31
+ socket = socket(STATUS_ACQUISITION_PORT)
32
+ cmd = [0x32] + 50.times.map { 0x00 }
33
+ socket.print(cmd.pack('C*'))
34
+ asb_status = socket.read(11)
35
+ @status.set_status(asb_status)
36
+ socket.close
37
+ @status.current_status
38
+ end
39
+
40
+ private
41
+
42
+ def socket(port)
43
+ TCPSocket.new(@host, port)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ require 'star_ethernet/status_item'
2
+
3
+ module StarEthernet
4
+ class StarEthernet::Status
5
+ def initialize
6
+ @statuses = []
7
+ end
8
+
9
+ def current_status
10
+ @statuses.first
11
+ end
12
+
13
+ def set_status(status_data)
14
+ current_status = StatusItem.decode_status(status_data)
15
+ @statuses.push(current_status)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ module StarEthernet
2
+ module StatusItem
3
+ class BasicStatus
4
+ # todo
5
+ end
6
+
7
+ class ErrorStatus
8
+ # todo
9
+ end
10
+
11
+ class SensorStatus
12
+ # todo
13
+ end
14
+
15
+ class EtbCounterStatus
16
+ # todo
17
+ end
18
+
19
+ class PresentorStatus
20
+ # todo
21
+ end
22
+
23
+ class NormalStatus < BasicStatus; end
24
+
25
+ def self.decode_status(status_raw_data)
26
+ status_data = status_raw_data.unpack('h*').first
27
+ if status_data == '3268000000000000000000'
28
+ StarEthernet::StatusItem::NormalStatus
29
+ else
30
+ StarEthernet::StatusItem::ErrorStatus
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module StarEthernet
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'star_ethernet/command'
2
+ require 'star_ethernet/printer'
3
+ require 'star_ethernet/status'
4
+ require 'star_ethernet/status_item'
5
+ require 'star_ethernet/version'
6
+
7
+ module StarEthernet
8
+ end
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "star_ethernet/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "star_ethernet"
8
+ spec.version = StarEthernet::VERSION
9
+ spec.authors = ["Shinsuke IMAI"]
10
+ spec.email = ["imaishinsuke@gmail.com"]
11
+
12
+ spec.summary = "Star Micronics thermal printer controller via ethernet card(IFBD-HE07/08-BE07)"
13
+ spec.description = "This library makes it possible to print via IDBD-HE07/08-BE07 ethernet I/F Card by ruby command. According to user manual's Raw Socket Print document, this library is developed. Currently this supports only Raw Socket Print(TCP Port 9100), Gets Printer Status(TCP Port 9101) and Reset with authentication, gets settings information(TCP Port 22222)."
14
+ spec.homepage = "https://github.com/shinsukeimai/star_ethernet"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 2.0"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: star_ethernet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shinsuke IMAI
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: This library makes it possible to print via IDBD-HE07/08-BE07 ethernet
56
+ I/F Card by ruby command. According to user manual's Raw Socket Print document,
57
+ this library is developed. Currently this supports only Raw Socket Print(TCP Port
58
+ 9100), Gets Printer Status(TCP Port 9101) and Reset with authentication, gets settings
59
+ information(TCP Port 22222).
60
+ email:
61
+ - imaishinsuke@gmail.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - ".gitignore"
67
+ - ".rspec"
68
+ - ".travis.yml"
69
+ - CODE_OF_CONDUCT.md
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - bin/console
76
+ - bin/setup
77
+ - lib/star_ethernet.rb
78
+ - lib/star_ethernet/command.rb
79
+ - lib/star_ethernet/printer.rb
80
+ - lib/star_ethernet/status.rb
81
+ - lib/star_ethernet/status_item.rb
82
+ - lib/star_ethernet/version.rb
83
+ - star_ethernet.gemspec
84
+ homepage: https://github.com/shinsukeimai/star_ethernet
85
+ licenses:
86
+ - MIT
87
+ metadata:
88
+ homepage_uri: https://github.com/shinsukeimai/star_ethernet
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.6.11
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Star Micronics thermal printer controller via ethernet card(IFBD-HE07/08-BE07)
109
+ test_files: []