sicl 0.2.0 → 1.0.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/History.txt +8 -8
- data/Manifest.txt +9 -9
- data/README.txt +93 -79
- data/Rakefile +78 -55
- data/ext/Makefile.bcc +81 -79
- data/ext/extconf.rb +61 -49
- data/ext/sicl.c +752 -749
- data/test/test_sicl.rb +465 -451
- metadata +55 -32
data/ext/extconf.rb
CHANGED
@@ -1,49 +1,61 @@
|
|
1
|
-
#!/usr/bin/ruby -W0
|
2
|
-
|
3
|
-
#
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
1
|
+
#!/usr/bin/ruby -W0
|
2
|
+
################################################################################
|
3
|
+
#
|
4
|
+
# Copyright (c) 2007 Naoki Kobayashi
|
5
|
+
#
|
6
|
+
# This library is free software. ( except for SICL Library )
|
7
|
+
# You can distribute/modify this file under the same terms of ruby.
|
8
|
+
#
|
9
|
+
# $LastChangedDate$
|
10
|
+
# $Revision$
|
11
|
+
# $Author$
|
12
|
+
#
|
13
|
+
################################################################################
|
14
|
+
|
15
|
+
# temporary solution for cygwin
|
16
|
+
case RUBY_PLATFORM
|
17
|
+
when "i386-cygwin"
|
18
|
+
# default file location settings
|
19
|
+
SICL_DIR = "/cygdrive/c/Program Files/Agilent/IO Libraries Suite"
|
20
|
+
SICL_LIB_DIR = "#{SICL_DIR}/lib"
|
21
|
+
SICL_INC_DIR = "#{SICL_DIR}/include"
|
22
|
+
SICL32LIB = "sicl32.lib"
|
23
|
+
# target options
|
24
|
+
SICL_LIB_OPT = "--with-sicl-lib"
|
25
|
+
SICL_INC_OPT = "--with-sicl-include"
|
26
|
+
|
27
|
+
ARGV.delete_if do |arg|
|
28
|
+
case arg
|
29
|
+
when /^(#{SICL_INC_OPT}=)(.*)/
|
30
|
+
SICL_INC_DIR = $2
|
31
|
+
true
|
32
|
+
when /^(#{SICL_LIB_OPT}=)(.*)/
|
33
|
+
SICL_LIB_DIR = $2
|
34
|
+
true
|
35
|
+
else
|
36
|
+
false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
ARGV << "#{SICL_INC_OPT}=#{SICL_INC_DIR}"
|
41
|
+
ARGV << "#{SICL_LIB_OPT}=."
|
42
|
+
SICL32LIB = "#{SICL_LIB_DIR}/#{SICL32LIB}"
|
43
|
+
|
44
|
+
raise IOError.new("'#{SICL32LIB}': No such file") unless File.exist?(SICL32LIB)
|
45
|
+
|
46
|
+
# convert dynamic link library to static link library
|
47
|
+
`printf 'NAME sicl32.dll\nEXPORTS\n' >x.def`
|
48
|
+
`nm -g --defined '#{SICL32LIB}' | sed -n '/00000000 I __imp__/s///p' >>x.def`
|
49
|
+
`dlltool --def=x.def --output-lib=libsicl.a`
|
50
|
+
`rm x.def`
|
51
|
+
else
|
52
|
+
end
|
53
|
+
|
54
|
+
require 'mkmf'
|
55
|
+
|
56
|
+
dir_config('sicl')
|
57
|
+
|
58
|
+
if have_header('sicl.h') and have_library('sicl')
|
59
|
+
create_makefile('sicl')
|
60
|
+
end
|
61
|
+
|
data/ext/sicl.c
CHANGED
@@ -1,749 +1,752 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (c) 2005-2006 Naoki Kobayashi
|
3
|
-
*
|
4
|
-
* This library is free software.
|
5
|
-
* You can distribute/modify this file under the same terms of ruby.
|
6
|
-
*
|
7
|
-
* $
|
8
|
-
*
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
16
|
-
#
|
17
|
-
|
18
|
-
#
|
19
|
-
|
20
|
-
#
|
21
|
-
|
22
|
-
#
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
-----------------------------------------------------------------------
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
static VALUE
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
static ID
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
static
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
-----------------------------------------------------------------------
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
-----------------------------------------------------------------------
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
inst->
|
74
|
-
}
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
-----------------------------------------------------------------------
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
inst
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
}
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
rb_ivar_set
|
293
|
-
rb_ivar_set
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
rb_ivar_set
|
365
|
-
else
|
366
|
-
rb_ivar_set
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
int
|
381
|
-
|
382
|
-
|
383
|
-
long
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
int
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
if (
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
VALUE
|
493
|
-
VALUE
|
494
|
-
VALUE
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
int
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
VALUE
|
661
|
-
VALUE
|
662
|
-
VALUE
|
663
|
-
VALUE
|
664
|
-
VALUE
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
-----------------------------------------------------------------------
|
669
|
-
|
670
|
-
|
671
|
-
#
|
672
|
-
void Init_sicl()
|
673
|
-
#
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
rb_define_const
|
682
|
-
rb_define_const
|
683
|
-
rb_define_const
|
684
|
-
rb_define_const
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
rb_define_method
|
711
|
-
rb_define_method
|
712
|
-
rb_define_method
|
713
|
-
rb_define_method
|
714
|
-
rb_define_method
|
715
|
-
|
716
|
-
rb_define_method
|
717
|
-
rb_define_method
|
718
|
-
|
719
|
-
rb_define_method
|
720
|
-
rb_define_method
|
721
|
-
rb_define_method
|
722
|
-
rb_define_method
|
723
|
-
rb_define_method
|
724
|
-
|
725
|
-
rb_define_method
|
726
|
-
rb_define_method
|
727
|
-
|
728
|
-
|
729
|
-
rb_define_method
|
730
|
-
rb_define_method
|
731
|
-
|
732
|
-
rb_define_method
|
733
|
-
rb_define_method
|
734
|
-
rb_define_method
|
735
|
-
rb_define_method
|
736
|
-
|
737
|
-
rb_define_method
|
738
|
-
rb_define_method
|
739
|
-
|
740
|
-
rb_define_method
|
741
|
-
rb_define_method
|
742
|
-
rb_define_method
|
743
|
-
rb_define_method
|
744
|
-
rb_define_method
|
745
|
-
|
746
|
-
|
747
|
-
rb_define_method
|
748
|
-
|
749
|
-
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2005-2006 Naoki Kobayashi
|
3
|
+
*
|
4
|
+
* This library is free software.(except for SICL Library)
|
5
|
+
* You can distribute/modify this file under the same terms of ruby.
|
6
|
+
*
|
7
|
+
* $LastChangedDate$
|
8
|
+
* $Revision$
|
9
|
+
* $Author$
|
10
|
+
*
|
11
|
+
*/
|
12
|
+
|
13
|
+
#if defined(__BORLANDC__) || defined(__CYGWIN__)
|
14
|
+
# define _MSC_VER 1200
|
15
|
+
# include <windows.h>
|
16
|
+
#endif /* __BORLANDC__ */
|
17
|
+
|
18
|
+
#if defined(__CYGWIN__)
|
19
|
+
# define _REENT_ONLY
|
20
|
+
#endif /* __CYGWIN__ */
|
21
|
+
|
22
|
+
#if defined(__BORLANDC__)
|
23
|
+
__declspec(dllexport) BOOL __stdcall DllMain(HANDLE h, DWORD w, LPVOID p) { return TRUE; }
|
24
|
+
#endif /* __BORLANDC__ */
|
25
|
+
|
26
|
+
#include <ruby.h>
|
27
|
+
#include "sicl.h"
|
28
|
+
|
29
|
+
/* -----------------------------------------------------------------------
|
30
|
+
File Local Variables
|
31
|
+
----------------------------------------------------------------------- */
|
32
|
+
|
33
|
+
/* prototype of class and module */
|
34
|
+
static VALUE mSicl;
|
35
|
+
static VALUE cInstrument;
|
36
|
+
static VALUE eSicl;
|
37
|
+
|
38
|
+
/* hash table of internal configurations */
|
39
|
+
static VALUE gConfig;
|
40
|
+
|
41
|
+
/* id of event handlers */
|
42
|
+
static ID s_errhdlr;
|
43
|
+
static ID s_srqhdlr;
|
44
|
+
static ID s_intrhdlr;
|
45
|
+
|
46
|
+
/* id of 'call' method of Proc object */
|
47
|
+
static ID s_call;
|
48
|
+
|
49
|
+
/* id of 'buf_mode' method of SICL::Instrument object */
|
50
|
+
static ID s_buf_mode;
|
51
|
+
|
52
|
+
static const VALUE READ_ALL_DATA = INT2FIX(-1);
|
53
|
+
static const char EOL[] = "\r\n";
|
54
|
+
|
55
|
+
/* -----------------------------------------------------------------------
|
56
|
+
struct cparse_params
|
57
|
+
----------------------------------------------------------------------- */
|
58
|
+
|
59
|
+
struct instrument {
|
60
|
+
INST id;
|
61
|
+
int err;
|
62
|
+
};
|
63
|
+
|
64
|
+
/* -----------------------------------------------------------------------
|
65
|
+
Utils
|
66
|
+
----------------------------------------------------------------------- */
|
67
|
+
|
68
|
+
#define CLEAR_ERROR(inst) do { inst->err=0; } while (0)
|
69
|
+
|
70
|
+
static VALUE sicl_return(VALUE self, struct instrument * inst, int error)
|
71
|
+
{
|
72
|
+
if (error) {
|
73
|
+
inst->err = error;
|
74
|
+
} else {
|
75
|
+
inst->err = 0;
|
76
|
+
}
|
77
|
+
|
78
|
+
return error ? Qnil : self;
|
79
|
+
}
|
80
|
+
|
81
|
+
/* -----------------------------------------------------------------------
|
82
|
+
SICL wrapper Main Routines
|
83
|
+
----------------------------------------------------------------------- */
|
84
|
+
|
85
|
+
static VALUE sicl_close (VALUE self)
|
86
|
+
{
|
87
|
+
rb_funcall(self, rb_intern("close"), 0, 0);
|
88
|
+
}
|
89
|
+
|
90
|
+
/* error handler(dummy) for sicl_enter () */
|
91
|
+
static void SICLCALLBACK dmy_handler(INST id, int error)
|
92
|
+
{
|
93
|
+
; /* do nothing. */
|
94
|
+
}
|
95
|
+
|
96
|
+
/* error handler */
|
97
|
+
static void SICLCALLBACK err_handler(INST id, int error)
|
98
|
+
{
|
99
|
+
VALUE self = rb_hash_aref(gConfig, INT2FIX(id));
|
100
|
+
VALUE hdlr = rb_ivar_get(self, s_errhdlr);
|
101
|
+
|
102
|
+
if (! NIL_P(self)) {
|
103
|
+
/* save error code */
|
104
|
+
struct instrument * inst = NULL;
|
105
|
+
Data_Get_Struct(self, struct instrument, inst);
|
106
|
+
inst->err = error;
|
107
|
+
}
|
108
|
+
|
109
|
+
if (! NIL_P(hdlr)) {
|
110
|
+
VALUE err = rb_ary_new ();
|
111
|
+
rb_ary_push(err, INT2FIX(error));
|
112
|
+
rb_ary_push(err, rb_str_new2(igeterrstr(error)));
|
113
|
+
|
114
|
+
rb_funcall(hdlr, s_call, 1, err);
|
115
|
+
} else {
|
116
|
+
rb_raise(eSicl, igeterrstr(error));
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
/* srq handler */
|
121
|
+
static void SICLCALLBACK srq_handler(INST id)
|
122
|
+
{
|
123
|
+
VALUE self = rb_hash_aref(gConfig, INT2FIX(id));
|
124
|
+
VALUE hdlr = rb_ivar_get(self, s_srqhdlr);
|
125
|
+
|
126
|
+
if (! NIL_P(hdlr))
|
127
|
+
rb_funcall(hdlr, s_call, 0);
|
128
|
+
}
|
129
|
+
|
130
|
+
/* interrupt handler */
|
131
|
+
static void SICLCALLBACK intr_handler(INST id, long reason, long secval)
|
132
|
+
{
|
133
|
+
VALUE self = rb_hash_aref(gConfig, INT2FIX(id));
|
134
|
+
VALUE hdlr = rb_ivar_get(self, s_srqhdlr);
|
135
|
+
|
136
|
+
if (! NIL_P(hdlr))
|
137
|
+
rb_funcall(hdlr, s_call, 2, INT2FIX(reason), INT2FIX(secval));
|
138
|
+
}
|
139
|
+
|
140
|
+
static VALUE sicl_s_igeterrstr(VALUE self, VALUE code)
|
141
|
+
{
|
142
|
+
Check_Type(code, T_FIXNUM);
|
143
|
+
|
144
|
+
return rb_str_new2(igeterrstr(FIX2INT(code)));
|
145
|
+
}
|
146
|
+
|
147
|
+
static VALUE sicl_igeterrstr(VALUE self)
|
148
|
+
{
|
149
|
+
struct instrument * inst = NULL;
|
150
|
+
|
151
|
+
Data_Get_Struct(self, struct instrument, inst);
|
152
|
+
|
153
|
+
return rb_str_new2(igeterrstr(inst->err));
|
154
|
+
}
|
155
|
+
|
156
|
+
static VALUE sicl_igeterrno(VALUE self)
|
157
|
+
{
|
158
|
+
struct instrument * inst = NULL;
|
159
|
+
|
160
|
+
Data_Get_Struct(self, struct instrument, inst);
|
161
|
+
|
162
|
+
return INT2FIX(inst->err);
|
163
|
+
}
|
164
|
+
|
165
|
+
static VALUE sicl_ionerror(VALUE self, VALUE proc)
|
166
|
+
{
|
167
|
+
if (NIL_P(proc) || CLASS_OF(proc)==rb_cProc) {
|
168
|
+
|
169
|
+
rb_ivar_set(self, s_errhdlr, proc);
|
170
|
+
|
171
|
+
} else {
|
172
|
+
|
173
|
+
rb_raise(rb_eTypeError, "Need a block or nil");
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
return self;
|
178
|
+
}
|
179
|
+
|
180
|
+
static VALUE sicl_igetonerror(VALUE self)
|
181
|
+
{
|
182
|
+
if (rb_block_given_p()) {
|
183
|
+
|
184
|
+
rb_ivar_set(self, s_errhdlr, rb_block_proc());
|
185
|
+
|
186
|
+
return self;
|
187
|
+
|
188
|
+
} else {
|
189
|
+
|
190
|
+
return rb_ivar_get(self, s_errhdlr);
|
191
|
+
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
195
|
+
static VALUE sicl_ionsrq(VALUE self, VALUE proc)
|
196
|
+
{
|
197
|
+
struct instrument * inst = NULL;
|
198
|
+
|
199
|
+
Data_Get_Struct(self, struct instrument, inst);
|
200
|
+
|
201
|
+
if (NIL_P(proc)) {
|
202
|
+
|
203
|
+
rb_ivar_set(self, s_srqhdlr, proc);
|
204
|
+
ionsrq(inst->id, 0);
|
205
|
+
|
206
|
+
} else if (CLASS_OF(proc)==rb_cProc) {
|
207
|
+
|
208
|
+
rb_ivar_set(self, s_srqhdlr, proc);
|
209
|
+
ionsrq(inst->id, srq_handler);
|
210
|
+
|
211
|
+
} else {
|
212
|
+
|
213
|
+
rb_raise(rb_eTypeError, "Need a block or nil");
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
return self;
|
218
|
+
}
|
219
|
+
|
220
|
+
static VALUE sicl_igetonsrq(VALUE self)
|
221
|
+
{
|
222
|
+
struct instrument * inst = NULL;
|
223
|
+
|
224
|
+
Data_Get_Struct(self, struct instrument, inst);
|
225
|
+
|
226
|
+
if (rb_block_given_p()) {
|
227
|
+
|
228
|
+
rb_ivar_set(self, s_srqhdlr, rb_block_proc());
|
229
|
+
ionsrq(inst->id, srq_handler);
|
230
|
+
|
231
|
+
return self;
|
232
|
+
|
233
|
+
} else {
|
234
|
+
|
235
|
+
return rb_ivar_get(self, s_srqhdlr);
|
236
|
+
|
237
|
+
}
|
238
|
+
}
|
239
|
+
|
240
|
+
static VALUE sicl_ionintr(VALUE self, VALUE proc)
|
241
|
+
{
|
242
|
+
struct instrument * inst = NULL;
|
243
|
+
|
244
|
+
Data_Get_Struct(self, struct instrument, inst);
|
245
|
+
|
246
|
+
if (NIL_P(proc)) {
|
247
|
+
|
248
|
+
rb_ivar_set(self, s_intrhdlr, proc);
|
249
|
+
ionintr(inst->id, 0);
|
250
|
+
|
251
|
+
} else if (CLASS_OF(proc)==rb_cProc) {
|
252
|
+
|
253
|
+
rb_ivar_set(self, s_intrhdlr, proc);
|
254
|
+
ionintr(inst->id, intr_handler);
|
255
|
+
|
256
|
+
} else {
|
257
|
+
|
258
|
+
rb_raise(rb_eTypeError, "Need a block or nil");
|
259
|
+
|
260
|
+
}
|
261
|
+
|
262
|
+
return self;
|
263
|
+
}
|
264
|
+
|
265
|
+
static VALUE sicl_igetonintr(VALUE self)
|
266
|
+
{
|
267
|
+
struct instrument * inst = NULL;
|
268
|
+
|
269
|
+
Data_Get_Struct(self, struct instrument, inst);
|
270
|
+
|
271
|
+
if (rb_block_given_p()) {
|
272
|
+
|
273
|
+
rb_ivar_set(self, s_intrhdlr, rb_block_proc());
|
274
|
+
ionintr(inst->id, intr_handler);
|
275
|
+
|
276
|
+
return self;
|
277
|
+
|
278
|
+
} else {
|
279
|
+
|
280
|
+
return rb_ivar_get(self, s_intrhdlr);
|
281
|
+
|
282
|
+
}
|
283
|
+
}
|
284
|
+
|
285
|
+
static VALUE sicl_s_allocate(VALUE klass)
|
286
|
+
{
|
287
|
+
VALUE self = 0;
|
288
|
+
struct instrument * inst = NULL;
|
289
|
+
|
290
|
+
self = Data_Make_Struct(klass, struct instrument, 0, 0, inst);
|
291
|
+
|
292
|
+
rb_ivar_set(self, s_errhdlr, Qnil);
|
293
|
+
rb_ivar_set(self, s_srqhdlr, Qnil);
|
294
|
+
rb_ivar_set(self, s_intrhdlr, Qnil);
|
295
|
+
rb_ivar_set(self, s_buf_mode, Qnil);
|
296
|
+
|
297
|
+
return self;
|
298
|
+
}
|
299
|
+
|
300
|
+
static VALUE sicl_iopen(VALUE self, VALUE addr)
|
301
|
+
{
|
302
|
+
struct instrument * inst = NULL;
|
303
|
+
|
304
|
+
Data_Get_Struct(self, struct instrument, inst);
|
305
|
+
|
306
|
+
Check_Type(addr, T_STRING);
|
307
|
+
|
308
|
+
inst->id = iopen(RSTRING(addr)->ptr);
|
309
|
+
itimeout(inst->id, 5000);
|
310
|
+
|
311
|
+
rb_hash_aset(gConfig, INT2FIX(inst->id), self);
|
312
|
+
|
313
|
+
CLEAR_ERROR(inst);
|
314
|
+
|
315
|
+
if (rb_block_given_p()) {
|
316
|
+
return rb_ensure(rb_yield, self, sicl_close, self);
|
317
|
+
}
|
318
|
+
|
319
|
+
return self;
|
320
|
+
}
|
321
|
+
|
322
|
+
static VALUE sicl_s_iopen(VALUE klass, VALUE addr)
|
323
|
+
{
|
324
|
+
VALUE self = sicl_s_allocate (cInstrument);
|
325
|
+
|
326
|
+
return sicl_iopen(self, addr);
|
327
|
+
}
|
328
|
+
|
329
|
+
static VALUE sicl_initialize(VALUE self, VALUE addr)
|
330
|
+
{
|
331
|
+
return sicl_iopen(self, addr);
|
332
|
+
}
|
333
|
+
|
334
|
+
static VALUE sicl_itimeout(VALUE self, VALUE ms)
|
335
|
+
{
|
336
|
+
int err = 0;
|
337
|
+
struct instrument * inst = NULL;
|
338
|
+
|
339
|
+
Check_Type(ms, T_FIXNUM);
|
340
|
+
|
341
|
+
Data_Get_Struct(self, struct instrument, inst);
|
342
|
+
|
343
|
+
err = itimeout(inst->id, FIX2INT(ms));
|
344
|
+
|
345
|
+
return sicl_return(self, inst, err);
|
346
|
+
}
|
347
|
+
|
348
|
+
static VALUE sicl_igettimeout(VALUE self)
|
349
|
+
{
|
350
|
+
int err = 0;
|
351
|
+
long tval = 0;
|
352
|
+
struct instrument * inst = NULL;
|
353
|
+
|
354
|
+
Data_Get_Struct(self, struct instrument, inst);
|
355
|
+
|
356
|
+
err = igettimeout(inst->id, & tval);
|
357
|
+
|
358
|
+
return sicl_return(INT2FIX(tval), inst, err);
|
359
|
+
}
|
360
|
+
|
361
|
+
static VALUE sicl_set_buf_mode(VALUE self, VALUE enabled)
|
362
|
+
{
|
363
|
+
if (NIL_P(enabled))
|
364
|
+
rb_ivar_set(self, s_buf_mode, Qnil);
|
365
|
+
else if (TYPE(enabled)==T_FALSE)
|
366
|
+
rb_ivar_set(self, s_buf_mode, Qfalse);
|
367
|
+
else
|
368
|
+
rb_ivar_set(self, s_buf_mode, Qtrue);
|
369
|
+
|
370
|
+
return self;
|
371
|
+
}
|
372
|
+
|
373
|
+
static VALUE sicl_get_buf_mode(VALUE self)
|
374
|
+
{
|
375
|
+
return rb_ivar_get(self, s_buf_mode);
|
376
|
+
}
|
377
|
+
|
378
|
+
static VALUE sicl_iwrite(VALUE self, VALUE cmd, VALUE eoi)
|
379
|
+
{
|
380
|
+
int err = 0;
|
381
|
+
struct instrument * inst = NULL;
|
382
|
+
int endi = 0; /* send END indicator, or not */
|
383
|
+
unsigned long actualcnt = 0;
|
384
|
+
char * ptr = NULL;
|
385
|
+
long len = 0;
|
386
|
+
|
387
|
+
int(* write_func)(INST, char *, unsigned long, int, unsigned long *) = iwrite;
|
388
|
+
|
389
|
+
Check_Type(cmd, T_STRING);
|
390
|
+
|
391
|
+
if (TYPE(eoi)==T_TRUE) endi = 1;
|
392
|
+
|
393
|
+
Data_Get_Struct(self, struct instrument, inst);
|
394
|
+
|
395
|
+
ptr = RSTRING(cmd)->ptr;
|
396
|
+
len = RSTRING(cmd)->len;
|
397
|
+
|
398
|
+
if (rb_ivar_get(self, s_buf_mode)==Qtrue) write_func = ifwrite;
|
399
|
+
|
400
|
+
while (len>0) {
|
401
|
+
err = write_func(inst->id, ptr, len, endi, & actualcnt);
|
402
|
+
|
403
|
+
if (err) break;
|
404
|
+
|
405
|
+
ptr += actualcnt;
|
406
|
+
len -= actualcnt;
|
407
|
+
}
|
408
|
+
|
409
|
+
return sicl_return(self, inst, err);
|
410
|
+
}
|
411
|
+
|
412
|
+
static VALUE sicl_iwrite_op(VALUE self, VALUE cmd)
|
413
|
+
{
|
414
|
+
VALUE eoi = Qfalse;
|
415
|
+
char ch = 0;
|
416
|
+
|
417
|
+
Check_Type(cmd, T_STRING);
|
418
|
+
|
419
|
+
ch = RSTRING(cmd)->ptr[RSTRING(cmd)->len-1];
|
420
|
+
|
421
|
+
if (ch == '\r' || ch == '\n') eoi = Qtrue;
|
422
|
+
|
423
|
+
return sicl_iwrite(self, cmd, eoi);
|
424
|
+
}
|
425
|
+
|
426
|
+
static VALUE sicl_iwrite_arg(int argc, VALUE * argv, VALUE self)
|
427
|
+
{
|
428
|
+
VALUE cmd = 0;
|
429
|
+
VALUE eoi = 0;
|
430
|
+
|
431
|
+
rb_scan_args(argc, argv, "11", & cmd, & eoi);
|
432
|
+
|
433
|
+
return sicl_iwrite(self, cmd, eoi);
|
434
|
+
}
|
435
|
+
|
436
|
+
static VALUE sicl_iread(VALUE self, VALUE max)
|
437
|
+
{
|
438
|
+
int err = 0;
|
439
|
+
struct instrument * inst = NULL;
|
440
|
+
char buf[0x100];
|
441
|
+
int size = sizeof(buf)-1;
|
442
|
+
int len = NUM2INT(READ_ALL_DATA);
|
443
|
+
int reason = 0;
|
444
|
+
unsigned long actualcnt = 0;
|
445
|
+
|
446
|
+
int(* read_func)(INST, char *, unsigned long, int *, unsigned long *) = iread;
|
447
|
+
|
448
|
+
VALUE str = rb_str_new2 ("");
|
449
|
+
|
450
|
+
buf[0] = '\0';
|
451
|
+
|
452
|
+
if (! NIL_P(max)) len = NUM2INT(max);
|
453
|
+
|
454
|
+
Data_Get_Struct(self, struct instrument, inst);
|
455
|
+
|
456
|
+
if (rb_ivar_get(self, s_buf_mode)==Qtrue) read_func = ifread;
|
457
|
+
|
458
|
+
for (;;) {
|
459
|
+
if (len==0) break;
|
460
|
+
|
461
|
+
if (0<len && len<size) size = len;
|
462
|
+
|
463
|
+
err = read_func(inst->id, buf, size, & reason, & actualcnt);
|
464
|
+
|
465
|
+
if (err && err!=I_ERR_TIMEOUT) break;
|
466
|
+
|
467
|
+
len -= actualcnt;
|
468
|
+
rb_str_cat(str, buf, actualcnt);
|
469
|
+
|
470
|
+
if (err==I_ERR_TIMEOUT) {
|
471
|
+
if (RSTRING(str)->len>0) err = I_ERR_NOERROR;
|
472
|
+
break;
|
473
|
+
}
|
474
|
+
if (reason==I_TERM_END) break;
|
475
|
+
if (reason==I_TERM_CHR) break;
|
476
|
+
}
|
477
|
+
|
478
|
+
return sicl_return(str, inst, err);
|
479
|
+
}
|
480
|
+
|
481
|
+
static VALUE sicl_iread_arg(int argc, VALUE * argv, VALUE self)
|
482
|
+
{
|
483
|
+
VALUE max = 0;
|
484
|
+
|
485
|
+
rb_scan_args(argc, argv, "01", & max);
|
486
|
+
|
487
|
+
return sicl_iread(self, max);
|
488
|
+
}
|
489
|
+
|
490
|
+
static VALUE sicl_output(VALUE self, VALUE cmd)
|
491
|
+
{
|
492
|
+
VALUE tmp = 0;
|
493
|
+
VALUE eoi = Qtrue;
|
494
|
+
VALUE reg1 = 0;
|
495
|
+
VALUE reg2 = 0;
|
496
|
+
VALUE blnk = 0;
|
497
|
+
ID s_gsub = 0;
|
498
|
+
|
499
|
+
Check_Type(cmd, T_STRING);
|
500
|
+
|
501
|
+
reg1 = rb_reg_new("[\\s;]*$", 7, 0);
|
502
|
+
reg2 = rb_reg_new("^[\\s;]*", 7, 0);
|
503
|
+
blnk = rb_str_new2("");
|
504
|
+
s_gsub = rb_intern("gsub");
|
505
|
+
|
506
|
+
tmp = rb_funcall(cmd, s_gsub, 2, reg1, blnk);
|
507
|
+
cmd = rb_funcall(tmp, s_gsub, 2, reg2, blnk);
|
508
|
+
|
509
|
+
rb_str_cat2(cmd, EOL);
|
510
|
+
|
511
|
+
self = sicl_iwrite(self, cmd, eoi);
|
512
|
+
|
513
|
+
return self;
|
514
|
+
}
|
515
|
+
|
516
|
+
static VALUE sicl_enter(VALUE self)
|
517
|
+
{
|
518
|
+
VALUE str = 0;
|
519
|
+
const ID s_chomp = rb_intern("chomp");
|
520
|
+
|
521
|
+
ionerror(dmy_handler);
|
522
|
+
|
523
|
+
str = sicl_iread(self, READ_ALL_DATA);
|
524
|
+
|
525
|
+
ionerror(err_handler);
|
526
|
+
|
527
|
+
if (NIL_P(str)) return Qnil;
|
528
|
+
|
529
|
+
str = rb_funcall(str, s_chomp, 0);
|
530
|
+
|
531
|
+
return str;
|
532
|
+
}
|
533
|
+
|
534
|
+
static VALUE sicl_enter2(VALUE self, VALUE out)
|
535
|
+
{
|
536
|
+
VALUE str = 0;
|
537
|
+
const VALUE reg = rb_reg_new(".*", 2, 0);
|
538
|
+
const ID s_gsub = rb_intern ("gsub!");
|
539
|
+
|
540
|
+
Check_Type(out, T_STRING);
|
541
|
+
|
542
|
+
str = sicl_enter(self);
|
543
|
+
|
544
|
+
if (NIL_P(str)) return Qnil;
|
545
|
+
|
546
|
+
rb_funcall(out, s_gsub, 2, reg, str);
|
547
|
+
|
548
|
+
return self;
|
549
|
+
}
|
550
|
+
|
551
|
+
static VALUE sicl_query(VALUE self, VALUE cmd)
|
552
|
+
{
|
553
|
+
self = sicl_output(self, cmd);
|
554
|
+
|
555
|
+
return NIL_P(self) ? Qnil : sicl_enter(self);
|
556
|
+
}
|
557
|
+
|
558
|
+
static VALUE sicl_ireadstb(VALUE self)
|
559
|
+
{
|
560
|
+
int err = 0;
|
561
|
+
struct instrument * inst = NULL;
|
562
|
+
unsigned char stb = 0;
|
563
|
+
|
564
|
+
Data_Get_Struct(self, struct instrument, inst);
|
565
|
+
|
566
|
+
err = ireadstb(inst->id, & stb);
|
567
|
+
|
568
|
+
return sicl_return(INT2FIX(stb), inst, err);
|
569
|
+
}
|
570
|
+
|
571
|
+
static int sicl_func(VALUE self, int (*func)(INST))
|
572
|
+
{
|
573
|
+
int err = 0;
|
574
|
+
struct instrument * inst = NULL;
|
575
|
+
|
576
|
+
Data_Get_Struct(self, struct instrument, inst);
|
577
|
+
|
578
|
+
err = func(inst->id);
|
579
|
+
|
580
|
+
return sicl_return(self, inst, err);
|
581
|
+
}
|
582
|
+
|
583
|
+
static VALUE sicl_iclose (VALUE self)
|
584
|
+
{
|
585
|
+
int err = 0;
|
586
|
+
struct instrument * inst = NULL;
|
587
|
+
INST id = 0;
|
588
|
+
|
589
|
+
Data_Get_Struct(self, struct instrument, inst);
|
590
|
+
|
591
|
+
id = inst->id;
|
592
|
+
|
593
|
+
err = iclose(inst->id);
|
594
|
+
|
595
|
+
if (!err)
|
596
|
+
rb_hash_delete(gConfig, INT2FIX(id));
|
597
|
+
|
598
|
+
return !err ? Qtrue : Qfalse;
|
599
|
+
}
|
600
|
+
|
601
|
+
static VALUE sicl_iflush (int argc, VALUE * argv, VALUE self)
|
602
|
+
{
|
603
|
+
int err = 0;
|
604
|
+
struct instrument * inst = NULL;
|
605
|
+
VALUE mask = 0;
|
606
|
+
|
607
|
+
rb_scan_args(argc, argv, "01", & mask);
|
608
|
+
|
609
|
+
if (NIL_P(mask)) mask = INT2FIX(I_BUF_READ | I_BUF_WRITE_END);
|
610
|
+
|
611
|
+
Check_Type(mask, T_FIXNUM);
|
612
|
+
|
613
|
+
Data_Get_Struct(self, struct instrument, inst);
|
614
|
+
|
615
|
+
err = iflush(inst->id, FIX2INT(mask));
|
616
|
+
|
617
|
+
return sicl_return(self, inst, err);
|
618
|
+
}
|
619
|
+
|
620
|
+
static VALUE sicl_igetaddr (VALUE self)
|
621
|
+
{
|
622
|
+
int err = 0;
|
623
|
+
struct instrument * inst = NULL;
|
624
|
+
char * addr = NULL;
|
625
|
+
|
626
|
+
Data_Get_Struct(self, struct instrument, inst);
|
627
|
+
|
628
|
+
err = igetaddr(inst->id, & addr);
|
629
|
+
|
630
|
+
return sicl_return(rb_str_new2(addr), inst, err);
|
631
|
+
}
|
632
|
+
|
633
|
+
static VALUE sicl_itermchr (VALUE self, VALUE tchr)
|
634
|
+
{
|
635
|
+
int err = 0;
|
636
|
+
struct instrument * inst = NULL;
|
637
|
+
|
638
|
+
Data_Get_Struct(self, struct instrument, inst);
|
639
|
+
|
640
|
+
Check_Type(tchr, T_FIXNUM);
|
641
|
+
|
642
|
+
err = itermchr(inst->id, FIX2INT(tchr));
|
643
|
+
|
644
|
+
return sicl_return(self, inst, err);
|
645
|
+
}
|
646
|
+
|
647
|
+
static VALUE sicl_igettermchr (VALUE self)
|
648
|
+
{
|
649
|
+
int err = 0;
|
650
|
+
struct instrument * inst = NULL;
|
651
|
+
int tchr = 0;
|
652
|
+
|
653
|
+
Data_Get_Struct(self, struct instrument, inst);
|
654
|
+
|
655
|
+
err = igettermchr(inst->id, & tchr);
|
656
|
+
|
657
|
+
return sicl_return(INT2FIX(tchr), inst, err);
|
658
|
+
}
|
659
|
+
|
660
|
+
static VALUE sicl_iabort (VALUE self) { sicl_func(self, iabort); }
|
661
|
+
static VALUE sicl_iclear (VALUE self) { sicl_func(self, iclear); }
|
662
|
+
static VALUE sicl_ilocal (VALUE self) { sicl_func(self, ilocal); }
|
663
|
+
static VALUE sicl_iremote(VALUE self) { sicl_func(self, iremote); }
|
664
|
+
static VALUE sicl_ilock (VALUE self) { sicl_func(self, ilock); }
|
665
|
+
static VALUE sicl_iunlock(VALUE self) { sicl_func(self, iunlock); }
|
666
|
+
static VALUE sicl_itrigger(VALUE self) { sicl_func(self, itrigger); }
|
667
|
+
|
668
|
+
/* -----------------------------------------------------------------------
|
669
|
+
Ruby Interface
|
670
|
+
----------------------------------------------------------------------- */
|
671
|
+
#if defined(__BORLANDC__)
|
672
|
+
__declspec(dllexport) void __stdcall Init_sicl()
|
673
|
+
#else /* __BORLANDC__ */
|
674
|
+
void Init_sicl()
|
675
|
+
#endif /* __BORLANDC__ */
|
676
|
+
{
|
677
|
+
mSicl = rb_define_module("SICL");
|
678
|
+
|
679
|
+
rb_define_module_function(mSicl, "open", sicl_s_iopen, 1);
|
680
|
+
|
681
|
+
rb_define_const(mSicl, "BUF_READ" , INT2FIX(I_BUF_READ) );
|
682
|
+
rb_define_const(mSicl, "BUF_WRITE" , INT2FIX(I_BUF_WRITE) );
|
683
|
+
rb_define_const(mSicl, "BUF_WRITE_END" , INT2FIX(I_BUF_WRITE_END) );
|
684
|
+
rb_define_const(mSicl, "BUF_DISCARD_READ" , INT2FIX(I_BUF_DISCARD_READ) );
|
685
|
+
rb_define_const(mSicl, "BUF_DISCARD_WRITE", INT2FIX(I_BUF_DISCARD_WRITE));
|
686
|
+
|
687
|
+
rb_define_const(mSicl, "EOL", rb_str_new2(EOL));
|
688
|
+
|
689
|
+
eSicl = rb_define_class_under(mSicl, "Error", rb_eStandardError);
|
690
|
+
rb_define_singleton_method(eSicl, "errstr", sicl_s_igeterrstr, 1);
|
691
|
+
|
692
|
+
ionerror(err_handler);
|
693
|
+
|
694
|
+
s_call = rb_intern("call");
|
695
|
+
|
696
|
+
s_buf_mode = rb_intern("buf_mode");
|
697
|
+
|
698
|
+
s_errhdlr = rb_intern("errhdlr" );
|
699
|
+
s_srqhdlr = rb_intern("srqhdlr" );
|
700
|
+
s_intrhdlr = rb_intern("intrhdlr");
|
701
|
+
|
702
|
+
gConfig = rb_hash_new ();
|
703
|
+
rb_global_variable(& gConfig);
|
704
|
+
|
705
|
+
cInstrument = rb_define_class_under(mSicl, "Instrument", rb_cObject);
|
706
|
+
|
707
|
+
rb_define_alloc_func(cInstrument, sicl_s_allocate);
|
708
|
+
rb_define_singleton_method(cInstrument, "open", sicl_s_iopen, 1);
|
709
|
+
|
710
|
+
rb_define_method(cInstrument, "initialize" , sicl_initialize, 1);
|
711
|
+
rb_define_method(cInstrument, "close" , sicl_iclose , 0);
|
712
|
+
rb_define_method(cInstrument, "write" , sicl_iwrite_arg, -1);
|
713
|
+
rb_define_method(cInstrument, "<<" , sicl_iwrite_op, 1);
|
714
|
+
rb_define_method(cInstrument, "read" , sicl_iread_arg , -1);
|
715
|
+
rb_define_method(cInstrument, "readstb" , sicl_ireadstb , 0);
|
716
|
+
rb_define_method(cInstrument, "spoll" , sicl_ireadstb , 0);
|
717
|
+
rb_define_method(cInstrument, "flush" , sicl_iflush , -1);
|
718
|
+
|
719
|
+
rb_define_method(cInstrument, "timeout=", sicl_itimeout , 1);
|
720
|
+
rb_define_method(cInstrument, "timeout" , sicl_igettimeout, 0);
|
721
|
+
rb_define_method(cInstrument, "termchr=", sicl_itermchr , 1);
|
722
|
+
rb_define_method(cInstrument, "termchr" , sicl_igettermchr, 0);
|
723
|
+
rb_define_method(cInstrument, "addr" , sicl_igetaddr , 0);
|
724
|
+
rb_define_method(cInstrument, "address" , sicl_igetaddr , 0);
|
725
|
+
rb_define_method(cInstrument, "errstr" , sicl_igeterrstr , 0);
|
726
|
+
rb_define_method(cInstrument, "errno" , sicl_igeterrno , 0);
|
727
|
+
|
728
|
+
rb_define_method(cInstrument, "output" , sicl_output, 1);
|
729
|
+
rb_define_method(cInstrument, "enter" , sicl_enter , 0);
|
730
|
+
rb_define_method(cInstrument, "query" , sicl_query , 1);
|
731
|
+
|
732
|
+
rb_define_method(cInstrument, "abort" , sicl_iabort , 0);
|
733
|
+
rb_define_method(cInstrument, "clear" , sicl_iclear , 0);
|
734
|
+
rb_define_method(cInstrument, "local" , sicl_ilocal , 0);
|
735
|
+
rb_define_method(cInstrument, "remote" , sicl_iremote , 0);
|
736
|
+
rb_define_method(cInstrument, "lock" , sicl_ilock , 0);
|
737
|
+
rb_define_method(cInstrument, "unlock" , sicl_iunlock , 0);
|
738
|
+
rb_define_method(cInstrument, "trigger", sicl_itrigger, 0);
|
739
|
+
|
740
|
+
rb_define_method(cInstrument, "on_error=", sicl_ionerror , 1);
|
741
|
+
rb_define_method(cInstrument, "on_error" , sicl_igetonerror, 0);
|
742
|
+
rb_define_method(cInstrument, "on_srq=" , sicl_ionsrq , 1);
|
743
|
+
rb_define_method(cInstrument, "on_srq" , sicl_igetonsrq , 0);
|
744
|
+
rb_define_method(cInstrument, "on_intr=" , sicl_ionintr , 1);
|
745
|
+
rb_define_method(cInstrument, "on_intr" , sicl_igetonintr , 0);
|
746
|
+
rb_define_method(cInstrument, "on_interrupt=" , sicl_ionintr , 1);
|
747
|
+
rb_define_method(cInstrument, "on_interrupt" , sicl_igetonintr , 0);
|
748
|
+
|
749
|
+
/* accessor for @buf_mode */
|
750
|
+
rb_define_method(cInstrument, "buf_mode=", sicl_set_buf_mode, 1);
|
751
|
+
rb_define_method(cInstrument, "buf_mode" , sicl_get_buf_mode, 0);
|
752
|
+
}
|