sicl 0.1.0 → 0.2.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 CHANGED
@@ -1,3 +1,8 @@
1
+ = 0.2.0 2007-05-12
2
+
3
+ * add build rules for bcc32 with ruby-mswin32.
4
+ * refactor testcases in test/test_sicl.rb.
5
+
1
6
  = 0.1.0 2007-05-12
2
7
 
3
8
  * Birthday!
data/Manifest.txt CHANGED
@@ -5,4 +5,5 @@ Rakefile
5
5
 
6
6
  ext/sicl.c
7
7
  ext/extconf.rb
8
+ ext/Makefile.bcc
8
9
  test/test_sicl.rb
data/README.txt CHANGED
@@ -62,7 +62,15 @@ Agilent Technologies
62
62
 
63
63
  == INSTALL:
64
64
 
65
- * sudo gem install sicl
65
+ $ export http_proxy='http://web-proxy:8088' # if you need
66
+ $ gem install sicl
67
+
68
+ or
69
+
70
+ $ tar jvxf sicl.tar.bz2
71
+ $ cd sicl
72
+ $ ruby extconf.rb
73
+ $ make
66
74
 
67
75
  == LICENSE:
68
76
 
data/Rakefile CHANGED
@@ -30,8 +30,8 @@ task :default => :package
30
30
 
31
31
  spec = Gem::Specification.new do |s|
32
32
  s.name = "sicl"
33
- s.version = "0.1.0"
34
- s.summary = "Agilent SICL API module for Ruby."
33
+ s.version = "0.2.0"
34
+ s.summary = "Agilent SICL API wrapper class for Ruby."
35
35
  s.autorequire = "sicl"
36
36
  s.files = PKG_FILES
37
37
  s.default_executable = "ext/extconf.rb"
@@ -45,3 +45,11 @@ Rake::GemPackageTask.new(spec) do |pkg|
45
45
  pkg.need_tar_bz2 = true
46
46
  pkg.need_tar_gz = true
47
47
  end
48
+
49
+ task :test do
50
+ ruby "-Iext test/test_sicl.rb"
51
+ end
52
+
53
+ task :html do
54
+ sh "rd2 -r rd/rd2html-lib.rb --with-css=style.css doc/sicl.ja.rd > html/sicl.ja.html"
55
+ end
data/ext/Makefile.bcc ADDED
@@ -0,0 +1,79 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (c) 2007 Satoshi Nihonyanagi
4
+ # Copyright (c) 2007 Naoki Kobayashi
5
+ #
6
+ # $Header: $
7
+ #
8
+ # Description:
9
+ #
10
+ # You need to export three environment variables for path of header
11
+ # files and libraries if you wish to build this library.
12
+ #
13
+ # - SICL_DIR is path of Agilent IO Libraries Suite.
14
+ # - BCC_DIR is path of Borland C/C++ compiler.
15
+ # - RUBY_DIR is path of Ruby mswin32 verion.
16
+ #
17
+ # Please, make like this:)
18
+ #
19
+ # $ SICL_DIR='C:\Program Files\Agilent\IO Libraries Suite' \
20
+ # > BCC_DIR='C:\borland\bcc55' RUBY_DIR='C:\ruby-mswin32' \
21
+ # > PATH=/cygdrive/c/borland/bcc55/Bin:$PATH make -f Makefile.bcc
22
+ #
23
+ ################################################################################
24
+
25
+ ################################################################################
26
+ # Path definitions
27
+ ################################################################################
28
+
29
+ #SICL_DIR = C:\Program Files\Agilent\IO Libraries Suite
30
+ SICL_INC_DIR = $(SICL_DIR)\include
31
+ SICL_LIB_DIR = $(SICL_DIR)\lib
32
+
33
+ #BCC_DIR = C:\borland\bcc55
34
+ BCC_INC_DIR = $(BCC_DIR)\include
35
+ BCC_LIB_DIR = $(BCC_DIR)\lib
36
+
37
+ #RUBY_DIR = C:\ruby-mswin32
38
+ RUBY_BIN_DIR = $(RUBY_DIR)\bin
39
+ RUBY_INC_DIR = $(RUBY_DIR)\lib\ruby\1.8\i386-mswin32
40
+ RUBYDLL = msvcrt-ruby18.dll
41
+ RUBYLIB = $(RUBYDLL:.dll=.lib)
42
+
43
+ ################################################################################
44
+ # Compiler and linker settings
45
+ ################################################################################
46
+
47
+ CC = bcc32
48
+ CFLAGS = -O2 -w-8070 -w-8004 -w-8057 \
49
+ -I"$(SICL_INC_DIR)" -I"$(RUBY_INC_DIR)" -I"$(BCC_INC_DIR)" \
50
+ -L"$(BCC_LIB_DIR)"
51
+
52
+ LD = ilink32
53
+ LDFLAGS = -L"$(BCC_LIB_DIR)" -L"$(SICL_LIB_DIR)"
54
+
55
+ ################################################################################
56
+ # List of target files
57
+ ################################################################################
58
+
59
+ SRCS = sicl.c
60
+ OBJS = $(SRCS:.c=.obj)
61
+ LIBS = bcsicl32.lib import32.lib cw32mt.lib $(RUBYLIB)
62
+ SICLDLL = sicl.dll
63
+
64
+ ################################################################################
65
+ # Build rules
66
+ ################################################################################
67
+
68
+ .PHONY: all
69
+ all: $(SICLDLL)
70
+
71
+ $(RUBYLIB): $(RUBY_BIN_DIR)\$(RUBYDLL)
72
+ implib -a $@ $?
73
+
74
+ $(SICLDLL): $(OBJS) $(RUBYLIB)
75
+ $(LD) $(LDFLAGS) -Tpd $? c0d32.obj, $(DLL), , $(LIBS),
76
+
77
+ .PHONY: clean
78
+ clean:
79
+ rm -f *~ *.obj *.lib *.tds *.map *.ilc *.ild *.ilf *.ils
data/ext/sicl.c CHANGED
@@ -8,7 +8,18 @@
8
8
  *
