rs232-sigmakoki 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/README +39 -0
- data/lib/rs232-sigmakoki.rb +63 -0
- data/rakefile.rb +10 -0
- data/test/test_rs232-sigmakoki.rb +27 -0
- metadata +60 -0
data/README
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
##
|
2
|
+
#
|
3
|
+
# RS232-SigmaKoki
|
4
|
+
#
|
5
|
+
# Ruby interface to Windows Serial Port API
|
6
|
+
#
|
7
|
+
# author hugo benichi
|
8
|
+
# email hugo.benichi@m4x.org
|
9
|
+
# copyright 2012 hugo benichi
|
10
|
+
# version 0.1.0
|
11
|
+
#
|
12
|
+
##
|
13
|
+
|
14
|
+
installation:
|
15
|
+
|
16
|
+
run in the root directory
|
17
|
+
rake gem_install
|
18
|
+
|
19
|
+
it will compile the gem library and produce a .gem package for ruby
|
20
|
+
it will then install the .gem automatically
|
21
|
+
|
22
|
+
usage:
|
23
|
+
|
24
|
+
cf test/test_rs232-sigmakoki.rb
|
25
|
+
|
26
|
+
the list of commands is
|
27
|
+
|
28
|
+
home # brings back both state to mechanical origin
|
29
|
+
stop # stop with deceleration
|
30
|
+
stop! # emergency stop
|
31
|
+
status # current state status
|
32
|
+
rom # internal rom version
|
33
|
+
ready?
|
34
|
+
busy? # is the stage ready to accept the next command
|
35
|
+
jog '++'|'++'|'+-' # slowly moves both stages in + or - direction
|
36
|
+
move a, b # move stage 1 of a steps, and stage 2 of b steps (b optional)
|
37
|
+
move! a, b # same as move, but wait until the stages are ready
|
38
|
+
position # return the position of both stages
|
39
|
+
position_of i # return the position of stage i (1,2)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class SigmaKoki
|
2
|
+
|
3
|
+
require 'rs232'
|
4
|
+
|
5
|
+
[
|
6
|
+
[:home, 'H:W--'],
|
7
|
+
[:stop, 'L:W'],
|
8
|
+
[:stop!, 'L:E'],
|
9
|
+
[:go, 'G'],
|
10
|
+
].each{ |meth,c| define_method(meth){ @comm.write c} }
|
11
|
+
|
12
|
+
[
|
13
|
+
[:status, 'Q:'],
|
14
|
+
[:rom, '?:V'],
|
15
|
+
[:busy, '!:'],
|
16
|
+
].each{ |meth,c| define_method(meth){ @comm.query c} }
|
17
|
+
|
18
|
+
|
19
|
+
def ready?
|
20
|
+
'R' == self.busy[0] #gsub(' ','').split(',')[-1]
|
21
|
+
end
|
22
|
+
|
23
|
+
def busy?
|
24
|
+
'B' == self.busy[0] #gsub(' ','').split(',')[-1]
|
25
|
+
end
|
26
|
+
|
27
|
+
def wait
|
28
|
+
sleep 0.2 while busy?
|
29
|
+
end
|
30
|
+
|
31
|
+
def jog *args
|
32
|
+
@comm.write "J:W%s%s" % args[0..1]
|
33
|
+
go
|
34
|
+
end
|
35
|
+
|
36
|
+
#main command to rotate the plates
|
37
|
+
def move step1, step2 = 0
|
38
|
+
s1, s2 = step1 > 0 ? "+" : "-", step2 > 0 ? "+" : "-"
|
39
|
+
command = "M:W%sP%i%sP%i" % [s1,step1.abs,s2,step2.abs]
|
40
|
+
@comm.write command
|
41
|
+
go
|
42
|
+
end
|
43
|
+
|
44
|
+
def move! step1, step2 = 0
|
45
|
+
move step1, step2
|
46
|
+
wait
|
47
|
+
end
|
48
|
+
|
49
|
+
def position
|
50
|
+
self.status.gsub(' ','').split(',').map{|x| x.to_i}[0..1]
|
51
|
+
end
|
52
|
+
|
53
|
+
def position_of chan
|
54
|
+
self.status.gsub(' ','').split(',')[chan-1].to_i
|
55
|
+
end
|
56
|
+
|
57
|
+
def initialize address, params = {}
|
58
|
+
@comm = RS232.new address, params
|
59
|
+
end
|
60
|
+
|
61
|
+
attr_reader :comm
|
62
|
+
|
63
|
+
end
|
data/rakefile.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
task :test_global do ruby "test/test_rs232-sigmakoki.rb" end
|
2
|
+
task :test_local do ruby "-Ilib test/test_rs232-sigmakoki.rb" end
|
3
|
+
|
4
|
+
task :gem_build do sh "gem build rs232-sigmakoki.gemspec" end
|
5
|
+
task :gem_install => :gem_build do
|
6
|
+
gemfile = Dir.new("./").entries.select{ |f| f =~ /rs232-sigmakoki-[\d]+\.[\d]+\.[\d]+.gem/ }.sort[-1]
|
7
|
+
sh "gem install --local %s" % gemfile
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :test_local
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rs232-sigmakoki'
|
2
|
+
|
3
|
+
plate = SigmaKoki.new 'COM1'
|
4
|
+
|
5
|
+
plate.home
|
6
|
+
|
7
|
+
puts plate.status
|
8
|
+
|
9
|
+
20.times do
|
10
|
+
puts plate.position
|
11
|
+
puts plate.busy?
|
12
|
+
sleep 0.2
|
13
|
+
end
|
14
|
+
|
15
|
+
plate.move 10000
|
16
|
+
|
17
|
+
while plate.busy?
|
18
|
+
print '..'
|
19
|
+
sleep 0.2
|
20
|
+
end
|
21
|
+
puts ""
|
22
|
+
|
23
|
+
plate.move! 20000
|
24
|
+
plate.home
|
25
|
+
|
26
|
+
|
27
|
+
puts "ok"
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rs232-sigmakoki
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Hugo Benichi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rs232
|
16
|
+
requirement: &21722160 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *21722160
|
25
|
+
description: Allows to script usage of the SigmaKoki step motor controllers with simple
|
26
|
+
commands and without serial port troubles
|
27
|
+
email: hugo.benichi@m4x.org
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- lib/rs232-sigmakoki.rb
|
33
|
+
- test/test_rs232-sigmakoki.rb
|
34
|
+
- rakefile.rb
|
35
|
+
- README
|
36
|
+
homepage: http://github.com/hugobenichi/rs232-sigmakoki
|
37
|
+
licenses: []
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.8.16
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: Ruby interface to SigmaKoki step motor controllers over the serial interface
|
60
|
+
test_files: []
|