kuro-rs 0.0.1
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/.gemtest +0 -0
- data/History.txt +3 -0
- data/Manifest.txt +16 -0
- data/README.rdoc +60 -0
- data/Rakefile +25 -0
- data/bin/kuro-rs +28 -0
- data/examples/read.rb +22 -0
- data/examples/write.rb +23 -0
- data/lib/kuro-rs.rb +14 -0
- data/lib/kuro-rs/main.rb +107 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/kuro-rs_spec.rb +11 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/rspec.rake +21 -0
- metadata +116 -0
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.rdoc
|
4
|
+
Rakefile
|
5
|
+
lib/kuro-rs.rb
|
6
|
+
lib/kuro-rs/main.rb
|
7
|
+
script/console
|
8
|
+
script/destroy
|
9
|
+
script/generate
|
10
|
+
spec/kuro-rs_spec.rb
|
11
|
+
spec/spec.opts
|
12
|
+
spec/spec_helper.rb
|
13
|
+
tasks/rspec.rake
|
14
|
+
examples/read.rb
|
15
|
+
examples/write.rb
|
16
|
+
bin/kuro-rs
|
data/README.rdoc
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
= kuro-rs
|
2
|
+
|
3
|
+
* http://github.com/shokai/ruby-kuro-rs
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
control KURO-RS (http://www.kuroutoshikou.com/modules/display/?iid=928) and PC-OP-RS1 (http://buffalo.jp/products/catalog/item/p/pc-op-rs1/)
|
8
|
+
|
9
|
+
== SYNOPSIS:
|
10
|
+
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'kuro-rs'
|
14
|
+
|
15
|
+
# open KURO-RS
|
16
|
+
kr = KuroRs.open('/dev/tty.usbserial-0012a3b4')
|
17
|
+
|
18
|
+
# read
|
19
|
+
puts kr.read
|
20
|
+
## => hex dump (ffffffff0300f0e0018083...)
|
21
|
+
|
22
|
+
# write
|
23
|
+
kr.write 'ffffffff0300f0e0018083'
|
24
|
+
|
25
|
+
# close
|
26
|
+
kr.close
|
27
|
+
|
28
|
+
|
29
|
+
== REQUIREMENTS:
|
30
|
+
|
31
|
+
* KURO-RS or PC-OP-RS1
|
32
|
+
|
33
|
+
== INSTALL:
|
34
|
+
|
35
|
+
* gem install kuro-rs
|
36
|
+
|
37
|
+
== LICENSE:
|
38
|
+
|
39
|
+
(The MIT License)
|
40
|
+
|
41
|
+
Copyright (c) 2011 Sho Hashimoto
|
42
|
+
|
43
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
44
|
+
a copy of this software and associated documentation files (the
|
45
|
+
'Software'), to deal in the Software without restriction, including
|
46
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
47
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
48
|
+
permit persons to whom the Software is furnished to do so, subject to
|
49
|
+
the following conditions:
|
50
|
+
|
51
|
+
The above copyright notice and this permission notice shall be
|
52
|
+
included in all copies or substantial portions of the Software.
|
53
|
+
|
54
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
55
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
56
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
57
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
58
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
59
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
60
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/kuro-rs'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'kuro-rs' do
|
14
|
+
self.developer 'Sho Hashimoto', 'hashimoto@shokai.org'
|
15
|
+
self.rubyforge_name = self.name # TODO this is default value
|
16
|
+
self.extra_deps = [['serialport','>= 1.0.4']]
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'newgem/tasks'
|
21
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
22
|
+
|
23
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
24
|
+
# remove_task :default
|
25
|
+
# task :default => [:spec, :features]
|
data/bin/kuro-rs
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'kuro-rs'
|
4
|
+
|
5
|
+
if ARGV.size < 1
|
6
|
+
puts '!!Device Name and Hex String required'
|
7
|
+
puts 'read - kuro-rs /dev/tty.usbserial-0012a3b4'
|
8
|
+
puts 'write - kuro-rs /dev/tty.usbserial-0012a3b4 ffffffff0300f0e0018083...'
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
device_name = ARGV.shift
|
13
|
+
hex_str = ARGV.shift
|
14
|
+
|
15
|
+
begin
|
16
|
+
kr = KuroRs.open device_name
|
17
|
+
rescue KuroRs::Error, StandardError => e
|
18
|
+
STDERR.puts e
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
|
22
|
+
kr.verbose = true
|
23
|
+
if hex_str.to_s.size > 0
|
24
|
+
kr.write hex_str
|
25
|
+
else
|
26
|
+
puts kr.read
|
27
|
+
end
|
28
|
+
|
data/examples/read.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
#require 'kuro-rs'
|
4
|
+
require File.dirname(__FILE__)+'/../lib/kuro-rs'
|
5
|
+
|
6
|
+
if ARGV.size < 1
|
7
|
+
puts '!!Device Name required'
|
8
|
+
puts 'e.g. ruby read.rb /dev/tty.usbserial-0012a3b4'
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
device_name = ARGV.shift
|
13
|
+
|
14
|
+
begin
|
15
|
+
kr = KuroRs.open device_name
|
16
|
+
rescue KuroRs::Error, StandardError => e
|
17
|
+
STDERR.puts e
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
|
21
|
+
kr.verbose = true
|
22
|
+
puts kr.read ## => hex dump
|
data/examples/write.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
#require 'kuro-rs'
|
4
|
+
require File.dirname(__FILE__)+'/../lib/kuro-rs'
|
5
|
+
|
6
|
+
if ARGV.size < 2
|
7
|
+
puts '!!Device Name and Hex String required'
|
8
|
+
puts 'e.g. ruby write.rb /dev/tty.usbserial-0012a3b4 ffffffff0300f0e0018083...'
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
device_name = ARGV.shift
|
13
|
+
hex_str = ARGV.shift
|
14
|
+
|
15
|
+
begin
|
16
|
+
kr = KuroRs.open device_name
|
17
|
+
rescue KuroRs::Error, StandardError => e
|
18
|
+
STDERR.puts e
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
|
22
|
+
kr.verbose = true
|
23
|
+
kr.write hex_str
|
data/lib/kuro-rs.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
gem 'serialport','>=1.0.4'
|
5
|
+
require 'serialport'
|
6
|
+
require 'timeout'
|
7
|
+
|
8
|
+
Dir.glob(File.dirname(__FILE__)+'/kuro-rs/*.rb').each do |f|
|
9
|
+
require f
|
10
|
+
end
|
11
|
+
|
12
|
+
module KuroRs
|
13
|
+
VERSION = '0.0.1'
|
14
|
+
end
|
data/lib/kuro-rs/main.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
module KuroRs
|
2
|
+
def KuroRs.open(device_name)
|
3
|
+
KuroRs.new(device_name)
|
4
|
+
end
|
5
|
+
|
6
|
+
class Error < Exception
|
7
|
+
end
|
8
|
+
|
9
|
+
class KuroRs
|
10
|
+
attr_accessor :verbose
|
11
|
+
|
12
|
+
def busy?
|
13
|
+
@busy
|
14
|
+
end
|
15
|
+
|
16
|
+
def serialport
|
17
|
+
@sp
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(device_name)
|
21
|
+
@device_name = device_name
|
22
|
+
@verbose = false
|
23
|
+
@busy = false
|
24
|
+
if !File.exists? device_name.to_s
|
25
|
+
device_name = "nil" if device_name.to_s.size < 1
|
26
|
+
raise Error.new "device not found (#{device_name})"
|
27
|
+
end
|
28
|
+
@sp = SerialPort.new(device_name, 115200, 8, 1, 0)
|
29
|
+
end
|
30
|
+
|
31
|
+
def close
|
32
|
+
@sp.close
|
33
|
+
end
|
34
|
+
|
35
|
+
def read
|
36
|
+
@busy = true
|
37
|
+
begin
|
38
|
+
## request reading mode
|
39
|
+
@sp.write 'c'
|
40
|
+
@sp.write 'r'
|
41
|
+
puts 'read mode' if @verbose
|
42
|
+
raise Error.new 'response is not "Y"' unless @sp.getc.chr == 'Y'
|
43
|
+
timeout(30) do
|
44
|
+
while @sp.getc.chr != 'S' do end
|
45
|
+
end
|
46
|
+
|
47
|
+
## read data
|
48
|
+
puts 'reading data..' if @verbose
|
49
|
+
data = (0...240).to_a.map{|i| @sp.getc} # read 240 Bytes
|
50
|
+
raise Error.new 'response is not "E"' unless @sp.getc.chr == 'E'
|
51
|
+
rescue Error, StandardError => e
|
52
|
+
@busy = false
|
53
|
+
raise Error.new e
|
54
|
+
rescue Timeout::Error
|
55
|
+
@busy = false
|
56
|
+
raise Error.new 'no response'
|
57
|
+
end
|
58
|
+
|
59
|
+
## hex dump
|
60
|
+
hex_str = data.map{|i|
|
61
|
+
h = i.to_s(16)
|
62
|
+
h = "0#{h}" if h.size < 2
|
63
|
+
h
|
64
|
+
}.join('')
|
65
|
+
@busy = false
|
66
|
+
return hex_str
|
67
|
+
end
|
68
|
+
|
69
|
+
def write(hex_str)
|
70
|
+
@busy = true
|
71
|
+
## request writing mode
|
72
|
+
begin
|
73
|
+
@sp.write 'c'
|
74
|
+
@sp.write 't'
|
75
|
+
raise Error.new 'response is not "Y"' unless @sp.getc.chr == 'Y'
|
76
|
+
@sp.write '1'
|
77
|
+
raise Error.new 'response is not "Y"' unless @sp.getc.chr == 'Y'
|
78
|
+
rescue Error, StandardError => e
|
79
|
+
@busy = false
|
80
|
+
raise Error.new e
|
81
|
+
end
|
82
|
+
|
83
|
+
## write hex string
|
84
|
+
cmd_arr = []
|
85
|
+
arr = hex_str.split('')
|
86
|
+
loop do
|
87
|
+
s = arr.shift + arr.shift
|
88
|
+
cmd_arr << s.hex
|
89
|
+
break if arr.empty?
|
90
|
+
end
|
91
|
+
|
92
|
+
puts "command size:#{cmd_arr.size}(Bytes)" if @verbose
|
93
|
+
puts 'writing data...' if @verbose
|
94
|
+
begin
|
95
|
+
cmd_arr.each{|c|
|
96
|
+
@sp.putc c
|
97
|
+
}
|
98
|
+
raise Error.new 'response is not E' unless @sp.getc.chr == 'E'
|
99
|
+
rescue => e
|
100
|
+
@busy = false
|
101
|
+
raise Error.new e
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/kuro-rs.rb'}"
|
9
|
+
puts "Loading kuro-rs gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kuro-rs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Sho Hashimoto
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-31 00:00:00 +09:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: serialport
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 31
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
- 4
|
34
|
+
version: 1.0.4
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: hoe
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 27
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 12
|
49
|
+
version: "2.12"
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
description: control KURO-RS (http://www.kuroutoshikou.com/modules/display/?iid=928) and PC-OP-RS1 (http://buffalo.jp/products/catalog/item/p/pc-op-rs1/)
|
53
|
+
email:
|
54
|
+
- hashimoto@shokai.org
|
55
|
+
executables:
|
56
|
+
- kuro-rs
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files:
|
60
|
+
- History.txt
|
61
|
+
- Manifest.txt
|
62
|
+
files:
|
63
|
+
- History.txt
|
64
|
+
- Manifest.txt
|
65
|
+
- README.rdoc
|
66
|
+
- Rakefile
|
67
|
+
- lib/kuro-rs.rb
|
68
|
+
- lib/kuro-rs/main.rb
|
69
|
+
- script/console
|
70
|
+
- script/destroy
|
71
|
+
- script/generate
|
72
|
+
- spec/kuro-rs_spec.rb
|
73
|
+
- spec/spec.opts
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
- tasks/rspec.rake
|
76
|
+
- examples/read.rb
|
77
|
+
- examples/write.rb
|
78
|
+
- bin/kuro-rs
|
79
|
+
- .gemtest
|
80
|
+
has_rdoc: true
|
81
|
+
homepage: http://github.com/shokai/ruby-kuro-rs
|
82
|
+
licenses: []
|
83
|
+
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options:
|
86
|
+
- --main
|
87
|
+
- README.rdoc
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
requirements: []
|
109
|
+
|
110
|
+
rubyforge_project: kuro-rs
|
111
|
+
rubygems_version: 1.6.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: control KURO-RS (http://www.kuroutoshikou.com/modules/display/?iid=928) and PC-OP-RS1 (http://buffalo.jp/products/catalog/item/p/pc-op-rs1/)
|
115
|
+
test_files: []
|
116
|
+
|