9
9
  */
10
10
 
11
- #define _REENT_ONLY
11
+ #if defined(__BORLANDC__)
12
+ # define _MSC_VER 1200
13
+ # include <windows.h>
14
+ #endif /* __BORLANDC__ */
15
+
16
+ #if defined(__CYGWIN__)
17
+ # define _REENT_ONLY
18
+ #endif /* __CYGWIN__ */
19
+
20
+ #if defined(__BORLANDC__)
21
+ __declspec(dllexport) BOOL __stdcall DllMain(HANDLE h, DWORD w, LPVOID p) { return TRUE; }
22
+ #endif /* __BORLANDC__ */
12
23
 
13
24
  #include <ruby.h>
14
25
  #include "sicl.h"
@@ -37,6 +48,7 @@ static ID s_call;
37
48
  static ID s_buf_mode;
38
49
 
39
50
  static const VALUE READ_ALL_DATA = INT2FIX(-1);
51
+ static const char EOL[] = "\r\n";
40
52
 
41
53
  /* -----------------------------------------------------------------------
42
54
  struct cparse_params
@@ -123,25 +135,29 @@ static void SICLCALLBACK intr_handler ( INST id, long reason, long secval )
123
135
  rb_funcall ( hdlr, s_call, 2, INT2FIX(reason), INT2FIX(secval) );
124
136
  }
125
137
 
126
- VALUE sicl_igeterrstr ( int argc, VALUE * argv, VALUE self )
138
+ VALUE sicl_s_igeterrstr ( VALUE self, VALUE code )
127
139
  {
128
- VALUE code = 0;
140
+ Check_Type ( code, T_FIXNUM );
129
141
 
130
- rb_scan_args ( argc, argv, "01", & code );
142
+ return rb_str_new2 ( igeterrstr ( FIX2INT ( code ) ) );
143
+ }
131
144
 
132
- if ( TYPE(code)!=T_FIXNUM ) {
133
- struct instrument * inst = NULL;
145
+ VALUE sicl_igeterrstr ( VALUE self )
146
+ {
147
+ struct instrument * inst = NULL;
134
148
 
135
- Data_Get_Struct ( self, struct instrument, inst );
149
+ Data_Get_Struct ( self, struct instrument, inst );
136
150
 
137
- if ( ! inst->errno ) return Qnil;
151
+ return rb_str_new2 ( igeterrstr ( inst->errno ) );
152
+ }
138
153
 
139
- code = INT2FIX ( inst->errno );
140
- }
154
+ VALUE sicl_igeterrno ( VALUE self )
155
+ {
156
+ struct instrument * inst = NULL;
141
157
 
142
- if ( NIL_P(code) ) return code;
158
+ Data_Get_Struct ( self, struct instrument, inst );
143
159
 
144
- return rb_str_new2 ( igeterrstr ( FIX2INT ( code ) ) );
160
+ return INT2FIX(inst->errno);
145
161
  }
146
162
 
147
163
  VALUE sicl_ionerror ( VALUE self, VALUE proc )
@@ -366,7 +382,7 @@ VALUE sicl_iwrite ( VALUE self, VALUE cmd, VALUE eoi )
366
382
  char * ptr = NULL;
367
383
  long len = 0;
368
384
 
369
- int ( * write )( INST, char *, unsigned long, int, unsigned long * ) = iwrite;
385
+ int ( * write_func )( INST, char *, unsigned long, int, unsigned long * ) = iwrite;
370
386
 
371
387
  Check_Type ( cmd, T_STRING );
372
388
 
@@ -377,10 +393,10 @@ VALUE sicl_iwrite ( VALUE self, VALUE cmd, VALUE eoi )
377
393
  ptr = RSTRING(cmd)->ptr;
378
394
  len = RSTRING(cmd)->len;
379
395
 
380
- if ( rb_ivar_get( self, s_buf_mode )==Qtrue ) write = ifwrite;
396
+ if ( rb_ivar_get( self, s_buf_mode )==Qtrue ) write_func = ifwrite;
381
397
 
382
398
  while ( len>0 ) {
383
- err = write ( inst->id, ptr, len, endi, & actualcnt );
399
+ err = write_func ( inst->id, ptr, len, endi, & actualcnt );
384
400
 
385
401
  if ( err ) break;
386
402
 
@@ -391,6 +407,20 @@ VALUE sicl_iwrite ( VALUE self, VALUE cmd, VALUE eoi )
391
407
  return sicl_return ( self, inst, err );
392
408
  }
393
409
 
410
+ VALUE sicl_iwrite_op ( VALUE self, VALUE cmd )
411
+ {
412
+ VALUE eoi = Qfalse;
413
+ char ch = 0;
414
+
415
+ Check_Type ( cmd, T_STRING );
416
+
417
+ ch = RSTRING(cmd)->ptr[RSTRING(cmd)->len-1];
418
+
419
+ if ( ch == '\r' || ch == '\n' ) eoi = Qtrue;
420
+
421
+ return sicl_iwrite ( self, cmd, eoi );
422
+ }
423
+
394
424
  VALUE sicl_iwrite_arg ( int argc, VALUE * argv, VALUE self )
395
425
  {
396
426
  VALUE cmd = 0;
@@ -411,7 +441,7 @@ VALUE sicl_iread ( VALUE self, VALUE max )
411
441
  int reason = 0;
412
442
  unsigned long actualcnt = 0;
413
443
 
414
- int ( * read )( INST, char *, unsigned long, int *, unsigned long *) = iread;
444
+ int ( * read_func )( INST, char *, unsigned long, int *, unsigned long *) = iread;
415
445
 
416
446
  VALUE str = rb_str_new2 ("");
417
447
 
@@ -421,14 +451,14 @@ VALUE sicl_iread ( VALUE self, VALUE max )
421
451
 
422
452
  Data_Get_Struct ( self, struct instrument, inst );
423
453
 
424
- if ( rb_ivar_get( self, s_buf_mode )==Qtrue ) read = ifread;
454
+ if ( rb_ivar_get( self, s_buf_mode )==Qtrue ) read_func = ifread;
425
455
 
426
456
  for (;;) {
427
457
  if ( len==0 ) break;
428
458
 
429
459
  if ( 0<len && len<size ) size = len;
430
460
 
431
- err = read ( inst->id, buf, size, & reason, & actualcnt );
461
+ err = read_func( inst->id, buf, size, & reason, & actualcnt );
432
462
 
433
463
  if ( err && err!=I_ERR_TIMEOUT ) break;
434
464
 
@@ -474,7 +504,7 @@ VALUE sicl_output ( VALUE self, VALUE cmd )
474
504
  tmp = rb_funcall ( cmd, s_gsub, 2, reg1, blnk );
475
505
  cmd = rb_funcall ( tmp, s_gsub, 2, reg2, blnk );
476
506
 
477
- rb_str_cat2 ( cmd, "\r\n" );
507
+ rb_str_cat2 ( cmd, EOL );
478
508
 
479
509
  self = sicl_iwrite ( self, cmd, eoi );
480
510
 
@@ -636,12 +666,16 @@ VALUE sicl_itrigger ( VALUE self ) { sicl_func ( self, itrigger ); }
636
666
  /* -----------------------------------------------------------------------
637
667
  Ruby Interface
638
668
  ----------------------------------------------------------------------- */
