escalator 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7090d0538de1f61b6ea04dbf1506275138c16bd
4
- data.tar.gz: 354bedc84a43edfeb2a560bcd55dce137d13e643
3
+ metadata.gz: 96df485214287d8eb979038fb09affe48df28e64
4
+ data.tar.gz: e4373e1835a8b56cad7fed3d576fa2174e1b3537
5
5
  SHA512:
6
- metadata.gz: 3ab6fd9adbc1c2cd896ad6497f743783ae9dc47776192b0cf7364870da113fc4ea7900d240d328a02654f9fcace9f4f6f4b039d928d6fee5d08297d71d8102e8
7
- data.tar.gz: 0fffaf803b79336a8f6bde8be7715b6ecec60253bb87feb18042654b17ac2b5c6b0f80ea667ffb3b6f5d7d057f542c7e9367c372e828ed30f24aedb456ed30eb
6
+ metadata.gz: 8aa906b7ecf76177535701a6a2d98a140f23e83d8758a38442f393e3cd8b1d0777cf3c2818aed377eb852ba3ae9d6a493c467147cbf7c728c817ef5a541a3533
7
+ data.tar.gz: 6af629c1378af4bfde276e48640e9a28b6add1661a399c57a527ba96d5c6d7f266f28fe25a82a22898a84fdaaa8521de6d82c5e509083d7b4e8c1420e0bfbb78
data/README.md CHANGED
@@ -47,8 +47,6 @@ Created files are consisted like the tree below.
47
47
  └── r08.gx3
48
48
  ```
49
49
 
50
- [![](http://img.youtube.com/vi/aFEtOIgKLvQ/0.jpg)](https://youtu.be/aFEtOIgKLvQ)
51
-
52
50
  # Connection configuration
53
51
 
54
52
  ## PLC configuration
@@ -92,6 +90,7 @@ Refer [Wiki](https://github.com/ito-soft-design/escalator/wiki/mnemonic) to chec
92
90
 
93
91
  ```
94
92
  # main.esc
93
+ # |M0|-|M1|----(M2)
95
94
  LD M0
96
95
  AND M1
97
96
  OUT M2
@@ -158,8 +157,27 @@ Below example writes values to devices from M0 to M7.
158
157
  > w m0 0 0 0 1 1 0 1 1
159
158
  ```
160
159
 
160
+ If you want to turn on and off the device like pushing a button, use p command.
161
+
162
+ ```sh
163
+ > p m0
164
+ ```
165
+
166
+ You can describe turn on time duration after a device. The unit is sec.
167
+
168
+ ```sh
169
+ > p m0 1.5
170
+ ```
171
+
172
+ ```
173
+ # |M0|---(M1)
174
+ LD M0
175
+ OUT M1
176
+ ```
177
+
178
+ [![https://gyazo.com/565d24a35887503281a46775f6ccd747](https://i.gyazo.com/565d24a35887503281a46775f6ccd747.gif)](https://gyazo.com/565d24a35887503281a46775f6ccd747)
161
179
 
162
- [![](http://img.youtube.com/vi/qGbicGLB7Gs/0.jpg)](https://youtu.be/qGbicGLB7Gs)
180
+ <!-- [![](http://img.youtube.com/vi/qGbicGLB7Gs/0.jpg)](https://youtu.be/qGbicGLB7Gs) -->
163
181
 
164
182
 
165
183
  # Information related escalator
data/README_jp.md CHANGED
@@ -94,6 +94,7 @@ PLC側の実装がまだ進んでいないので実行できるニーモニッ
94
94
 
95
95
  ```
96
96
  # main.esc
97
+ # |M0|-|M1|----(M2)
97
98
  LD M0
98
99
  AND M1
99
100
  OUT M2
@@ -160,7 +161,7 @@ done uploading
160
161
  > w m0 0 0 0 1 1 0 1 1
161
162
  ```
162
163
 
163
- ボタンを押した様にパルス状にデバイスをオンにするにはpwコマンドを使用します。
164
+ ボタンを押した様にパルス状にデバイスをオンにするにはpコマンドを使用します。
164
165
 
165
166
  ```sh
166
167
  > p m0
@@ -172,9 +173,15 @@ done uploading
172
173
  > p m0 1.5