639
-
640
- void Init_sicl ()
669
+ #if defined(__BORLANDC__)
670
+ __declspec(dllexport) void __stdcall Init_sicl()
671
+ #else /* __BORLANDC__ */
672
+ void Init_sicl()
673
+ #endif /* __BORLANDC__ */
641
674
  {
642
675
  mSicl = rb_define_module ( "SICL" );
643
676
 
644
677
  rb_define_module_function( mSicl, "open", sicl_s_iopen, 1 );
678
+ rb_define_module_function( mSicl, "errstr", sicl_s_igeterrstr, 1 );
645
679
 
646
680
  rb_define_const ( mSicl, "BUF_READ" , INT2FIX(I_BUF_READ) );
647
681
  rb_define_const ( mSicl, "BUF_WRITE" , INT2FIX(I_BUF_WRITE) );
@@ -649,6 +683,8 @@ void Init_sicl ()
649
683
  rb_define_const ( mSicl, "BUF_DISCARD_READ" , INT2FIX(I_BUF_DISCARD_READ) );
650
684
  rb_define_const ( mSicl, "BUF_DISCARD_WRITE", INT2FIX(I_BUF_DISCARD_WRITE) );
651
685
 
686
+ rb_define_const ( mSicl, "EOL", rb_str_new2(EOL) );
687
+
652
688
  eSicl = rb_define_class_under ( mSicl, "Error", rb_eStandardError );
653
689
 
654
690
  ionerror ( err_handler );
@@ -671,23 +707,24 @@ void Init_sicl ()
671
707
  rb_define_method ( cInstrument, "initialize" , sicl_initialize, 1 );
672
708
  rb_define_method ( cInstrument, "close" , sicl_iclose , 0 );
673
709
  rb_define_method ( cInstrument, "write" , sicl_iwrite_arg, -1 );
710
+ rb_define_method ( cInstrument, "<<" , sicl_iwrite_op, 1 );
674
711
  rb_define_method ( cInstrument, "read" , sicl_iread_arg , -1 );
712
+ rb_define_method ( cInstrument, "readstb" , sicl_ireadstb , 0 );
675
713
  rb_define_method ( cInstrument, "spoll" , sicl_ireadstb , 0 );
676
714
  rb_define_method ( cInstrument, "flush" , sicl_iflush , -1 );
677
715
 
678
- rb_define_method ( cInstrument, "timeout=", sicl_itimeout , 1 );
679
- rb_define_method ( cInstrument, "timeout" , sicl_igettimeout, 0 );
680
- rb_define_method ( cInstrument, "termchr=", sicl_itermchr , 1 );
681
- rb_define_method ( cInstrument, "termchr" , sicl_igettermchr, 0 );
682
- rb_define_method ( cInstrument, "addr" , sicl_igetaddr , 0 );
683
- rb_define_method ( cInstrument, "address" , sicl_igetaddr , 0 );
684
- rb_define_method ( cInstrument, "errstr" , sicl_igeterrstr , -1 );
716
+ rb_define_method ( cInstrument, "timeout=", sicl_itimeout , 1 );
717
+ rb_define_method ( cInstrument, "timeout" , sicl_igettimeout, 0 );
718
+ rb_define_method ( cInstrument, "termchr=", sicl_itermchr , 1 );
719
+ rb_define_method ( cInstrument, "termchr" , sicl_igettermchr, 0 );
720
+ rb_define_method ( cInstrument, "addr" , sicl_igetaddr , 0 );
721
+ rb_define_method ( cInstrument, "address" , sicl_igetaddr , 0 );
722
+ rb_define_method ( cInstrument, "errstr" , sicl_igeterrstr , 0 );
723
+ rb_define_method ( cInstrument, "errno" , sicl_igeterrno , 0 );
685
724
 
686
725
  rb_define_method ( cInstrument, "output" , sicl_output, 1 );
687
726
  rb_define_method ( cInstrument, "enter" , sicl_enter , 0 );
688
727
  rb_define_method ( cInstrument, "query" , sicl_query , 1 );
689
- rb_define_method ( cInstrument, "<<" , sicl_output, 1 );
690
- rb_define_method ( cInstrument, ">>" , sicl_enter2, 1 );
691
728
 
692
729
  rb_define_method ( cInstrument, "abort" , sicl_iabort , 0 );
693
730
  rb_define_method ( cInstrument, "clear" , sicl_iclear , 0 );
@@ -701,8 +738,10 @@ void Init_sicl ()
701
738
  rb_define_method ( cInstrument, "on_error" , sicl_igetonerror, 0 );
702
739
  rb_define_method ( cInstrument, "on_srq=" , sicl_ionsrq , 1 );
703
740
  rb_define_method ( cInstrument, "on_srq" , sicl_igetonsrq , 0 );
704
- rb_define_method ( cInstrument, "on_intrrupt=" , sicl_ionintr , 1 );
705
- rb_define_method ( cInstrument, "on_intrrupt" , sicl_igetonintr , 0 );
741
+ rb_define_method ( cInstrument, "on_intr=" , sicl_ionintr , 1 );
742
+ rb_define_method ( cInstrument, "on_intr" , sicl_igetonintr , 0 );
743
+ rb_define_method ( cInstrument, "on_interrupt=" , sicl_ionintr , 1 );
744
+ rb_define_method ( cInstrument, "on_interrupt" , sicl_igetonintr , 0 );
706
745
 
707
746
  /* accessor for @buf_mode */
708
747
  rb_define_method ( cInstrument, "buf_mode=", sicl_set_buf_mode, 1 );
data/test/test_sicl.rb CHANGED
@@ -10,6 +10,8 @@
10
10
  #
11
11
  ################################################################################
12
12
 
13
+ Signal.trap(:USR2) {} if RUBY_PLATFORM =~ /hpux/ # workaround ...;|
14
+
13
15
  ################################################################################
14
16
  # OPTION SETTINGS
15
17
  ################################################################################
@@ -19,6 +21,7 @@ require "optparse"
19
21
  Settings = Hash.new
20
22
  opts = OptionParser.new
21
23
  opts.on( "-a", "--address ADDRESS", String ) { |v| Settings[:address] = v }
24
+ opts.on( "-d", "--debug", String ) { |v| Settings[:debug] = true }
22
25
  opts.parse!( ARGV )
23
26
 
24
27
  ################################################################################
@@ -40,7 +43,8 @@ class TestSicl < RUNIT::TestCase
40
43
 
41
44
  def TestSicl.suite(address)
42
45
  @@address = address
43
- @@idn_str = SICL.open(@@address).query("*idn?")
46
+ SICL.open(@@address) { |io| @@name = io.query("*IDN?") }
47
+ puts "#{@@address} : #{@@name}" if Settings[:debug]
44
48
  super()
45
49
  end
46
50
 
@@ -50,18 +54,22 @@ class TestSicl < RUNIT::TestCase
50
54
  super(addr)
51
55
 
52
56
  reset
53
- enable_srq_detection
54
57
  end
55
58
 
56
59
  def reset
57
- output "*cls"
58
- output "*rst"
59
- query "*esr?"
60
+ output "*CLS"
61
+ output "*RST"
62
+ query "*ESR?"
60
63
  end
61
64
 
62
65
  def enable_srq_detection
63
- output "*sre #{0x20}"
64
- output "*ese #{0x3c}"
66
+ output "*SRE #{0x20}"
67
+ output "*ESE #{0x3c}"
68
+ end
69
+
70
+ def disable_srq_detection
71
+ output "*SRE #{0x00}"
72
+ output "*ESE #{0x00}"
65
73
  end
66
74
 
67
75
  def raise_timeout(timeout=1000)
@@ -85,19 +93,23 @@ class TestSicl < RUNIT::TestCase
85
93
  RQS_BIT = 6 # ReQuest Service
86
94
 
87
95
  def setup
88
- @exp = {}
89
- @exp[:str] = @@idn_str
90
- @exp[:chr] = @exp[:str][0].chr
91
- @exp[:rgx] = /^#{@exp[:str]}/
92
-
93
- @inst = MyInstrument.new @@address
96
+ @io = MyInstrument.new @@address
97
+ @name = @@name
94
98
  end
95
99
 
96
100
  def teardown
97
101
 
98
102
  begin
99
- @inst.on_error = nil
100
- @inst.on_srq = nil
103
+ if Settings[:debug] then
104
+ @io.on_error { |err| puts "[ERR: #{err}]" }
105
+ @io.on_srq { puts "[SRQ]" }
106
+ @io.on_intr { |reason, secval| puts "[INTR: #{reason}, #{secval}]" }
107
+ else
108
+ @io.on_error = nil
109
+ @io.on_srq = nil
110
+ @io.on_intr = nil
111
+ end
112
+ @io.disable_srq_detection
101
113
  rescue
102
114
  # do nothing...
103
115
  end
@@ -107,14 +119,14 @@ class TestSicl < RUNIT::TestCase
107
119
  def test_open0
108
120
  ret = SICL.open(@@address) { |io|
109
121
 
110
- res = io.write("*idn?\n").read
111
- assert_match @exp[:rgx], res
122
+ res = io.write("*IDN?\n").read.chomp
123
+ assert_equal @name, res
112
124
 
113
- res = io.output("*idn?").enter
114
- assert_match @exp[:rgx], res
125
+ res = io.output("*IDN?").enter
126
+ assert_equal @name, res
115
127
 
116
- res = io.query("*idn?")
117
- assert_match @exp[:rgx], res
128
+ res = io.query("*IDN?")
129
+ assert_equal @name, res
118
130
 
119
131
  io.address
120
132
  }
@@ -129,53 +141,73 @@ class TestSicl < RUNIT::TestCase
129
141
  end
130
142
 
131
143
  def test_stb0
132
- @inst.output("*sre #{0x00}")
133
- @inst.output("*ese #{0x00}")
144
+ @io.output("*SRE #{0x00}")
145
+ @io.output("*ESE #{0x00}")
134
146
 
135
- rqs = @inst.query("*stb?").to_i[RQS_BIT]
147
+ rqs = @io.query("*STB?").to_i[RQS_BIT]
136
148
  assert_equal 0, rqs
137
149
  end
138
150
 
139
151
  def test_stb1
140
- @inst.output("xxx")
152
+ @io.enable_srq_detection
153
+
154
+ @io.output("xxx")
141
155
 
142
156
  sleep 0.1
143
157
 
144
- stb = @inst.query("*stb?").to_i
158
+ stb = @io.query("*STB?").to_i
145
159
 
146
160
  assert_equal 1, stb[ESR_BIT]
147
161
  assert_equal 1, stb[RQS_BIT]
148
162
  end
149
163
 
150
164
  def test_stb2
151
- @inst.output("xxx")
165
+ @io.enable_srq_detection
166
+
167
+ @io.output("xxx")
152
168
 
153
169
  sleep 1
154
170
 
155
- stb = @inst.spoll
171
+ stb = @io.spoll
156
172
 
157
173
  assert_equal 1, stb[ESR_BIT]
158
174
  assert_equal 1, stb[RQS_BIT]
159
175
  end
160
176
 
177
+ def test_typerr_error
178
+ assert_exception(TypeError) { @io.on_error = "xxx" }
179
+ end
180
+
181
+ def test_typerr_srq
182
+ assert_exception(TypeError) { @io.on_srq = "xxx" }
183
+ end
184
+
185
+ def test_typerr_intr
186
+ assert_exception(TypeError) { @io.on_intr = "xxx" }
187
+ end
188
+
161
189
  def test_srq0
190
+ @io.enable_srq_detection
191
+
162
192
  srq_occured = false
163
193
 
164
- @inst.on_srq { srq_occured = true }
194
+ @io.on_srq { srq_occured = true }
165
195
 
166
- @inst.output("xxx")
196
+ @io.output("xxx")
167
197
 
168
- 10.times { sleep 0.1 until srq_occured }
198
+ 10.times { sleep 0.1 unless srq_occured }
169
199
 
170
200
  assert_equal true, srq_occured
171
201
  end
172
202
 
173
203
  def test_srq1
204
+ @io.enable_srq_detection
205
+
174
206
  stb = 0
175
207
 
176
- @inst.on_srq { sleep 1; stb = @inst.spoll }
208
+ @io.on_srq { sleep 1; stb = @io.spoll }
177
209
 
178
- @inst.output("xxx")
210
+ @io.output("xxx")
179
211
 
180
212
  10.times { sleep 0.1 if stb == 0 }
181
213
 
@@ -183,68 +215,92 @@ class TestSicl < RUNIT::TestCase
183
215
  assert_equal 1, stb[RQS_BIT]
184
216
  end
185
217
 
218
+ def test_typerr_write
219
+ assert_exception(TypeError) { @io.write(10) }
220
+ end
221
+
222
+ def test_typerr_write_op
223
+ assert_exception(TypeError) { @io << 10 }
224
+ end
225
+
226
+ def test_typerr_read
227
+ assert_exception(TypeError) { @io.read("xxx") }
228
+ end
229
+
230
+ def test_typerr_output
231
+ assert_exception(TypeError) { @io.output(10) }
232
+ end
233
+
186
234
  def test_write_and_read0
187
- res = @inst.write("*idn?\n")
235
+ res = @io.write("*IDN?\n")
188
236
  assert res
189
237
 
190
- res = @inst.read 1
191
- assert_equal @exp[:chr], res
238
+ res = @io.read 1
239
+ assert_equal @name[0].chr, res
192
240
  end
241
+
193
242
  def test_write_and_read1
194
- res = @inst.write("*idn?\n").read 1
195
- assert_equal @exp[:chr], res
243
+ res = @io.write("*IDN?\n").read 1
244
+ assert_equal @name[0].chr, res
196
245
  end
246
+
197
247
  def test_write_and_read2
198
- res = @inst.write("*idn?\n").read 7
199
- assert_equal @exp[:str][0...7], res
248
+ res = @io.write("*IDN?\n").read 7
249
+ assert_equal @name[0...7], res
200
250
  end
251
+
201
252
  def test_write_and_read3
202
- res = @inst.write("*i").write("dn").write("?\n").read 1
203
- assert_equal @exp[:chr], res
253
+ res = @io.write("*I").write("DN").write("?\n").read 1
254
+ assert_equal @name[0].chr, res
255
+ end
256
+
257
+ def test_write_and_read4
258
+ @io << "*I" << "DN" << "?" << SICL::EOL
259
+ res = @io.read 1
260
+ assert_equal @name[0].chr, res
261
+ end
262
+
263
+ def test_write_and_read5
264
+ @io << "*RST" << SICL::EOL << "*IDN?" << SICL::EOL
265
+ res = @io.read 1
266
+ assert_equal @name[0].chr, res
204
267
  end
205
268
 
206
269
  def test_output_and_enter0
207
- res = @inst.output("*idn?")
270
+ res = @io.output("*IDN?")
208
271
  assert res
209
- res = @inst.enter
210
- assert_match @exp[:rgx], res
272
+ res = @io.enter
273
+ assert_equal @name, res
211
274
  end
212
275
 
213
276
  def test_output_and_enter1
214
- res = @inst.output("*idn?").enter
215
- assert_match @exp[:rgx], res
277
+ res = @io.output("*IDN?").enter
278
+ assert_equal @name, res
216
279
  end
217
280
 
218
281
  def test_output_and_enter2
219
- res = @inst.output("*idn?\r\n \r\r\r\r;;\n;;\r\n\n").enter
220
- assert_match @exp[:rgx], res
221
- end
222
-
223
- def test_output_and_enter3
224
- @inst << "*idn?"
225
- res = "" # @inst.enter
226
- @inst >> res
227
- assert_match @exp[:rgx], res
282
+ res = @io.output("*IDN?\r\n \r\r\r\r;;\n;;\r\n\n").enter
283
+ assert_equal @name, res
228
284
  end
229
285
 
230
286
  def test_error_message0
231
- assert_equal NO_ERROR, @inst.errstr(0)
287
+ assert_equal NO_ERROR, SICL.errstr(0)
232
288
  end
233
289
 
234
290
  def test_error_message1
235
- assert @inst.errstr(15)
291
+ assert SICL.errstr(15)
236
292
  end
237
293
 
238
294
  def test_error_message2
239
- assert_equal nil, @inst.errstr
295
+ assert_equal NO_ERROR, @io.errstr
240
296
  end
241
297
 
242
298
  def test_error_message3
243
299
  error_message = ''
244
300
 
245
- @inst.on_error { |err| error_message = err[1] }
301
+ @io.on_error { |err| error_message = err[1] }
246
302
 
247
- @inst.raise_timeout
303
+ @io.raise_timeout
248
304
 
249
305
  assert_equal TIMEOUT_OCCURRED, error_message
250
306
  end
@@ -252,23 +308,33 @@ class TestSicl < RUNIT::TestCase
252
308
  def test_error_message4
253
309
  error_message = ''
254
310
 
255
- @inst.on_error { |num, msg| error_message = msg }
311
+ @io.on_error {}
256
312
 
257
- @inst.raise_timeout
313
+ @io.raise_timeout
314
+
315
+ assert_equal TIMEOUT_OCCURRED, @io.errstr
316
+ end
317
+
318
+ def test_error_message5
319
+ error_message = ''
320
+
321
+ @io.on_error { |num, msg| error_message = msg }
322
+
323
+ @io.raise_timeout
258
324
 
259
325
  assert_equal TIMEOUT_OCCURRED, error_message
260
326
  end
261
327
 
262
328
  def test_error_close0
263
- @inst.close
264
- err = assert_exception(SICL::Error) { @inst.close }
329
+ @io.close
330
+ err = assert_exception(SICL::Error) { @io.close }
265
331
 
266
332
  assert_equal INVALID_INST, err.message
267
333
  end
268
334
 
269
335
  def test_error_close1
270
- @inst.close
271
- err = assert_exception(SICL::Error) { @inst.close }
336
+ @io.close
337
+ err = assert_exception(SICL::Error) { @io.close }
272
338
 
273
339
  assert_equal INVALID_INST, err.message
274
340
  end
@@ -276,90 +342,102 @@ class TestSicl < RUNIT::TestCase
276
342
  def test_error_timeout0
277
343
  time_limit = 10000
278
344
 
279
- @inst.timeout = time_limit
345
+ @io.timeout = time_limit
280
346
 
281
- assert_equal time_limit, @inst.timeout
347
+ assert_equal time_limit, @io.timeout
282
348
  end
283
349
 
284
350
  def test_error_timeout1
285
351
  err = assert_exception(SICL::Error) {
286
- @inst.raise_timeout
352
+ @io.raise_timeout
287
353
  }
288
354
 
289
355
  assert_equal TIMEOUT_OCCURRED, err.message
290
356
  end
291
357
 
292
358
  def test_error_timeout2
293
- @inst.on_error = lambda {}
359
+ @io.on_error = lambda {}
294
360
 
295
- @inst.raise_timeout
361
+ @io.raise_timeout
296
362
 
297
363
  assert true
298
364
  end
299
365
 
300
366
  def test_error_timeout3
301
- @inst.on_error = lambda {}
302
- @inst.on_error = nil
367
+ @io.on_error = lambda {}
368
+ @io.on_error = nil
303
369
 
304
370
  err = assert_exception(SICL::Error) {
305
- @inst.raise_timeout
371
+ @io.raise_timeout
306
372
  }
307
373
 
308
374
  assert_equal TIMEOUT_OCCURRED, err.message
309
375
  end
310
376
 
311
377
  def test_error_timeout4
312
- @inst.on_error {}
378
+ @io.on_error {}
313
379
 
314
- @inst.raise_timeout
380
+ @io.raise_timeout
315
381
 
316
382
  assert true
317
383
  end
318
384
 
385
+ def test_close
386
+ assert @io.close
387
+ end
388
+
319
389
  def test_abort
320
- assert @inst.abort if @@address =~ /^[gh]pib/ # gpib only
390
+ assert @io.abort.instance_of?(@io.class) if @@address =~ /^[gh]pib/
321
391
  end
322
392
 
323
393
  def test_clear
324
- assert @inst.clear
394
+ assert @io.clear.instance_of?(@io.class)
325
395
  end
326
396
 
327
397
  def test_spoll
328
- assert @inst.spoll
398
+ assert @io.spoll.instance_of?(Fixnum)
399
+ end
400
+
401
+ def test_readstb
402
+ assert @io.readstb.instance_of?(Fixnum)
329
403
  end
330
404
 
331
405
  def test_local
332
- assert @inst.local
406
+ assert @io.local.instance_of?(@io.class)
333
407
  end
334
408
 
335
409
  def test_remote
336
- assert @inst.remote
410
+ assert @io.remote.instance_of?(@io.class)
337
411
  end
338
412
 
339
413
  def test_flush0
340
- assert @inst.flush
414
+ assert @io.flush.instance_of?(@io.class)
341
415
  end
342
416
 
343
417
  def test_flush1
344
- assert @inst.flush(SICL::BUF_DISCARD_READ | SICL::BUF_DISCARD_WRITE)
418
+ assert @io.flush(SICL::BUF_DISCARD_READ | SICL::BUF_DISCARD_WRITE)
345
419
  end
346
420
 
347
421
  def test_addr
348
- assert_equal @inst.addr, @@address
422
+ assert_equal @io.addr, @@address
349
423
  end
350
424
 
351
425
  def test_addr
352
- assert_equal @inst.address, @@address
426
+ assert_equal @io.address, @@address
427
+ end
428
+
429
+ def test_typerr_termchr
430
+ assert_exception(TypeError) { @io.termchr = " " }
353
431
  end
354
432
 
355
433
  def test_termchr0
356
- assert @inst.termchr = 0x20
357
- assert_equal @inst.termchr, 0x20
434
+ assert @io.termchr = 0x20
435
+ assert_equal @io.termchr, 0x20
358
436
  end
359
437
 
360
438
  def test_termchr1
361
- assert @inst.termchr = " "[0]
362
- assert_equal @inst.termchr, 0x20
439
+ assert @io.termchr = " "[0]
440
+ assert_equal @io.termchr, 0x20
363
441
  end
364
442
 
365
443
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.3
3
3
  specification_version: 1
4
4
  name: sicl
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2007-05-13 00:00:00 +09:00
8
- summary: Agilent SICL API module for Ruby.
6
+ version: 0.2.0
7
+ date: 2007-05-18 00:00:00 +09:00
8
+ summary: Agilent SICL API wrapper class for Ruby.
9
9
  require_paths:
10
10
  - lib
11
11
  email:
@@ -35,6 +35,7 @@ files:
35
35
  - Rakefile
36
36
  - ext/sicl.c
37
37
  - ext/extconf.rb
38
+ - ext/Makefile.bcc
38
39
  - test/test_sicl.rb
39
40
  test_files: []
40
41