173
174
  ```
174
175
 
176
+ ```
177
+ # |M0|---(M1)
178
+ LD M0
179
+ OUT M1
180
+ ```
175
181
 
182
+ [![https://gyazo.com/565d24a35887503281a46775f6ccd747](https://i.gyazo.com/565d24a35887503281a46775f6ccd747.gif)](https://gyazo.com/565d24a35887503281a46775f6ccd747)
176
183
 
177
- [![](http://img.youtube.com/vi/qGbicGLB7Gs/0.jpg)](https://youtu.be/qGbicGLB7Gs)
184
+ <!-- [![](http://img.youtube.com/vi/qGbicGLB7Gs/0.jpg)](https://youtu.be/qGbicGLB7Gs) -->
178
185
 
179
186
  ## エスカレーターに関する情報
180
187
 
@@ -46,13 +46,14 @@ module Escalator
46
46
  d = protocol.device_by_name EscDevice.new($1)
47
47
  c = $2 ? $2.to_i : 1
48
48
  values = protocol.get_from_devices d, c
49
+ values = values.map{|v| case v; when true; 1; when false; 0; else; v; end}
49
50
  puts values.join(" ")
50
51
  when /^p\s+(\w+)(\s+(\d+))?/
51
52
  d = protocol.device_by_name EscDevice.new($1)
52
53
  t = $2 ? $2.to_f : 0.1
53
- protocol.set_to_devices d, 1
54
+ protocol.set_to_devices d, true
54
55
  sleep t
55
- protocol.set_to_devices d, 0
56
+ protocol.set_to_devices d, false
56
57
  when /^w\s+(\w+)/
57
58
  d = protocol.device_by_name EscDevice.new($1)
58
59
  v = $'.scan(/\d+/).map{|e| e.to_i}
@@ -55,7 +55,7 @@ module Keyence
55
55
 
56
56
  def get_bits_from_device count, device
57
57
  values = get_words_from_device count, device
58
- values.map{|v| v == 0 ? false : true}
58
+ values = values.map{|v| v == 0 ? false : true}
59
59
  values.each do |v|
60
60
  device.bool = v
61
61
  device = device_by_name (device+1).name
@@ -86,8 +86,10 @@ module Protocol
86
86
  end
87
87
 
88
88
  def set_to_devices device, values
89
+ values = [values] unless values.is_a? Array
89
90
  d = device_by_name device
90
91
  if d.bit_device?
92
+ values = values.map{|v| case v; when 1; true; when 0; false; else; v; end}
91
93
  set_bits_to_device values, d
92
94
  else
93
95
  set_words_to_device values, d
@@ -22,5 +22,5 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
24
  module Escalator
25
- VERSION = "0.2.3"
25
+ VERSION = "0.2.4"
26
26
  end
@@ -45,6 +45,10 @@ module Emulator
45
45
 
46
46
  CYCLE_RUN_FLAG = 2
47
47
 
48
+ INDEX_BIT_STACK_COUNT = 4
49
+ INDEX_BIT_STACK = 5
50
+ SIZE_OF_BIT_STACK = 3
51
+
48
52
  def initialize
49
53
  SUFFIXES.each do |k|
50
54
  eval "@#{k}_devices = []"
@@ -95,7 +99,7 @@ module Emulator
95
99
  when 0
96
100
  status_form_plc.value = CYCLE_RUN_FLAG
97
101
  @program_pointer = 0
98
- @stacks = [[]]
102
+ clear_stacks
99
103
  while fetch_and_execution; end
100
104
  sleep 0.0001
101
105
  else
@@ -105,18 +109,14 @@ module Emulator
105
109
  end
106
110
 
107
111
  def bool
108
- unless @stacks.empty?
109
- !!@stacks.last.last
110
- else
111
- nil
112
- end
112
+ (stack_device.word & 1) != 0 ? true : false
113
113
  end
114
114
 
115
115
  def bool= value
116
- if stack.empty?
117
- stack << value
116
+ if value
117
+ stack_device.word |= 1
118
118
  else
119
- stack[-1] = value
119
+ stack_device.word &= 0xfffe;
120
120
  end
121
121
  end
122
122
 
@@ -196,10 +196,71 @@ module Emulator
196
196
 
197
197
  private
198
198
 
199
- def stack
200
- @stacks.last
199
+ # ----------------
200
+ # stack operations
201
+ def stack_device index=0
202
+ device_by_name (device_by_name("SD0") + INDEX_BIT_STACK + index).name
203
+ end
204
+
205
+ def stack_count_device
206
+ device_by_name (device_by_name("SD0") + INDEX_BIT_STACK_COUNT).name
207
+ end
208
+
209
+ def push_stack flag = false
210
+ stack_device.word <<= 1
211
+ if flag
212
+ stack_device.word |= 1
213
+ else
214
+ stack_device.word &= 0xfffe
215
+ end
216
+ stack_device.word &= 0xffff
217
+ end
218
+
219
+ def pop_stack
220
+ stack_device.word >>= 1
221
+ stack_device.word |= 0x8000
201
222
  end
202
223
 
224
+ def clear_stacks
225
+ stack_device.word = 0xffff
226
+ stack_count_device.word = 0
227
+ end
228
+
229
+ def push_stacks
230
+ if stack_count_device.word > SIZE_OF_BIT_STACK
231
+ puts "ERROR: stacks overflow pc: H#{program_pointer.to_s(16).rjust(4, "0")}"
232
+ return
233
+ end
234
+ values = []
235
+ (SIZE_OF_BIT_STACK - 1).downto 0 do |i|
236
+ values << stack_device(i).word
237
+ end
238
+ values.shift
239
+ values << 0xffff
240
+ SIZE_OF_BIT_STACK.times do |i|
241
+ stack_device(i).word = values.pop
242
+ end
243
+ stack_count_device.word += 1
244
+ end
245
+
246
+ def pop_stacks
247
+ if stack_count_device.word <= 0
248
+ puts "ERROR: stacks underflow pc: H#{program_pointer.to_s(16).rjust(4, "0")}"
249
+ return
250
+ end
251
+ values = []
252
+ (SIZE_OF_BIT_STACK - 1).downto 0 do |i|
253
+ values << stack_device(i).word
254
+ end
255
+ v = values.pop
256
+ values.each_with_index do |v, i|
257
+ stack_device(i).word = v
258
+ end
259
+ stack_count_device.word -= 1
260
+ v
261
+ end
262
+ # ----------------
263
+
203
264
  def sync_input
204
265
  @lock.synchronize {
205
266
  device_dict.values.each do |d|
@@ -217,7 +278,10 @@ module Emulator
217
278
  end
218
279
 
219
280
  def and_join_stack
220
- @stacks[-1] = [@stacks.last.inject(true){|r,b| r & b}]
281
+ d = stack_device
282
+ b = d.word == 0xffff
283
+ d.word = 0xffff
284
+ push_stack b
221
285
  end
222
286
 
223
287
  def mnenonic_table
@@ -324,7 +388,7 @@ EOB
324
388
  def ld inverse=false
325
389
  b = fetch_bool_value inverse
326
390
  return false if b.nil?
327
- stack << b
391
+ push_stack b
328
392
  true
329
393
  end
330
394
  def ldi; ld true; end
@@ -352,12 +416,15 @@ EOB
352
416
  def ori; send :or, true; end
353
417
 
354
418
  def anb
419
+ b = self.bool
420
+ pop_stack
421
+ self.bool &= b
355
422
  true
356
423
  end
357
424
 
358
425
  def orb
359
426
  b = self.bool
360
- stack.pop
427
+ pop_stack
361
428
  self.bool |= b
362
429
  true
363
430
  end
@@ -366,13 +433,17 @@ EOB
366
433
 
367
434
  def mps
368
435
  and_join_stack
369
- @stacks << [self.bool]
436
+ b = self.bool
437
+ push_stacks
438
+ push_stack b
370
439
  true
371
440
  end
372
441
 
373
442
  def mrd
374
- @stacks.pop
375
- @stacks << [self.bool]
443
+ b = self.bool
444
+ pop_stacks
445
+ push_stacks
446
+ push_stack b
376
447
  true
377
448
  end
378
449
  def mpp; mrd; end
@@ -385,7 +456,7 @@ EOB
385
456
  return false
386
457
  end
387
458
  d.bool = inverse ? !self.bool : self.bool unless d.input?
388
- stack.pop
459
+ pop_stack
389
460
  true
390
461
  end
391
462
  def outi; out true; end
@@ -398,7 +469,7 @@ EOB
398
469
  return false
399
470
  end
400
471
  d.bool = !inverse if self.bool unless d.input?
401
- stack.pop
472
+ pop_stack
402
473
  true
403
474
  end
404
475
  def rst; set true; end
Binary file
@@ -1,5 +1,5 @@
1
- # |-|X0|-+-|/X1|-|/Y1|---(Y0)
2
- # |-|Y0|-+
1
+ # |X0|-+-|/X1|-|/Y1|---(Y0)
2
+ # |Y0|-+
3
3
  LD X0
4
4
  OR Y0
5
5
  ANI X1
@@ -49,4 +49,22 @@ OUT Y2
49
49
  MPP
50
50
  OUTI Y3
51
51
 
52
+ # |M14|---[SET M17]
53
+ # SET is not implement completely.
54
+ # If both conditions of set and rst turn on same time, output is not stable.
55
+ LD M14
56
+ SET M17
57
+
58
+ # |M15|---[RST M17]
59
+ # RST is not implement completely.
60
+ # If both conditions of set and rst turn on same time, output is not stable.
61
+ LD M15
62
+ RST M17
63
+
64
+ # |M16|---[FF M17]
65
+ # Currently ff is not supported.
66
+ #LD M16
67
+ #FF M17
68
+
69
+ NOP
52
70
  END
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escalator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuyoshi Ito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-24 00:00:00.000000000 Z
11
+ date: 2016-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor