phidgets 0.1.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +3 -0
  3. data/README.rdoc +32 -43
  4. data/Rakefile +4 -2
  5. data/bin/phidget +18 -72
  6. data/ext/phidgets/extconf.rb +5 -8
  7. data/ext/phidgets/phidgets.c +708 -173
  8. data/ext/phidgets/phidgets.h +54 -35
  9. data/ext/phidgets/phidgets_accelerometer.c +193 -109
  10. data/ext/phidgets/phidgets_bldc_motor.c +529 -0
  11. data/ext/phidgets/phidgets_capacitive_touch.c +302 -0
  12. data/ext/phidgets/phidgets_common.c +570 -315
  13. data/ext/phidgets/phidgets_current_input.c +229 -0
  14. data/ext/phidgets/phidgets_dc_motor.c +562 -0
  15. data/ext/phidgets/phidgets_dictionary.c +154 -213
  16. data/ext/phidgets/phidgets_digital_input.c +127 -0
  17. data/ext/phidgets/phidgets_digital_output.c +288 -0
  18. data/ext/phidgets/phidgets_distance_sensor.c +295 -0
  19. data/ext/phidgets/phidgets_encoder.c +211 -192
  20. data/ext/phidgets/phidgets_frequency_counter.c +310 -177
  21. data/ext/phidgets/phidgets_gps.c +226 -164
  22. data/ext/phidgets/phidgets_gyroscope.c +195 -0
  23. data/ext/phidgets/phidgets_hub.c +39 -0
  24. data/ext/phidgets/phidgets_humidity_sensor.c +200 -0
  25. data/ext/phidgets/phidgets_ir.c +211 -171
  26. data/ext/phidgets/phidgets_lcd.c +512 -0
  27. data/ext/phidgets/phidgets_light_sensor.c +200 -0
  28. data/ext/phidgets/phidgets_log.c +263 -0
  29. data/ext/phidgets/phidgets_magnetometer.c +279 -0
  30. data/ext/phidgets/phidgets_manager.c +86 -297
  31. data/ext/phidgets/phidgets_motor_position_controller.c +787 -0
  32. data/ext/phidgets/phidgets_phsensor.c +200 -152
  33. data/ext/phidgets/phidgets_power_guard.c +144 -0
  34. data/ext/phidgets/phidgets_pressure_sensor.c +200 -0
  35. data/ext/phidgets/phidgets_rc_servo.c +672 -0
  36. data/ext/phidgets/phidgets_resistance_input.c +227 -0
  37. data/ext/phidgets/phidgets_rfid.c +107 -221
  38. data/ext/phidgets/phidgets_sound_sensor.c +284 -0
  39. data/ext/phidgets/phidgets_spatial.c +124 -318
  40. data/ext/phidgets/phidgets_stepper.c +457 -430
  41. data/ext/phidgets/phidgets_temp_sensor.c +223 -228
  42. data/ext/phidgets/phidgets_voltage_input.c +428 -0
  43. data/ext/phidgets/phidgets_voltage_output.c +167 -0
  44. data/ext/phidgets/phidgets_voltage_ratio_input.c +435 -0
  45. data/lib/phidgets.rb +21 -14
  46. data/lib/phidgets/accelerometer.rb +11 -15
  47. data/lib/phidgets/bldc_motor.rb +45 -0
  48. data/lib/phidgets/capacitive_touch.rb +33 -0
  49. data/lib/phidgets/common.rb +40 -69
  50. data/lib/phidgets/current_input.rb +21 -0
  51. data/lib/phidgets/dc_motor.rb +45 -0
  52. data/lib/phidgets/dictionary.rb +30 -39
  53. data/lib/phidgets/digital_input.rb +21 -0
  54. data/lib/phidgets/digital_output.rb +56 -0
  55. data/lib/phidgets/distance_sensor.rb +33 -0
  56. data/lib/phidgets/encoder.rb +1 -29
  57. data/lib/phidgets/frequency_counter.rb +23 -14
  58. data/lib/phidgets/gps.rb +34 -26
  59. data/lib/phidgets/gyroscope.rb +21 -0
  60. data/lib/phidgets/humidity_sensor.rb +21 -0
  61. data/lib/phidgets/ir.rb +34 -39
  62. data/lib/phidgets/light_sensor.rb +21 -0
  63. data/lib/phidgets/magnetometer.rb +21 -0
  64. data/lib/phidgets/manager.rb +18 -66
  65. data/lib/phidgets/motor_position_controller.rb +45 -0
  66. data/lib/phidgets/ph_sensor.rb +2 -6
  67. data/lib/phidgets/pressure_sensor.rb +21 -0
  68. data/lib/phidgets/rc_servo.rb +58 -0
  69. data/lib/phidgets/resistance_input.rb +21 -0
  70. data/lib/phidgets/rfid.rb +22 -38
  71. data/lib/phidgets/sound_sensor.rb +21 -0
  72. data/lib/phidgets/spatial.rb +11 -15
  73. data/lib/phidgets/stepper.rb +48 -50
  74. data/lib/phidgets/temperature_sensor.rb +11 -15
  75. data/lib/phidgets/version.rb +5 -0
  76. data/lib/phidgets/voltage_input.rb +34 -0
  77. data/lib/phidgets/voltage_output.rb +23 -0
  78. data/lib/phidgets/voltage_ratio_input.rb +34 -0
  79. data/phidgets.gemspec +3 -22
  80. data/test/test_accelerometer.rb +42 -23
  81. data/test/test_bldc_motor.rb +134 -0
  82. data/test/test_capacitive_touch.rb +82 -0
  83. data/test/test_common.rb +125 -108
  84. data/test/test_current_input.rb +62 -0
  85. data/test/test_dc_motor.rb +146 -0
  86. data/test/test_dictionary.rb +22 -54
  87. data/test/test_digital_input.rb +30 -0
  88. data/test/test_digital_output.rb +70 -0
  89. data/test/test_distance_sensor.rb +76 -0
  90. data/test/test_encoder.rb +45 -38
  91. data/test/test_frequency_counter.rb +71 -36
  92. data/test/test_gps.rb +29 -38
  93. data/test/test_gyroscope.rb +54 -0
  94. data/test/test_helper.rb +0 -1
  95. data/test/test_hub.rb +14 -0
  96. data/test/test_humidity_sensor.rb +58 -0
  97. data/test/test_ir.rb +34 -34
  98. data/test/test_lcd.rb +146 -0
  99. data/test/test_light_sensor.rb +58 -0
  100. data/test/test_magnetometer.rb +78 -0
  101. data/test/test_manager.rb +10 -79
  102. data/test/test_motor_control.rb +146 -108
  103. data/test/test_phidgets.rb +2 -14
  104. data/test/test_phsensor.rb +46 -34
  105. data/test/test_power_guard.rb +42 -0
  106. data/test/test_pressure_sensor.rb +58 -0
  107. data/test/test_rc_servo.rb +174 -0
  108. data/test/test_resistance_input.rb +66 -0
  109. data/test/test_rfid.rb +15 -54
  110. data/test/test_sound_sensor.rb +78 -0
  111. data/test/test_spatial.rb +19 -85
  112. data/test/test_stepper.rb +89 -98
  113. data/test/test_temp_sensor.rb +42 -47
  114. data/test/test_voltage_input.rb +102 -0
  115. data/test/test_voltage_output.rb +46 -0
  116. data/test/test_voltage_ratio_input.rb +102 -0
  117. metadata +72 -89
  118. data/ext/phidgets/phidgets_advanced_servo.c +0 -567
  119. data/ext/phidgets/phidgets_analog.c +0 -139
  120. data/ext/phidgets/phidgets_bridge.c +0 -263
  121. data/ext/phidgets/phidgets_interface_kit.c +0 -340
  122. data/ext/phidgets/phidgets_led.c +0 -178
  123. data/ext/phidgets/phidgets_motor_control.c +0 -642
  124. data/ext/phidgets/phidgets_servo.c +0 -276
  125. data/ext/phidgets/phidgets_text_lcd.c +0 -381
  126. data/ext/phidgets/phidgets_text_led.c +0 -107
  127. data/ext/phidgets/phidgets_weight_sensor.c +0 -113
  128. data/lib/phidgets/advanced_servo.rb +0 -49
  129. data/lib/phidgets/analog.rb +0 -8
  130. data/lib/phidgets/bridge.rb +0 -25
  131. data/lib/phidgets/interfacekit.rb +0 -49
  132. data/lib/phidgets/led.rb +0 -8
  133. data/lib/phidgets/motor_control.rb +0 -110
  134. data/lib/phidgets/servo.rb +0 -23
  135. data/lib/phidgets/text_lcd.rb +0 -8
  136. data/lib/phidgets/text_led.rb +0 -8
  137. data/lib/phidgets/weight_sensor.rb +0 -25
  138. data/test/test_advanced_servo.rb +0 -152
  139. data/test/test_analog.rb +0 -45
  140. data/test/test_bridge.rb +0 -77
  141. data/test/test_interfacekit.rb +0 -97
  142. data/test/test_led.rb +0 -55
  143. data/test/test_servo.rb +0 -67
  144. data/test/test_text_lcd.rb +0 -115
  145. data/test/test_text_led.rb +0 -35
  146. data/test/test_weight_sensor.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3fd7bef7f559dc77c93de80a317dd43f97da07f
4
- data.tar.gz: 8a41b2c09ac0b90067b7f76d20aab7b2afb5bb1c
3
+ metadata.gz: 269e80f514a11868b488560279ac48490f96d6c0
4
+ data.tar.gz: 3d7f3f44df420ef0354e074db95d6641f9c86270
5
5
  SHA512:
6
- metadata.gz: 4b4500f256c1e668defc86a8f26c4eabb06758516f6bd3041b490ae5d1e6d13b64d7f6d75bde00f4139a0e5786eb1129171e1fa98cb67409d2669cade1dfaf49
7
- data.tar.gz: 3233b9dcb43665bdb02e0d8323c226de86965dd7a11484e19fa5c9e09162ccbb6bf187afe235025083e0d830d21af91322565d401914adc695d5c8cc0631998f
6
+ metadata.gz: 35b317744b09f8602b5250715721812bd9087a985ec88ea01f64af2ba2b7640e89611a5b07d07b39b56c8f660f9c9b3c9d7162934558c5f8b1d204e44c51b92c
7
+ data.tar.gz: 7495847c8447027b0cabf86f0970d861d997cf706a1888e0cf7d1a94dd1f13788e70448259ea78f786e6d660977de0bfe3fa99acd9f58884ddfc5e34ef954034
@@ -1,3 +1,6 @@
1
+ == 1.0.0 2019-xx-xx
2
+ * Update to phidgets library 2.2
3
+
1
4
  == 0.1.3 2015-11-10
2
5
  * Fix undefined symbol error in ruby version 2.2
3
6
 
@@ -9,27 +9,26 @@ This gem provides a ruby interface to the phidgets library.
9
9
 
10
10
  == FEATURES/PROBLEMS:
11
11
 
12
+ * Version 1.0 of this gem if for Phidget Lib 2.2. For the older Phidget Lib 2.1, use version 0.1.3 of the gem.
12
13
  * This gem compiles a c extension for the phidget library, so the library must be installed and the development files must be located
13
14
  in a place that the compiler can find them. For windows the DevKit is required.
14
15
  * The gem has been tested to work on both Linux and Windows.
15
- * Tested with Phidget Library version 2.1.8.20130618
16
- * Callbacks do not work on Ruby versions earlier than 1.9. This is because native threads are required for them to work.
17
- * Method names follow the naming convention of the C library (getOutputState, setOutputState, etc). In addition, more "rubyish" aliases are provided (output_state, set_output_state, etc)
16
+ * Tested with Phidget Library 2.2 Version 1.0.0
17
+ * Method names follow the naming convention of the C library (getState, setState, etc). In addition, more "rubyish" aliases are provided (state, state=, etc)
18
18
 
19
19
  == SYNOPSIS:
20
20
 
21
21
  require 'phidgets'
22
22
 
23
23
  begin
24
- ik = Phidgets::InterfaceKit.new
25
- ik.open -1
26
- ik.wait_for_attachment
24
+ di = Phidgets::DigitalInput.new
25
+ di.open_wait_for_attachment 500
27
26
 
28
- puts "Device Name = #{ik.device_name}"
29
- puts "Serial Number = #{ik.serial_number}"
30
- puts "Device Version = #{ik.device_version}"
27
+ puts "Device Name = #{di.device_name}"
28
+ puts "Serial Number = #{di.device_serial_number}"
29
+ puts "Device Version = #{di.device_version}"
31
30
 
32
- ik.close
31
+ di.close
33
32
 
34
33
  rescue Phidgets::Error => e
35
34
  puts e
@@ -38,45 +37,35 @@ This gem provides a ruby interface to the phidgets library.
38
37
 
39
38
  # Or using callbacks:
40
39
 
41
- ik = Phidgets::InterfaceKit.new
42
- ik.on_attach { |phid|
40
+ di = Phidgets::DigitalInput.new
41
+ di.on_attach { |phid|
43
42
  puts "Device Name = #{phid.device_name}"
44
- puts "Serial Number = #{phid.serial_number}"
43
+ puts "Serial Number = #{phid.device_serial_number}"
45
44
  puts "Device Version = #{phid.device_version}"
46
45
  }
47
46
 
48
- ik.open -1
49
- sleep 5
50
- ik.close
47
+ di.open
48
+ sleep 3
49
+ di.close
51
50
 
52
51
 
53
- # The gem also installs a command line program that will list all phidget devices that are attached, as well as allowing any
54
- # valid method for a given phidget type to be called. For example:
55
-
56
- # To list all phidgets attached to the local computer:
52
+ # The gem also installs a command line program that will list all phidget devices
53
+ # that are attached. For example:
57
54
 
58
- => phidget list
59
- ----------------------------------------------------------------------
60
- | SerialNumber | Device Name |
61
- ----------------------------------------------------------------------
62
- | 73723 | Phidget InterfaceKit 0/0/8 |
63
- | 88103 | Phidget InterfaceKit 0/0/4 |
64
- ----------------------------------------------------------------------
55
+ => phidget
56
+ ----------------------------------------------------------------------------
57
+ | SerialNumber | Class | Hub | Index |
58
+ ----------------------------------------------------------------------------
59
+ | 269819 | Voltage Input | 0 | 0 |
60
+ | 269819 | Voltage Input | 0 | 1 |
61
+ | 269819 | Voltage Ratio Input | 0 | 0 |
62
+ | 269819 | Voltage Ratio Input | 0 | 1 |
63
+ | 269819 | Digital Input | 0 | 0 |
64
+ | 269819 | Digital Input | 0 | 1 |
65
+ | 269819 | Digital Output | 0 | 0 |
66
+ | 269819 | Digital Output | 0 | 1 |
67
+ ----------------------------------------------------------------------------
65
68
 
66
- # To list all phidgets attached to a remote computer:
67
-
68
- => phidget 192.168.100.67 list
69
- ----------------------------------------------------------------------
70
- | SerialNumber | Device Name |
71
- ----------------------------------------------------------------------
72
- | 73782 | Phidget InterfaceKit 0/0/8 |
73
- ----------------------------------------------------------------------
74
-
75
- # To call a method for a specific local phidget:
76
- => phidget 73723 set_output_state 0 true
77
-
78
- # To call a method for a specific remote phidget:
79
- => phidget 192.168.100.67:73782 set_output_state 2 false
80
69
 
81
70
 
82
71
  == REQUIREMENTS:
@@ -85,8 +74,8 @@ This gem provides a ruby interface to the phidgets library.
85
74
  * For Windows the ruby DevKit is required
86
75
  * The development header file and library must be placed in a location where the compiler can find them.
87
76
  For Linux this should be done when running "make install" for the Phidget Library. For Windows the files
88
- need to be copied from the install directory (\\Program Files\\Phidgets). phidget21.h can be copied to
89
- RUBY_DIR\\include\\ruby-1.9.1. phidget21.lib can be copied to RUBY_DIR\\lib.
77
+ need to be copied from the install directory (\\Program Files\\Phidgets). phidget22.h can be copied to
78
+ RUBY_DIR\\include\\ruby-x.x.x. phidget22.lib can be copied to RUBY_DIR\\lib.
90
79
 
91
80
  == INSTALL:
92
81
 
data/Rakefile CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'rubygems'
4
4
  require 'rake/extensiontask'
5
5
  require 'rake/packagetask'
6
+ require 'rake/testtask'
6
7
  require 'rdoc/task'
7
8
 
8
9
  spec = Gem::Specification.load('phidgets.gemspec')
@@ -10,8 +11,10 @@ spec = Gem::Specification.load('phidgets.gemspec')
10
11
  Rake::ExtensionTask.new 'phidgets', spec
11
12
 
12
13
  Gem::PackageTask.new(spec) do |pkg|
13
-
14
+ end
14
15
 
16
+ Rake::TestTask.new do |task|
17
+ task.pattern = 'test/test_*.rb'
15
18
  end
16
19
 
17
20
  RDOC_FILES = FileList["README.rdoc", "ext/phidgets/*.c", "lib/phidgets/*.rb"]
@@ -28,4 +31,3 @@ Rake::RDocTask.new(:ri) do |rd|
28
31
  rd.options << "--ri-system"
29
32
  rd.rdoc_files.include(RDOC_FILES)
30
33
  end
31
-
@@ -1,84 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
4
3
  require 'phidgets'
5
4
 
6
- def usage
7
- $stdout.puts 'phidget [[host:]id] cmd [args]'
8
- $stdout.puts ' host = host name if connecting through web service'
9
- $stdout.puts ' id = serial # of phidget board (-1 for any)'
10
- $stdout.puts ' cmd = list | method'
11
- $stdout.puts ' args = arguments are dependent on the command'
12
- $stdout.puts
13
- $stdout.puts ' Examples:'
14
- $stdout.puts ' phidget list'
15
- $stdout.puts ' phidget -1 set_output_state 0 true'
16
- $stdout.puts ' phidget 34619 device_name'
17
- end
18
-
19
5
  begin
20
- args = {:port => 5001, :password => ''}
21
-
22
- case ARGV[0]
23
- when /^(-1|\d+)$/
24
- args[:serial_number] = $1.to_i
25
- when /^(\w|.+):(-1|\d+)$/
26
- args[:address] = $1
27
- args[:serial_number] = $2.to_i
28
- when /^list$/i
29
- args[:list] = true
30
- when /^(\w|.+)$/
31
- if ARGV[1].downcase == 'list'
32
- args[:list] = true
33
- args[:address] = $1
34
- else
35
- raise "Invalid Arguments."
36
- end
37
- else
38
- raise "Invalid Arguments."
39
- end
40
-
41
6
  manager = Phidgets::Manager.new
42
- manager.open(args)
43
-
44
- # give the manager some time to find the devices
45
- args[:address] ? sleep(2) : sleep(1)
46
-
47
- devices = manager.attached_devices
48
- manager.close
49
-
50
- if devices.size == 0
51
- $stdout.puts "\nThere are no phidgets attached.\n\n"
52
- exit
7
+ manager.on_attach do |phid, serial, hub_port, index, ch_name|
8
+ str = "| #{serial}"
9
+ str += ' ' * (18 - str.length)
10
+ str += "| #{ch_name}"
11
+ str += ' ' * (57 - str.length)
12
+ str += "| #{hub_port}"
13
+ str += ' ' * (66 - str.length)
14
+ str += "| #{index}"
15
+ str += ' ' * (75 - str.length) + '|'
16
+ $stdout.puts str
53
17
  end
54
-
55
- if args[:list]
56
- $stdout.puts "\n----------------------------------------------------------------------"
57
- $stdout.puts "| SerialNumber | Device Name |"
58
- $stdout.puts "----------------------------------------------------------------------"
59
- devices.each_pair { |serial,phidget|
60
- args[:serial_number] = serial
61
- phidget.open(args)
62
- phidget.wait_for_attachment(2000)
63
- d_str = "| #{serial}"
64
- d_str += " " * (24 - d_str.length) + "| #{phidget.device_name}"
65
- d_str += " " * (69 - d_str.length) + "|"
66
- $stdout.puts d_str
67
- phidget.close
68
- }
69
- $stdout.puts "----------------------------------------------------------------------\n"
18
+ $stdout.puts "\n----------------------------------------------------------------------------"
19
+ $stdout.puts "| SerialNumber | Class | Hub | Index |"
20
+ $stdout.puts "----------------------------------------------------------------------------"
21
+ manager.open
22
+ sleep 0.5
23
+ $stdout.puts "----------------------------------------------------------------------------\n"
24
+ manager.close
70
25
 
71
- else
72
- phidget = args[:serial_number] > 0 ? devices[args[:serial_number]] : devices.values[0]
73
- args[:serial_number] = devices.keys[0] unless args[:serial_number] > 0
74
- phidget.open(args)
75
- phidget.wait_for_attachment(2000)
76
- $stdout.puts eval("phidget.#{ARGV[1]}(#{ARGV[2..-1].join(',')})")
77
- phidget.close
78
- end
79
-
80
26
  rescue SystemExit
81
27
  rescue Exception => e
82
- $stdout.puts "#{e}\n#{e.backtrace.join("\n")}\n#{usage}\n"
28
+ $stdout.puts "#{e}\n#{e.backtrace.join("\n")}\n"
83
29
  end
84
30
 
@@ -1,18 +1,15 @@
1
1
  require 'mkmf'
2
2
 
3
- HEADER_DIRS = [ '/Library/Frameworks/Phidget21.framework/Headers' ]
3
+ HEADER_DIRS = [ '/Library/Frameworks/Phidget22.framework/Headers' ]
4
4
 
5
- find_header 'phidget21.h', *HEADER_DIRS
6
- find_library 'libphidget21', 'CPhidget_getLibraryVersion', '/usr/lib/'
7
- have_framework('Phidget21') unless RUBY_VERSION < '1.9.0'
8
- have_library('phidget21')
5
+ find_header 'phidget22.h', *HEADER_DIRS
6
+ find_library 'phidget22', 'Phidget_getLibraryVersion', '/usr/lib/'
7
+ have_framework('Phidget22')
8
+ have_library('phidget22')
9
9
  dir_config("phidgets")
10
10
 
11
11
  have_header('ruby/thread.h')
12
- have_func('rb_thread_blocking_region')
13
12
  have_func('rb_thread_call_without_gvl')
14
13
 
15
- $CFLAGS += ' -DPH_CALLBACK' unless RUBY_VERSION < '1.9.0'
16
-
17
14
  create_makefile("phidgets")
18
15
 
@@ -5,122 +5,326 @@
5
5
  #include <ruby/thread.h>
6
6
  #endif
7
7
 
8
- VALUE ph_errors[PHIDGET_ERROR_CODE_COUNT+1];
9
8
 
10
- VALUE ph_get_library_version(VALUE self);
11
- VALUE ph_enable_logging(VALUE self, VALUE level, VALUE output_file);
12
- VALUE ph_disable_logging(VALUE self);
13
- VALUE ph_log(VALUE self, VALUE level, VALUE msg_id, VALUE message);
14
9
 
10
+ VALUE ph_get_library_version(VALUE self) {
11
+ const char *lib_version;
12
+ ph_raise(Phidget_getLibraryVersion(&lib_version));
13
+ return rb_str_new2(lib_version);
14
+ }
15
+
16
+ VALUE ph_add_server(VALUE self, VALUE name, VALUE address, VALUE port, VALUE password, VALUE flags) {
17
+ ph_raise(PhidgetNet_addServer(StringValueCStr(name), StringValueCStr(address), NUM2INT(port), StringValueCStr(password), NUM2INT(flags)));
18
+ return Qnil;
19
+ }
20
+
21
+ VALUE ph_remove_server(VALUE self, VALUE name) {
22
+ ph_raise(PhidgetNet_removeServer(StringValueCStr(name)));
23
+ return Qnil;
24
+ }
25
+
26
+ VALUE ph_enable_server(VALUE self, VALUE name) {
27
+ ph_raise(PhidgetNet_enableServer(StringValueCStr(name)));
28
+ return Qnil;
29
+ }
30
+
31
+ VALUE ph_disable_server(VALUE self, VALUE name, VALUE flags) {
32
+ ph_raise(PhidgetNet_disableServer(StringValueCStr(name), NUM2INT(flags)));
33
+ return Qnil;
34
+ }
35
+
36
+ VALUE ph_enable_server_discovery(VALUE self, VALUE server_type) {
37
+ ph_raise(PhidgetNet_enableServerDiscovery(NUM2INT(server_type)));
38
+ return Qnil;
39
+ }
40
+
41
+ VALUE ph_disable_server_discovery(VALUE self, VALUE server_type) {
42
+ ph_raise(PhidgetNet_disableServerDiscovery(NUM2INT(server_type)));
43
+ return Qnil;
44
+ }
45
+
46
+ VALUE ph_set_server_password(VALUE self, VALUE name, VALUE password) {
47
+ ph_raise(PhidgetNet_setServerPassword(StringValueCStr(name), StringValueCStr(password)));
48
+ return Qnil;
49
+ }
15
50
 
16
51
 
17
52
  void Init_phidgets() {
18
53
  VALUE ph_module = rb_define_module("Phidgets");
19
54
  VALUE ph_error;
20
55
 
21
- rb_define_const(ph_module, "NOTATTACHED", INT2FIX(PHIDGET_NOTATTACHED));
22
- rb_define_const(ph_module, "ATTACHED", INT2FIX(PHIDGET_ATTACHED));
23
-
24
- rb_define_const(ph_module, "CLASS_ACCELEROMETER", INT2FIX(PHIDCLASS_ACCELEROMETER));
25
- rb_define_const(ph_module, "CLASS_ADVANCEDSERVO", INT2FIX(PHIDCLASS_ADVANCEDSERVO));
26
- rb_define_const(ph_module, "CLASS_ANALOG", INT2FIX(PHIDCLASS_ANALOG));
27
- rb_define_const(ph_module, "CLASS_BRIDGE", INT2FIX(PHIDCLASS_BRIDGE));
28
- rb_define_const(ph_module, "CLASS_ENCODER", INT2FIX(PHIDCLASS_ENCODER));
29
- rb_define_const(ph_module, "CLASS_FREQUENCYCOUNTER", INT2FIX(PHIDCLASS_FREQUENCYCOUNTER));
30
- rb_define_const(ph_module, "CLASS_GPS", INT2FIX(PHIDCLASS_GPS));
31
- rb_define_const(ph_module, "CLASS_INTERFACEKIT", INT2FIX(PHIDCLASS_INTERFACEKIT));
32
- rb_define_const(ph_module, "CLASS_IR", INT2FIX(PHIDCLASS_IR));
33
- rb_define_const(ph_module, "CLASS_LED", INT2FIX(PHIDCLASS_LED));
34
- rb_define_const(ph_module, "CLASS_MOTORCONTROL", INT2FIX(PHIDCLASS_MOTORCONTROL));
35
- rb_define_const(ph_module, "CLASS_PHSENSOR", INT2FIX(PHIDCLASS_PHSENSOR));
36
- rb_define_const(ph_module, "CLASS_RFID", INT2FIX(PHIDCLASS_RFID));
37
- rb_define_const(ph_module, "CLASS_SERVO", INT2FIX(PHIDCLASS_SERVO));
38
- rb_define_const(ph_module, "CLASS_SPATIAL", INT2FIX(PHIDCLASS_SPATIAL));
39
- rb_define_const(ph_module, "CLASS_STEPPER", INT2FIX(PHIDCLASS_STEPPER));
40
- rb_define_const(ph_module, "CLASS_TEMPERATURESENSOR", INT2FIX(PHIDCLASS_TEMPERATURESENSOR));
41
- rb_define_const(ph_module, "CLASS_TEXTLCD", INT2FIX(PHIDCLASS_TEXTLCD));
42
- rb_define_const(ph_module, "CLASS_TEXTLED", INT2FIX(PHIDCLASS_TEXTLED));
43
- rb_define_const(ph_module, "CLASS_WEIGHTSENSOR", INT2FIX(PHIDCLASS_WEIGHTSENSOR));
44
-
45
- rb_define_const(ph_module, "ID_ACCELEROMETER_3AXIS", INT2FIX(PHIDID_ACCELEROMETER_3AXIS));
46
- rb_define_const(ph_module, "ID_ADVANCEDSERVO_1MOTOR", INT2FIX(PHIDID_ADVANCEDSERVO_1MOTOR));
47
- rb_define_const(ph_module, "ID_ADVANCEDSERVO_8MOTOR", INT2FIX(PHIDID_ADVANCEDSERVO_8MOTOR));
48
- rb_define_const(ph_module, "ID_ANALOG_4OUTPUT", INT2FIX(PHIDID_ANALOG_4OUTPUT));
49
- rb_define_const(ph_module, "ID_BIPOLAR_STEPPER_1MOTOR", INT2FIX(PHIDID_BIPOLAR_STEPPER_1MOTOR));
50
- rb_define_const(ph_module, "ID_BRIDGE_4INPUT", INT2FIX(PHIDID_BRIDGE_4INPUT));
51
- rb_define_const(ph_module, "ID_ENCODER_1ENCODER_1INPUT", INT2FIX(PHIDID_ENCODER_1ENCODER_1INPUT));
52
- rb_define_const(ph_module, "ID_ENCODER_HS_1ENCODER", INT2FIX(PHIDID_ENCODER_HS_1ENCODER));
53
- rb_define_const(ph_module, "ID_ENCODER_HS_4ENCODER_4INPUT", INT2FIX(PHIDID_ENCODER_HS_4ENCODER_4INPUT));
54
- rb_define_const(ph_module, "ID_FREQUENCYCOUNTER_2INPUT", INT2FIX(PHIDID_FREQUENCYCOUNTER_2INPUT));
55
- rb_define_const(ph_module, "ID_GPS", INT2FIX(PHIDID_GPS));
56
- rb_define_const(ph_module, "ID_INTERFACEKIT_0_0_4", INT2FIX(PHIDID_INTERFACEKIT_0_0_4));
57
- rb_define_const(ph_module, "ID_INTERFACEKIT_0_0_8", INT2FIX(PHIDID_INTERFACEKIT_0_0_8));
58
- rb_define_const(ph_module, "ID_INTERFACEKIT_0_16_16", INT2FIX(PHIDID_INTERFACEKIT_0_16_16));
59
- rb_define_const(ph_module, "ID_INTERFACEKIT_2_2_2", INT2FIX(PHIDID_INTERFACEKIT_2_2_2));
60
- rb_define_const(ph_module, "ID_INTERFACEKIT_8_8_8", INT2FIX(PHIDID_INTERFACEKIT_8_8_8));
61
- rb_define_const(ph_module, "ID_INTERFACEKIT_8_8_8_w_LCD", INT2FIX(PHIDID_INTERFACEKIT_8_8_8_w_LCD));
62
- rb_define_const(ph_module, "ID_IR", INT2FIX(PHIDID_IR));
63
- rb_define_const(ph_module, "ID_LED_64_ADV", INT2FIX(PHIDID_LED_64_ADV));
64
- rb_define_const(ph_module, "ID_LINEAR_TOUCH", INT2FIX(PHIDID_LINEAR_TOUCH));
65
- rb_define_const(ph_module, "ID_MOTORCONTROL_1MOTOR", INT2FIX(PHIDID_MOTORCONTROL_1MOTOR));
66
- rb_define_const(ph_module, "ID_MOTORCONTROL_HC_2MOTOR", INT2FIX(PHIDID_MOTORCONTROL_HC_2MOTOR));
67
- rb_define_const(ph_module, "ID_RFID_2OUTPUT", INT2FIX(PHIDID_RFID_2OUTPUT));
68
- rb_define_const(ph_module, "ID_RFID_2OUTPUT_READ_WRITE", INT2FIX(PHIDID_RFID_2OUTPUT_READ_WRITE));
69
- rb_define_const(ph_module, "ID_ROTARY_TOUCH", INT2FIX(PHIDID_ROTARY_TOUCH));
70
- rb_define_const(ph_module, "ID_SPATIAL_ACCEL_3AXIS", INT2FIX(PHIDID_SPATIAL_ACCEL_3AXIS));
71
- rb_define_const(ph_module, "ID_SPATIAL_ACCEL_GYRO_COMPASS", INT2FIX(PHIDID_SPATIAL_ACCEL_GYRO_COMPASS));
72
- rb_define_const(ph_module, "ID_TEMPERATURESENSOR", INT2FIX(PHIDID_TEMPERATURESENSOR));
73
- rb_define_const(ph_module, "ID_TEMPERATURESENSOR_4", INT2FIX(PHIDID_TEMPERATURESENSOR_4));
74
- rb_define_const(ph_module, "ID_TEMPERATURESENSOR_IR", INT2FIX(PHIDID_TEMPERATURESENSOR_IR));
75
- rb_define_const(ph_module, "ID_TEXTLCD_2x20_w_8_8_8", INT2FIX(PHIDID_TEXTLCD_2x20_w_8_8_8));
76
- rb_define_const(ph_module, "ID_TEXTLCD_ADAPTER", INT2FIX(PHIDID_TEXTLCD_ADAPTER));
77
- rb_define_const(ph_module, "ID_UNIPOLAR_STEPPER_4MOTOR", INT2FIX(PHIDID_UNIPOLAR_STEPPER_4MOTOR));
78
- rb_define_const(ph_module, "ID_ACCELEROMETER_2AXIS", INT2FIX(PHIDID_ACCELEROMETER_2AXIS));
79
- rb_define_const(ph_module, "ID_INTERFACEKIT_0_8_8_w_LCD", INT2FIX(PHIDID_INTERFACEKIT_0_8_8_w_LCD));
80
- rb_define_const(ph_module, "ID_INTERFACEKIT_4_8_8", INT2FIX(PHIDID_INTERFACEKIT_4_8_8));
81
- rb_define_const(ph_module, "ID_LED_64", INT2FIX(PHIDID_LED_64));
82
- rb_define_const(ph_module, "ID_MOTORCONTROL_LV_2MOTOR_4INPUT", INT2FIX(PHIDID_MOTORCONTROL_LV_2MOTOR_4INPUT));
83
- rb_define_const(ph_module, "ID_PHSENSOR", INT2FIX(PHIDID_PHSENSOR));
84
- rb_define_const(ph_module, "ID_RFID", INT2FIX(PHIDID_RFID));
85
- rb_define_const(ph_module, "ID_SERVO_1MOTOR", INT2FIX(PHIDID_SERVO_1MOTOR));
86
- rb_define_const(ph_module, "ID_SERVO_1MOTOR_OLD", INT2FIX(PHIDID_SERVO_1MOTOR_OLD));
87
- rb_define_const(ph_module, "ID_SERVO_4MOTOR", INT2FIX(PHIDID_SERVO_4MOTOR));
88
- rb_define_const(ph_module, "ID_SERVO_4MOTOR_OLD", INT2FIX(PHIDID_SERVO_4MOTOR_OLD));
89
- rb_define_const(ph_module, "ID_TEXTLCD_2x20", INT2FIX(PHIDID_TEXTLCD_2x20));
90
- rb_define_const(ph_module, "ID_TEXTLCD_2x20_w_0_8_8", INT2FIX(PHIDID_TEXTLCD_2x20_w_0_8_8));
91
- rb_define_const(ph_module, "ID_TEXTLED_1x8", INT2FIX(PHIDID_TEXTLED_1x8));
92
- rb_define_const(ph_module, "ID_TEXTLED_4x8", INT2FIX(PHIDID_TEXTLED_4x8));
93
- rb_define_const(ph_module, "ID_WEIGHTSENSOR", INT2FIX(PHIDID_WEIGHTSENSOR));
94
- rb_define_const(ph_module, "ID_FIRMWARE_UPGRADE", INT2FIX(PHIDID_FIRMWARE_UPGRADE));
95
-
96
- rb_define_const(ph_module, "LOG_CRITICAL", INT2FIX(PHIDGET_LOG_CRITICAL));
97
- rb_define_const(ph_module, "LOG_ERROR", INT2FIX(PHIDGET_LOG_ERROR));
98
- rb_define_const(ph_module, "LOG_WARNING", INT2FIX(PHIDGET_LOG_WARNING));
99
- rb_define_const(ph_module, "LOG_DEBUG", INT2FIX(PHIDGET_LOG_DEBUG));
100
- rb_define_const(ph_module, "LOG_INFO", INT2FIX(PHIDGET_LOG_INFO));
101
- rb_define_const(ph_module, "LOG_VERBOSE", INT2FIX(PHIDGET_LOG_VERBOSE));
56
+ rb_define_const(ph_module, "SERVER_DEVICEREMOTE", INT2NUM(PHIDGETSERVER_DEVICEREMOTE));
57
+ rb_define_const(ph_module, "SERVER_WWWREMOTE", INT2NUM(PHIDGETSERVER_WWWREMOTE));
58
+ rb_define_const(ph_module, "SERVER_SBC", INT2NUM(PHIDGETSERVER_SBC));
59
+
60
+ rb_define_const(ph_module, "SERIALNUMBER_ANY", INT2NUM(PHIDGET_SERIALNUMBER_ANY));
61
+ rb_define_const(ph_module, "HUBPORT_ANY", INT2NUM(PHIDGET_HUBPORT_ANY));
62
+ rb_define_const(ph_module, "CHANNEL_ANY", INT2NUM(PHIDGET_CHANNEL_ANY));
63
+ rb_define_const(ph_module, "LABEL_ANY", Qnil);
64
+ rb_define_const(ph_module, "TIMEOUT_INFINITE", INT2NUM(PHIDGET_TIMEOUT_INFINITE));
65
+ rb_define_const(ph_module, "TIMEOUT_DEFAULT", INT2NUM(PHIDGET_TIMEOUT_DEFAULT));
66
+ rb_define_const(ph_module, "SERVER_AUTHREQUIRED", INT2NUM(PHIDGETSERVER_AUTHREQUIRED));
67
+
68
+ rb_define_const(ph_module, "CLASS_NOTHING", INT2NUM(PHIDCLASS_NOTHING));
69
+ rb_define_const(ph_module, "CLASS_ACCELEROMETER", INT2NUM(PHIDCLASS_ACCELEROMETER));
70
+ rb_define_const(ph_module, "CLASS_ADVANCEDSERVO", INT2NUM(PHIDCLASS_ADVANCEDSERVO));
71
+ rb_define_const(ph_module, "CLASS_ANALOG", INT2NUM(PHIDCLASS_ANALOG));
72
+ rb_define_const(ph_module, "CLASS_BRIDGE", INT2NUM(PHIDCLASS_BRIDGE));
73
+ rb_define_const(ph_module, "CLASS_ENCODER", INT2NUM(PHIDCLASS_ENCODER));
74
+ rb_define_const(ph_module, "CLASS_FREQUENCYCOUNTER", INT2NUM(PHIDCLASS_FREQUENCYCOUNTER));
75
+ rb_define_const(ph_module, "CLASS_GPS", INT2NUM(PHIDCLASS_GPS));
76
+ rb_define_const(ph_module, "CLASS_INTERFACEKIT", INT2NUM(PHIDCLASS_INTERFACEKIT));
77
+ rb_define_const(ph_module, "CLASS_IR", INT2NUM(PHIDCLASS_IR));
78
+ rb_define_const(ph_module, "CLASS_LED", INT2NUM(PHIDCLASS_LED));
79
+ rb_define_const(ph_module, "CLASS_MOTORCONTROL", INT2NUM(PHIDCLASS_MOTORCONTROL));
80
+ rb_define_const(ph_module, "CLASS_PHSENSOR", INT2NUM(PHIDCLASS_PHSENSOR));
81
+ rb_define_const(ph_module, "CLASS_RFID", INT2NUM(PHIDCLASS_RFID));
82
+ rb_define_const(ph_module, "CLASS_SERVO", INT2NUM(PHIDCLASS_SERVO));
83
+ rb_define_const(ph_module, "CLASS_SPATIAL", INT2NUM(PHIDCLASS_SPATIAL));
84
+ rb_define_const(ph_module, "CLASS_STEPPER", INT2NUM(PHIDCLASS_STEPPER));
85
+ rb_define_const(ph_module, "CLASS_TEMPERATURESENSOR", INT2NUM(PHIDCLASS_TEMPERATURESENSOR));
86
+ rb_define_const(ph_module, "CLASS_TEXTLCD", INT2NUM(PHIDCLASS_TEXTLCD));
87
+ rb_define_const(ph_module, "CLASS_HUB", INT2NUM(PHIDCLASS_HUB));
88
+ rb_define_const(ph_module, "CLASS_MESHDONGLE", INT2NUM(PHIDCLASS_MESHDONGLE));
89
+ rb_define_const(ph_module, "CLASS_VINT", INT2NUM(PHIDCLASS_VINT));
90
+ rb_define_const(ph_module, "CLASS_GENERIC", INT2NUM(PHIDCLASS_GENERIC));
91
+ rb_define_const(ph_module, "CLASS_FIRMWAREUPGRADE", INT2NUM(PHIDCLASS_FIRMWAREUPGRADE));
92
+ rb_define_const(ph_module, "CLASS_DICTIONARY", INT2NUM(PHIDCLASS_DICTIONARY));
93
+
94
+ rb_define_const(ph_module, "CHCLASS_NOTHING", INT2NUM(PHIDCHCLASS_NOTHING));
95
+ rb_define_const(ph_module, "CHCLASS_ACCELEROMETER", INT2NUM(PHIDCHCLASS_ACCELEROMETER));
96
+ rb_define_const(ph_module, "CHCLASS_CURRENTINPUT", INT2NUM(PHIDCHCLASS_CURRENTINPUT));
97
+ rb_define_const(ph_module, "CHCLASS_DATAADAPTER", INT2NUM(PHIDCHCLASS_DATAADAPTER));
98
+ rb_define_const(ph_module, "CHCLASS_DCMOTOR", INT2NUM(PHIDCHCLASS_DCMOTOR));
99
+ rb_define_const(ph_module, "CHCLASS_DIGITALINPUT", INT2NUM(PHIDCHCLASS_DIGITALINPUT));
100
+ rb_define_const(ph_module, "CHCLASS_DIGITALOUTPUT", INT2NUM(PHIDCHCLASS_DIGITALOUTPUT));
101
+ rb_define_const(ph_module, "CHCLASS_DISTANCESENSOR", INT2NUM(PHIDCHCLASS_DISTANCESENSOR));
102
+ rb_define_const(ph_module, "CHCLASS_ENCODER", INT2NUM(PHIDCHCLASS_ENCODER));
103
+ rb_define_const(ph_module, "CHCLASS_FREQUENCYCOUNTER", INT2NUM(PHIDCHCLASS_FREQUENCYCOUNTER));
104
+ rb_define_const(ph_module, "CHCLASS_GPS", INT2NUM(PHIDCHCLASS_GPS));
105
+ rb_define_const(ph_module, "CHCLASS_LCD", INT2NUM(PHIDCHCLASS_LCD));
106
+ rb_define_const(ph_module, "CHCLASS_GYROSCOPE", INT2NUM(PHIDCHCLASS_GYROSCOPE));
107
+ rb_define_const(ph_module, "CHCLASS_HUB", INT2NUM(PHIDCHCLASS_HUB));
108
+ rb_define_const(ph_module, "CHCLASS_CAPACITIVETOUCH", INT2NUM(PHIDCHCLASS_CAPACITIVETOUCH));
109
+ rb_define_const(ph_module, "CHCLASS_HUMIDITYSENSOR", INT2NUM(PHIDCHCLASS_HUMIDITYSENSOR));
110
+ rb_define_const(ph_module, "CHCLASS_IR", INT2NUM(PHIDCHCLASS_IR));
111
+ rb_define_const(ph_module, "CHCLASS_LIGHTSENSOR", INT2NUM(PHIDCHCLASS_LIGHTSENSOR));
112
+ rb_define_const(ph_module, "CHCLASS_MAGNETOMETER", INT2NUM(PHIDCHCLASS_MAGNETOMETER));
113
+ rb_define_const(ph_module, "CHCLASS_MESHDONGLE", INT2NUM(PHIDCHCLASS_MESHDONGLE));
114
+ rb_define_const(ph_module, "CHCLASS_PHSENSOR", INT2NUM(PHIDCHCLASS_PHSENSOR));
115
+ rb_define_const(ph_module, "CHCLASS_POWERGUARD", INT2NUM(PHIDCHCLASS_POWERGUARD));
116
+ rb_define_const(ph_module, "CHCLASS_PRESSURESENSOR", INT2NUM(PHIDCHCLASS_PRESSURESENSOR));
117
+ rb_define_const(ph_module, "CHCLASS_RCSERVO", INT2NUM(PHIDCHCLASS_RCSERVO));
118
+ rb_define_const(ph_module, "CHCLASS_RESISTANCEINPUT", INT2NUM(PHIDCHCLASS_RESISTANCEINPUT));
119
+ rb_define_const(ph_module, "CHCLASS_RFID", INT2NUM(PHIDCHCLASS_RFID));
120
+ rb_define_const(ph_module, "CHCLASS_SOUNDSENSOR", INT2NUM(PHIDCHCLASS_SOUNDSENSOR));
121
+ rb_define_const(ph_module, "CHCLASS_SPATIAL", INT2NUM(PHIDCHCLASS_SPATIAL));
122
+ rb_define_const(ph_module, "CHCLASS_STEPPER", INT2NUM(PHIDCHCLASS_STEPPER));
123
+ rb_define_const(ph_module, "CHCLASS_TEMPERATURESENSOR", INT2NUM(PHIDCHCLASS_TEMPERATURESENSOR));
124
+ rb_define_const(ph_module, "CHCLASS_VOLTAGEINPUT", INT2NUM(PHIDCHCLASS_VOLTAGEINPUT));
125
+ rb_define_const(ph_module, "CHCLASS_VOLTAGEOUTPUT", INT2NUM(PHIDCHCLASS_VOLTAGEOUTPUT));
126
+ rb_define_const(ph_module, "CHCLASS_VOLTAGERATIOINPUT", INT2NUM(PHIDCHCLASS_VOLTAGERATIOINPUT));
127
+ rb_define_const(ph_module, "CHCLASS_FIRMWAREUPGRADE", INT2NUM(PHIDCHCLASS_FIRMWAREUPGRADE));
128
+ rb_define_const(ph_module, "CHCLASS_GENERIC", INT2NUM(PHIDCHCLASS_GENERIC));
129
+ rb_define_const(ph_module, "CHCLASS_MOTORPOSITIONCONTROLLER", INT2NUM(PHIDCHCLASS_MOTORPOSITIONCONTROLLER));
130
+ rb_define_const(ph_module, "CHCLASS_BLDCMOTOR", INT2NUM(PHIDCHCLASS_BLDCMOTOR));
131
+ rb_define_const(ph_module, "CHCLASS_DICTIONARY", INT2NUM(PHIDCHCLASS_DICTIONARY));
132
+ rb_define_const(ph_module, "CHCLASS_CURRENTOUTPUT", INT2NUM(PHIDCHCLASS_CURRENTOUTPUT));
133
+
134
+ rb_define_const(ph_module, "CHSUBCLASS_NONE", INT2NUM(PHIDCHSUBCLASS_NONE));
135
+ rb_define_const(ph_module, "CHSUBCLASS_DIGITALOUTPUT_DUTY_CYCLE", INT2NUM(PHIDCHSUBCLASS_DIGITALOUTPUT_DUTY_CYCLE));
136
+ rb_define_const(ph_module, "CHSUBCLASS_DIGITALOUTPUT_LED_DRIVER", INT2NUM(PHIDCHSUBCLASS_DIGITALOUTPUT_LED_DRIVER));
137
+ rb_define_const(ph_module, "CHSUBCLASS_TEMPERATURESENSOR_RTD", INT2NUM(PHIDCHSUBCLASS_TEMPERATURESENSOR_RTD));
138
+ rb_define_const(ph_module, "CHSUBCLASS_TEMPERATURESENSOR_THERMOCOUPLE", INT2NUM(PHIDCHSUBCLASS_TEMPERATURESENSOR_THERMOCOUPLE));
139
+ rb_define_const(ph_module, "CHSUBCLASS_VOLTAGEINPUT_SENSOR_PORT", INT2NUM(PHIDCHSUBCLASS_VOLTAGEINPUT_SENSOR_PORT));
140
+ rb_define_const(ph_module, "CHSUBCLASS_VOLTAGERATIOINPUT_SENSOR_PORT", INT2NUM(PHIDCHSUBCLASS_VOLTAGERATIOINPUT_SENSOR_PORT));
141
+ rb_define_const(ph_module, "CHSUBCLASS_VOLTAGERATIOINPUT_BRIDGE", INT2NUM(PHIDCHSUBCLASS_VOLTAGERATIOINPUT_BRIDGE));
142
+ rb_define_const(ph_module, "CHSUBCLASS_LCD_GRAPHIC", INT2NUM(PHIDCHSUBCLASS_LCD_GRAPHIC));
143
+ rb_define_const(ph_module, "CHSUBCLASS_LCD_TEXT", INT2NUM(PHIDCHSUBCLASS_LCD_TEXT));
144
+ rb_define_const(ph_module, "CHSUBCLASS_ENCODER_MODE_SETTABLE", INT2NUM(PHIDCHSUBCLASS_ENCODER_MODE_SETTABLE));
145
+
146
+ rb_define_const(ph_module, "ID_NOTHING", INT2NUM(PHIDID_NOTHING));
147
+ rb_define_const(ph_module, "ID_INTERFACEKIT_4_8_8", INT2NUM(PHIDID_INTERFACEKIT_4_8_8));
148
+ rb_define_const(ph_module, "ID_1000", INT2NUM(PHIDID_1000));
149
+ rb_define_const(ph_module, "ID_1001", INT2NUM(PHIDID_1001));
150
+ rb_define_const(ph_module, "ID_1002", INT2NUM(PHIDID_1002));
151
+ rb_define_const(ph_module, "ID_1008", INT2NUM(PHIDID_1008));
152
+ rb_define_const(ph_module, "ID_1010_1013_1018_1019", INT2NUM(PHIDID_1010_1013_1018_1019));
153
+ rb_define_const(ph_module, "ID_1011", INT2NUM(PHIDID_1011));
154
+ rb_define_const(ph_module, "ID_1012", INT2NUM(PHIDID_1012));
155
+ rb_define_const(ph_module, "ID_1014", INT2NUM(PHIDID_1014));
156
+ rb_define_const(ph_module, "ID_1015", INT2NUM(PHIDID_1015));
157
+ rb_define_const(ph_module, "ID_1016", INT2NUM(PHIDID_1016));
158
+ rb_define_const(ph_module, "ID_1017", INT2NUM(PHIDID_1017));
159
+ rb_define_const(ph_module, "ID_1023", INT2NUM(PHIDID_1023));
160
+ rb_define_const(ph_module, "ID_1024", INT2NUM(PHIDID_1024));
161
+ rb_define_const(ph_module, "ID_1030", INT2NUM(PHIDID_1030));
162
+ rb_define_const(ph_module, "ID_1031", INT2NUM(PHIDID_1031));
163
+ rb_define_const(ph_module, "ID_1032", INT2NUM(PHIDID_1032));
164
+ rb_define_const(ph_module, "ID_1040", INT2NUM(PHIDID_1040));
165
+ rb_define_const(ph_module, "ID_1041", INT2NUM(PHIDID_1041));
166
+ rb_define_const(ph_module, "ID_1042", INT2NUM(PHIDID_1042));
167
+ rb_define_const(ph_module, "ID_1043", INT2NUM(PHIDID_1043));
168
+ rb_define_const(ph_module, "ID_1044", INT2NUM(PHIDID_1044));
169
+ rb_define_const(ph_module, "ID_1045", INT2NUM(PHIDID_1045));
170
+ rb_define_const(ph_module, "ID_1046", INT2NUM(PHIDID_1046));
171
+ rb_define_const(ph_module, "ID_1047", INT2NUM(PHIDID_1047));
172
+ rb_define_const(ph_module, "ID_1048", INT2NUM(PHIDID_1048));
173
+ rb_define_const(ph_module, "ID_1049", INT2NUM(PHIDID_1049));
174
+ rb_define_const(ph_module, "ID_1051", INT2NUM(PHIDID_1051));
175
+ rb_define_const(ph_module, "ID_1052", INT2NUM(PHIDID_1052));
176
+ rb_define_const(ph_module, "ID_1053", INT2NUM(PHIDID_1053));
177
+ rb_define_const(ph_module, "ID_1054", INT2NUM(PHIDID_1054));
178
+ rb_define_const(ph_module, "ID_1055", INT2NUM(PHIDID_1055));
179
+ rb_define_const(ph_module, "ID_1056", INT2NUM(PHIDID_1056));
180
+ rb_define_const(ph_module, "ID_1057", INT2NUM(PHIDID_1057));
181
+ rb_define_const(ph_module, "ID_1058", INT2NUM(PHIDID_1058));
182
+ rb_define_const(ph_module, "ID_1059", INT2NUM(PHIDID_1059));
183
+ rb_define_const(ph_module, "ID_1060", INT2NUM(PHIDID_1060));
184
+ rb_define_const(ph_module, "ID_1061", INT2NUM(PHIDID_1061));
185
+ rb_define_const(ph_module, "ID_1062", INT2NUM(PHIDID_1062));
186
+ rb_define_const(ph_module, "ID_1063", INT2NUM(PHIDID_1063));
187
+ rb_define_const(ph_module, "ID_1064", INT2NUM(PHIDID_1064));
188
+ rb_define_const(ph_module, "ID_1065", INT2NUM(PHIDID_1065));
189
+ rb_define_const(ph_module, "ID_1066", INT2NUM(PHIDID_1066));
190
+ rb_define_const(ph_module, "ID_1067", INT2NUM(PHIDID_1067));
191
+ rb_define_const(ph_module, "ID_1202_1203", INT2NUM(PHIDID_1202_1203));
192
+ rb_define_const(ph_module, "ID_1204", INT2NUM(PHIDID_1204));
193
+ rb_define_const(ph_module, "ID_1215__1218", INT2NUM(PHIDID_1215__1218));
194
+ rb_define_const(ph_module, "ID_1219__1222", INT2NUM(PHIDID_1219__1222));
195
+ rb_define_const(ph_module, "ID_ADP1000", INT2NUM(PHIDID_ADP1000));
196
+ rb_define_const(ph_module, "ID_ADP1001", INT2NUM(PHIDID_ADP1001));
197
+ rb_define_const(ph_module, "ID_DAQ1000", INT2NUM(PHIDID_DAQ1000));
198
+ rb_define_const(ph_module, "ID_DAQ1200", INT2NUM(PHIDID_DAQ1200));
199
+ rb_define_const(ph_module, "ID_DAQ1300", INT2NUM(PHIDID_DAQ1300));
200
+ rb_define_const(ph_module, "ID_DAQ1301", INT2NUM(PHIDID_DAQ1301));
201
+ rb_define_const(ph_module, "ID_DAQ1400", INT2NUM(PHIDID_DAQ1400));
202
+ rb_define_const(ph_module, "ID_DAQ1500", INT2NUM(PHIDID_DAQ1500));
203
+ rb_define_const(ph_module, "ID_DCC1000", INT2NUM(PHIDID_DCC1000));
204
+ rb_define_const(ph_module, "ID_DST1000", INT2NUM(PHIDID_DST1000));
205
+ rb_define_const(ph_module, "ID_DST1200", INT2NUM(PHIDID_DST1200));
206
+ rb_define_const(ph_module, "ID_ENC1000", INT2NUM(PHIDID_ENC1000));
207
+ rb_define_const(ph_module, "ID_HIN1000", INT2NUM(PHIDID_HIN1000));
208
+ rb_define_const(ph_module, "ID_HIN1001", INT2NUM(PHIDID_HIN1001));
209
+ rb_define_const(ph_module, "ID_HIN1100", INT2NUM(PHIDID_HIN1100));
210
+ rb_define_const(ph_module, "ID_HUB0000", INT2NUM(PHIDID_HUB0000));
211
+ rb_define_const(ph_module, "ID_HUB0001", INT2NUM(PHIDID_HUB0001));
212
+ rb_define_const(ph_module, "ID_HUB0002", INT2NUM(PHIDID_HUB0002));
213
+ rb_define_const(ph_module, "ID_HUB0004", INT2NUM(PHIDID_HUB0004));
214
+ rb_define_const(ph_module, "ID_HUB0005", INT2NUM(PHIDID_HUB0005));
215
+ rb_define_const(ph_module, "ID_HUM1000", INT2NUM(PHIDID_HUM1000));
216
+ rb_define_const(ph_module, "ID_LCD1100", INT2NUM(PHIDID_LCD1100));
217
+ rb_define_const(ph_module, "ID_LED1000", INT2NUM(PHIDID_LED1000));
218
+ rb_define_const(ph_module, "ID_LUX1000", INT2NUM(PHIDID_LUX1000));
219
+ rb_define_const(ph_module, "ID_MOT1100", INT2NUM(PHIDID_MOT1100));
220
+ rb_define_const(ph_module, "ID_MOT1101", INT2NUM(PHIDID_MOT1101));
221
+ rb_define_const(ph_module, "ID_OUT1000", INT2NUM(PHIDID_OUT1000));
222
+ rb_define_const(ph_module, "ID_OUT1001", INT2NUM(PHIDID_OUT1001));
223
+ rb_define_const(ph_module, "ID_OUT1002", INT2NUM(PHIDID_OUT1002));
224
+ rb_define_const(ph_module, "ID_OUT1100", INT2NUM(PHIDID_OUT1100));
225
+ rb_define_const(ph_module, "ID_PRE1000", INT2NUM(PHIDID_PRE1000));
226
+ rb_define_const(ph_module, "ID_RCC1000", INT2NUM(PHIDID_RCC1000));
227
+ rb_define_const(ph_module, "ID_REL1000", INT2NUM(PHIDID_REL1000));
228
+ rb_define_const(ph_module, "ID_REL1100", INT2NUM(PHIDID_REL1100));
229
+ rb_define_const(ph_module, "ID_REL1101", INT2NUM(PHIDID_REL1101));
230
+ rb_define_const(ph_module, "ID_SAF1000", INT2NUM(PHIDID_SAF1000));
231
+ rb_define_const(ph_module, "ID_SND1000", INT2NUM(PHIDID_SND1000));
232
+ rb_define_const(ph_module, "ID_STC1000", INT2NUM(PHIDID_STC1000));
233
+ rb_define_const(ph_module, "ID_TMP1000", INT2NUM(PHIDID_TMP1000));
234
+ rb_define_const(ph_module, "ID_TMP1100", INT2NUM(PHIDID_TMP1100));
235
+ rb_define_const(ph_module, "ID_TMP1101", INT2NUM(PHIDID_TMP1101));
236
+ rb_define_const(ph_module, "ID_TMP1200", INT2NUM(PHIDID_TMP1200));
237
+ rb_define_const(ph_module, "ID_TMP1300", INT2NUM(PHIDID_TMP1300));
238
+ rb_define_const(ph_module, "ID_VCP1000", INT2NUM(PHIDID_VCP1000));
239
+ rb_define_const(ph_module, "ID_VCP1001", INT2NUM(PHIDID_VCP1001));
240
+ rb_define_const(ph_module, "ID_VCP1002", INT2NUM(PHIDID_VCP1002));
241
+ rb_define_const(ph_module, "ID_DIGITALINPUT_PORT", INT2NUM(PHIDID_DIGITALINPUT_PORT));
242
+ rb_define_const(ph_module, "ID_DIGITALOUTPUT_PORT", INT2NUM(PHIDID_DIGITALOUTPUT_PORT));
243
+ rb_define_const(ph_module, "ID_VOLTAGEINPUT_PORT", INT2NUM(PHIDID_VOLTAGEINPUT_PORT));
244
+ rb_define_const(ph_module, "ID_VOLTAGERATIOINPUT_PORT", INT2NUM(PHIDID_VOLTAGERATIOINPUT_PORT));
245
+ rb_define_const(ph_module, "ID_GENERICUSB", INT2NUM(PHIDID_GENERICUSB));
246
+ rb_define_const(ph_module, "ID_GENERICVINT", INT2NUM(PHIDID_GENERICVINT));
247
+ rb_define_const(ph_module, "ID_FIRMWARE_UPGRADE_USB", INT2NUM(PHIDID_FIRMWARE_UPGRADE_USB));
248
+ rb_define_const(ph_module, "ID_FIRMWARE_UPGRADE_STM32F0", INT2NUM(PHIDID_FIRMWARE_UPGRADE_STM32F0));
249
+ rb_define_const(ph_module, "ID_FIRMWARE_UPGRADE_STM8S", INT2NUM(PHIDID_FIRMWARE_UPGRADE_STM8S));
250
+ rb_define_const(ph_module, "ID_FIRMWARE_UPGRADE_SPI", INT2NUM(PHIDID_FIRMWARE_UPGRADE_SPI));
251
+ rb_define_const(ph_module, "ID_VCP1100", INT2NUM(PHIDID_VCP1100));
252
+ rb_define_const(ph_module, "ID_DCC1100", INT2NUM(PHIDID_DCC1100));
253
+ rb_define_const(ph_module, "ID_HIN1101", INT2NUM(PHIDID_HIN1101));
254
+ rb_define_const(ph_module, "ID_DCC1001", INT2NUM(PHIDID_DCC1001));
255
+ rb_define_const(ph_module, "ID_DICTIONARY", INT2NUM(PHIDID_DICTIONARY));
256
+ rb_define_const(ph_module, "ID_STC1001", INT2NUM(PHIDID_STC1001));
257
+ rb_define_const(ph_module, "ID_USBSWITCH", INT2NUM(PHIDID_USBSWITCH));
258
+ rb_define_const(ph_module, "ID_DCC1002", INT2NUM(PHIDID_DCC1002));
259
+ rb_define_const(ph_module, "ID_STC1002", INT2NUM(PHIDID_STC1002));
260
+ rb_define_const(ph_module, "ID_STC1003", INT2NUM(PHIDID_STC1003));
261
+ rb_define_const(ph_module, "ID_DCC1003", INT2NUM(PHIDID_DCC1003));
262
+ rb_define_const(ph_module, "ID_DST1001", INT2NUM(PHIDID_DST1001));
263
+ rb_define_const(ph_module, "ID_CURLOOP", INT2NUM(PHIDID_CURLOOP));
264
+ rb_define_const(ph_module, "ID_HUB5000", INT2NUM(PHIDID_HUB5000));
265
+ rb_define_const(ph_module, "ID_RCC0004", INT2NUM(PHIDID_RCC0004));
266
+
267
+ rb_define_const(ph_module, "INPUT_MODE_NPN", INT2NUM(INPUT_MODE_NPN));
268
+ rb_define_const(ph_module, "INPUT_MODE_PNP", INT2NUM(INPUT_MODE_PNP));
269
+
270
+ rb_define_const(ph_module, "POWER_SUPPLY_OFF", INT2NUM(POWER_SUPPLY_OFF));
271
+ rb_define_const(ph_module, "POWER_SUPPLY_12V", INT2NUM(POWER_SUPPLY_12V));
272
+ rb_define_const(ph_module, "POWER_SUPPLY_24V", INT2NUM(POWER_SUPPLY_24V));
273
+
274
+ rb_define_const(ph_module, "RTD_WIRE_SETUP_2WIRE", INT2NUM(RTD_WIRE_SETUP_2WIRE));
275
+ rb_define_const(ph_module, "RTD_WIRE_SETUP_3WIRE", INT2NUM(RTD_WIRE_SETUP_3WIRE));
276
+ rb_define_const(ph_module, "RTD_WIRE_SETUP_4WIRE", INT2NUM(RTD_WIRE_SETUP_4WIRE));
277
+
278
+ rb_define_const(ph_module, "FAN_MODE_OFF", INT2NUM(FAN_MODE_OFF));
279
+ rb_define_const(ph_module, "FAN_MODE_ON", INT2NUM(FAN_MODE_ON));
280
+ rb_define_const(ph_module, "FAN_MODE_AUTO", INT2NUM(FAN_MODE_AUTO));
102
281
 
103
282
  ph_error = rb_define_class_under(ph_module, "Error", rb_eStandardError);
104
- ph_errors[EPHIDGET_NOTFOUND] = rb_define_class_under(ph_error, "NotFound", ph_error);
105
- ph_errors[EPHIDGET_NOMEMORY] = rb_define_class_under(ph_error, "NoMemory", ph_error);
106
- ph_errors[EPHIDGET_UNEXPECTED] = rb_define_class_under(ph_error, "Unexpected", ph_error);
107
- ph_errors[EPHIDGET_INVALIDARG] = rb_define_class_under(ph_error, "InvalidArg", ph_error);
108
- ph_errors[EPHIDGET_NOTATTACHED] = rb_define_class_under(ph_error, "NotAttached", ph_error);
109
- ph_errors[EPHIDGET_INTERRUPTED] = rb_define_class_under(ph_error, "Interrupted", ph_error);
110
- ph_errors[EPHIDGET_INVALID] = rb_define_class_under(ph_error, "Invalid", ph_error);
111
- ph_errors[EPHIDGET_NETWORK] = rb_define_class_under(ph_error, "Network", ph_error);
112
- ph_errors[EPHIDGET_UNKNOWNVAL] = rb_define_class_under(ph_error, "UnknownVal", ph_error);
113
- ph_errors[EPHIDGET_BADPASSWORD] = rb_define_class_under(ph_error, "BadPassword", ph_error);
114
- ph_errors[EPHIDGET_UNSUPPORTED] = rb_define_class_under(ph_error, "Unsupported", ph_error);
115
- ph_errors[EPHIDGET_DUPLICATE] = rb_define_class_under(ph_error, "Duplicate", ph_error);
116
- ph_errors[EPHIDGET_TIMEOUT] = rb_define_class_under(ph_error, "Timeout", ph_error);
117
- ph_errors[EPHIDGET_OUTOFBOUNDS] = rb_define_class_under(ph_error, "OutOfBounds", ph_error);
118
- ph_errors[EPHIDGET_EVENT] = rb_define_class_under(ph_error, "Event", ph_error);
119
- ph_errors[EPHIDGET_NETWORK_NOTCONNECTED] = rb_define_class_under(ph_error, "NetworkNotConnected", ph_error);
120
- ph_errors[EPHIDGET_WRONGDEVICE] = rb_define_class_under(ph_error, "WrongDevice", ph_error);
121
- ph_errors[EPHIDGET_CLOSED] = rb_define_class_under(ph_error, "Closed", ph_error);
122
- ph_errors[EPHIDGET_BADVERSION] = rb_define_class_under(ph_error, "BadVersion", ph_error);
123
- ph_errors[EPHIDGET_NOTIMPLEMENTED] = rb_define_class_under(ph_error, "NotImplemented", ph_error);
283
+ rb_define_class_under(ph_error, "NotPermitted", ph_error);
284
+ rb_define_class_under(ph_error, "NoSuchEntity", ph_error);
285
+ rb_define_class_under(ph_error, "TimedOut", ph_error);
286
+ rb_define_class_under(ph_error, "KeepAliveFailure", ph_error);
287
+ rb_define_class_under(ph_error, "OpInterrupted", ph_error);
288
+ rb_define_class_under(ph_error, "IOError", ph_error);
289
+ rb_define_class_under(ph_error, "MemoryError", ph_error);
290
+ rb_define_class_under(ph_error, "AccessError", ph_error);
291
+ rb_define_class_under(ph_error, "AddressError", ph_error);
292
+ rb_define_class_under(ph_error, "ResourceBusy", ph_error);
293
+ rb_define_class_under(ph_error, "ObjectExists", ph_error);
294
+ rb_define_class_under(ph_error, "ObjectNotDirectory", ph_error);
295
+ rb_define_class_under(ph_error, "ObjectIsDirectory", ph_error);
296
+ rb_define_class_under(ph_error, "Invalid", ph_error);
297
+ rb_define_class_under(ph_error, "TooManyOpenFilesInSystem", ph_error);
298
+ rb_define_class_under(ph_error, "TooManyOpenFiles", ph_error);
299
+ rb_define_class_under(ph_error, "NoSpace", ph_error);
300
+ rb_define_class_under(ph_error, "FileTooBig", ph_error);
301
+ rb_define_class_under(ph_error, "ReadOnlyFilesystem", ph_error);
302
+ rb_define_class_under(ph_error, "ReadOnlyObject", ph_error);
303
+ rb_define_class_under(ph_error, "OpNotSupported", ph_error);
304
+ rb_define_class_under(ph_error, "InvalidArg", ph_error);
305
+ rb_define_class_under(ph_error, "TryAgain", ph_error);
306
+ rb_define_class_under(ph_error, "NotEmpty", ph_error);
307
+ rb_define_class_under(ph_error, "UnexpectedError", ph_error);
308
+ rb_define_class_under(ph_error, "Duplicate", ph_error);
309
+ rb_define_class_under(ph_error, "BadCredential", ph_error);
310
+ rb_define_class_under(ph_error, "NetworkUnavailable", ph_error);
311
+ rb_define_class_under(ph_error, "ConnectionRefused", ph_error);
312
+ rb_define_class_under(ph_error, "ConnectionReset", ph_error);
313
+ rb_define_class_under(ph_error, "NoRouteToHost", ph_error);
314
+ rb_define_class_under(ph_error, "NoSuchDevice", ph_error);
315
+ rb_define_class_under(ph_error, "WrongDevice", ph_error);
316
+ rb_define_class_under(ph_error, "BrokenPipe", ph_error);
317
+ rb_define_class_under(ph_error, "NameResolutionError", ph_error);
318
+ rb_define_class_under(ph_error, "UnknownValue", ph_error);
319
+ rb_define_class_under(ph_error, "DeviceNotAttached", ph_error);
320
+ rb_define_class_under(ph_error, "InvalidPacket", ph_error);
321
+ rb_define_class_under(ph_error, "ArgListTooLong", ph_error);
322
+ rb_define_class_under(ph_error, "BadVersion", ph_error);
323
+ rb_define_class_under(ph_error, "Closed", ph_error);
324
+ rb_define_class_under(ph_error, "NotConfigured", ph_error);
325
+ rb_define_class_under(ph_error, "EndOfFile", ph_error);
326
+ rb_define_class_under(ph_error, "NotImplemented", ph_error);
327
+ rb_define_class_under(ph_error, "UnknownError", ph_error);
124
328
 
125
329
  /*
126
330
  * Document-method: getLibraryVersion
@@ -129,78 +333,128 @@ void Init_phidgets() {
129
333
  * Gets the library version. This contains a version number and a build date.
130
334
  */
131
335
  rb_define_singleton_method(ph_module, "getLibraryVersion", ph_get_library_version, 0);
336
+ rb_define_singleton_method(ph_module, "library_version", ph_get_library_version, 0);
337
+
132
338
 
133
339
  /*
134
- * Document-method: library_version
135
- * call-seq: library_version -> version
340
+ * Document-method: addServer
341
+ * call-seq: addServer(server_name, address, port, password, flags)
136
342
  *
137
- * Gets the library version. This contains a version number and a build date.
343
+ * Registers a server that the client (your program) will try to connect to. The client will continually try to connect to the server, increasing the time between each attempt to a maximum interval of 16 seconds.
344
+ * This call is intended for use when server discovery is not enabled, or to connect to a server that is not discoverable.
345
+ * The server name used by this function does not have to match the name of the server running on the host machine. Only the address, port, and password need to match.
346
+ * This call will fail if a server with the same name has already been discovered.
347
+ * This call will fail if PhidgetNet_setServerPassword() has already been called with the same server name, as PhidgetNet_setServerPassword() registers the server entry anticipating the discovery of the server.
138
348
  */
139
- rb_define_singleton_method(ph_module, "library_version", ph_get_library_version, 0);
349
+ rb_define_singleton_method(ph_module, "addServer", ph_add_server, 5);
350
+ rb_define_singleton_method(ph_module, "add_server", ph_add_server, 5);
351
+
140
352
 
141
353
  /*
142
- * Document-method: enableLogging
143
- * call-seq: enableLogging(log_level, output_file)
354
+ * Document-method: removeServer
355
+ * call-seq: removeServer(server_name)
144
356
  *
145
- * Enables logging.
357
+ * Removes a registration for a server that the client (your program) is trying to connect to.If the client is currently connected to the server, the connection will be closed.
358
+ * If the server was discovered (not added by PhidgetNet_addServer()), the connection may be reestablished if and when the server is rediscovered. PhidgetNet_disableServer()
359
+ * should be used to prevent the reconnection of a discovered server.
146
360
  */
147
- rb_define_singleton_method(ph_module, "enableLogging", ph_enable_logging, 2);
361
+ rb_define_singleton_method(ph_module, "removeServer", ph_remove_server, 1);
362
+ rb_define_singleton_method(ph_module, "remove_server", ph_remove_server, 1);
363
+
148
364
 
149
365
  /*
150
- * Document-method: enable_logging
151
- * call-seq: enable_logging(log_level, output_file)
366
+ * Document-method: enableServer
367
+ * call-seq: enableServer(server_name)
152
368
  *
153
- * Enables logging.
369
+ * Enables attempts to connect to a discovered server, if attempts were previously disabled by PhidgetNet_disableServer(). All servers are enabled by default.
370
+ * This call will fail if the server was not previously added, disabled or discovered.
154
371
  */
155
- rb_define_singleton_method(ph_module, "enable_logging", ph_enable_logging, 2);
372
+ rb_define_singleton_method(ph_module, "enableServer", ph_enable_server, 1);
373
+ rb_define_singleton_method(ph_module, "enable_server", ph_enable_server, 1);
374
+
156
375
 
157
376
  /*
158
- * Document-method: disableLogging
159
- * call-seq: disableLogging
377
+ * Document-method: disableServer
378
+ * call-seq: disableServer(server_name, flags)
160
379
  *
161
- * Disables logging.
380
+ * Prevents attempts to automatically connect to a server.
381
+ * By default the client (your program) will continually attempt to connect to added or discovered servers.This call will disable those attempts, but will not close an already established connection.
162
382
  */
163
- rb_define_singleton_method(ph_module, "disableLogging", ph_disable_logging, 0);
383
+ rb_define_singleton_method(ph_module, "disableServer", ph_disable_server, 2);
384
+ rb_define_singleton_method(ph_module, "disable_server", ph_disable_server, 2);
385
+
164
386
 
165
387
  /*
166
- * Document-method: disable_logging
167
- * call-seq: disable_logging
388
+ * Document-method: enableServerDiscovery
389
+ * call-seq: enableServerDiscovery(server_type)
168
390
  *
169
- * Disables logging.
391
+ * Enables the dynamic discovery of servers that publish their identity to the network. Currently Multicast DNS is used to discover and publish Phidget servers.
392
+ * To connect to remote Phidgets, call this function with server type DEVICEREMOTE.
393
+ * PhidgetNet_enableServerDiscovery() must be called once for each server type your program requires. Multiple calls for the same server type are ignored
394
+ * This call will fail with the error code EPHIDGET_UNSUPPORTED if your computer does not have the required mDNS support. We recommend using Bonjour Print Services on Windows and Mac, or Avahi on Linux.
170
395
  */
171
- rb_define_singleton_method(ph_module, "disable_logging", ph_disable_logging, 0);
396
+ rb_define_singleton_method(ph_module, "enableServerDiscovery", ph_enable_server_discovery, 1);
397
+ rb_define_singleton_method(ph_module, "enable_server_discovery", ph_enable_server_discovery, 1);
398
+
172
399
 
173
400
  /*
174
- * Document-method: log
175
- * call-seq: log(log_level, msg_id, msg)
401
+ * Document-method: disableServerDiscovery
402
+ * call-seq: disableServerDiscovery(server_type)
176
403
  *
177
- * Appends a message to the log.
404
+ * Disables the dynamic discovery of servers that publish their identity.
405
+ * PhidgetNet_disableServerDiscovery() does not disconnect already established connections.
178
406
  */
179
- rb_define_singleton_method(ph_module, "log", ph_log, 3);
407
+ rb_define_singleton_method(ph_module, "disableServerDiscovery", ph_disable_server_discovery, 1);
408
+ rb_define_singleton_method(ph_module, "disable_server_discovery", ph_disable_server_discovery, 1);
180
409
 
181
- Init_dictionary();
410
+
411
+ /*
412
+ * Document-method: setServerPassword
413
+ * call-seq: setServerPassword(server_name, password)
414
+ *
415
+ * Sets the password that will be used to attempt to connect to the server. If the server has not already been added or discovered, a placeholder server entry
416
+ * will be registered to use this password on the server once it is discovered.
417
+ */
418
+ rb_define_singleton_method(ph_module, "setServerPassword", ph_set_server_password, 2);
419
+ rb_define_singleton_method(ph_module, "server_password", ph_set_server_password, 2);
420
+
421
+
422
+ Init_logging();
182
423
  Init_manager();
183
424
  Init_common();
184
425
  Init_accelerometer();
185
- Init_advanced_servo();
186
- Init_analog();
187
- Init_bridge();
426
+ Init_bldc_motor();
427
+ Init_capacitive_touch();
428
+ Init_current_input();
429
+ Init_dc_motor();
430
+ Init_dictionary();
431
+ Init_digital_input();
432
+ Init_digital_output();
433
+ Init_distance();
188
434
  Init_encoder();
189
435
  Init_frequency_counter();
190
436
  Init_gps();
191
- Init_interface_kit();
437
+ Init_gyroscope();
438
+ Init_hub();
439
+ Init_humidity();
192
440
  Init_ir();
193
- Init_led();
194
- Init_motor_control();
441
+ Init_lcd();
442
+ Init_light();
443
+ Init_magnetometer();
444
+ Init_motor_position_controller();
195
445
  Init_ph_sensor();
446
+ Init_power_guard();
447
+ Init_pressure();
448
+ Init_rc_servo();
196
449
  Init_rfid();
197
- Init_servo();
450
+ Init_resistance();
451
+ Init_sound();
198
452
  Init_spatial();
199
453
  Init_stepper();
200
454
  Init_temperature_sensor();
201
- Init_text_lcd();
202
- Init_text_led();
203
- Init_weight_sensor();
455
+ Init_voltage_input();
456
+ Init_voltage_output();
457
+ Init_voltage_ratio_input();
204
458
  }
205
459
 
206
460
 
@@ -210,69 +464,350 @@ ph_data_t *get_ph_data(VALUE self) {
210
464
  return ph;
211
465
  }
212
466
 
213
- CPhidgetHandle get_ph_handle(VALUE self) {
467
+ PhidgetHandle get_ph_handle(VALUE self) {
214
468
  ph_data_t *ph = get_ph_data(self);
215
469
  return ph->handle;
216
470
  }
217
471
 
218
472
  void ph_raise(int err_code) {
219
- if(err_code > EPHIDGET_OK && err_code < PHIDGET_ERROR_CODE_COUNT) {
220
- const char *err_description;
221
- CPhidget_getErrorDescription(err_code, &err_description);
222
- rb_raise(ph_errors[err_code], err_description);
473
+ if(err_code != EPHIDGET_OK) {
474
+ VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
475
+ VALUE ph_error = rb_const_get(ph_module, rb_intern("Error"));
476
+
477
+ switch( err_code ) {
478
+ case EPHIDGET_PERM:
479
+ rb_raise(rb_const_get(ph_error, rb_intern("NotPermitted")), "Not Permitted");
480
+ break;
481
+ case EPHIDGET_NOENT:
482
+ rb_raise(rb_const_get(ph_error, rb_intern("NoSuchEntity")), "No Such Entity");
483
+ break;
484
+ case EPHIDGET_TIMEOUT:
485
+ rb_raise(rb_const_get(ph_error, rb_intern("TimedOut")), "Timed Out");
486
+ break;
487
+ case EPHIDGET_KEEPALIVE:
488
+ rb_raise(rb_const_get(ph_error, rb_intern("KeepAliveFailure")), "Keep Alive Failure");
489
+ break;
490
+ case EPHIDGET_INTERRUPTED:
491
+ rb_raise(rb_const_get(ph_error, rb_intern("OpInterrupted")), "Op Interrupted");
492
+ break;
493
+ case EPHIDGET_IO:
494
+ rb_raise(rb_const_get(ph_error, rb_intern("IOError")), "IO Issue");
495
+ break;
496
+ case EPHIDGET_NOMEMORY:
497
+ rb_raise(rb_const_get(ph_error, rb_intern("MemoryError")), "Memory Issue");
498
+ break;
499
+ case EPHIDGET_ACCESS:
500
+ rb_raise(rb_const_get(ph_error, rb_intern("AccessError")), "Access (Permission) Issue");
501
+ break;
502
+ case EPHIDGET_FAULT:
503
+ rb_raise(rb_const_get(ph_error, rb_intern("AddressError")), "Address Issue");
504
+ break;
505
+ case EPHIDGET_BUSY:
506
+ rb_raise(rb_const_get(ph_error, rb_intern("ResourceBusy")), "Resource Busy");
507
+ break;
508
+ case EPHIDGET_EXIST:
509
+ rb_raise(rb_const_get(ph_error, rb_intern("ObjectExists")), "Object Exists");
510
+ break;
511
+ case EPHIDGET_NOTDIR:
512
+ rb_raise(rb_const_get(ph_error, rb_intern("ObjectNotDirectory")), "Object is not a directory");
513
+ break;
514
+ case EPHIDGET_ISDIR:
515
+ rb_raise(rb_const_get(ph_error, rb_intern("ObjectIsDirectory")), "Object is a directory");
516
+ break;
517
+ case EPHIDGET_INVALID:
518
+ rb_raise(rb_const_get(ph_error, rb_intern("Invalid")), "Invalid");
519
+ break;
520
+ case EPHIDGET_NFILE:
521
+ rb_raise(rb_const_get(ph_error, rb_intern("TooManyOpenFilesInSystem")), "Too many open files in system");
522
+ break;
523
+ case EPHIDGET_MFILE:
524
+ rb_raise(rb_const_get(ph_error, rb_intern("TooManyOpenFiles")), "Too many open files");
525
+ break;
526
+ case EPHIDGET_NOSPC:
527
+ rb_raise(rb_const_get(ph_error, rb_intern("NoSpace")), "Not enough space");
528
+ break;
529
+ case EPHIDGET_FBIG:
530
+ rb_raise(rb_const_get(ph_error, rb_intern("FileTooBig")), "File too Big");
531
+ break;
532
+ case EPHIDGET_ROFS:
533
+ rb_raise(rb_const_get(ph_error, rb_intern("ReadOnlyFilesystem")), "Read Only Filesystem");
534
+ break;
535
+ case EPHIDGET_RO:
536
+ rb_raise(rb_const_get(ph_error, rb_intern("ReadOnlyObject")), "Read Only Object");
537
+ break;
538
+ case EPHIDGET_UNSUPPORTED:
539
+ rb_raise(rb_const_get(ph_error, rb_intern("OpNotSupported")), "Operation Not Supported");
540
+ break;
541
+ case EPHIDGET_INVALIDARG:
542
+ rb_raise(rb_const_get(ph_error, rb_intern("InvalidArg")), "Invalid Argument");
543
+ break;
544
+ case EPHIDGET_AGAIN:
545
+ rb_raise(rb_const_get(ph_error, rb_intern("TryAgain")), "Try again");
546
+ break;
547
+ case EPHIDGET_NOTEMPTY:
548
+ rb_raise(rb_const_get(ph_error, rb_intern("NotEmpty")), "Not Empty");
549
+ break;
550
+ case EPHIDGET_UNEXPECTED:
551
+ rb_raise(rb_const_get(ph_error, rb_intern("UnexpectedError")), "Unexpected Error");
552
+ break;
553
+ case EPHIDGET_DUPLICATE:
554
+ rb_raise(rb_const_get(ph_error, rb_intern("Duplicate")), "Duplicate");
555
+ break;
556
+ case EPHIDGET_BADPASSWORD:
557
+ rb_raise(rb_const_get(ph_error, rb_intern("BadCredential")), "Bad Credential");
558
+ break;
559
+ case EPHIDGET_NETUNAVAIL:
560
+ rb_raise(rb_const_get(ph_error, rb_intern("NetworkUnavailable")), "Network Unavailable");
561
+ break;
562
+ case EPHIDGET_CONNREF:
563
+ rb_raise(rb_const_get(ph_error, rb_intern("ConnectionRefused")), "Connection Refused");
564
+ break;
565
+ case EPHIDGET_CONNRESET:
566
+ rb_raise(rb_const_get(ph_error, rb_intern("ConnectionReset")), "Connection Reset");
567
+ break;
568
+ case EPHIDGET_HOSTUNREACH:
569
+ rb_raise(rb_const_get(ph_error, rb_intern("NoRouteToHost")), "No route to host");
570
+ break;
571
+ case EPHIDGET_NODEV:
572
+ rb_raise(rb_const_get(ph_error, rb_intern("NoSuchDevice")), "No Such Device");
573
+ break;
574
+ case EPHIDGET_WRONGDEVICE:
575
+ rb_raise(rb_const_get(ph_error, rb_intern("WrongDevice")), "Wrong Device");
576
+ break;
577
+ case EPHIDGET_PIPE:
578
+ rb_raise(rb_const_get(ph_error, rb_intern("BrokenPipe")), "Broken Pipe");
579
+ break;
580
+ case EPHIDGET_RESOLV:
581
+ rb_raise(rb_const_get(ph_error, rb_intern("NameResolutionError")), "Name Resolution Failure");
582
+ break;
583
+ case EPHIDGET_UNKNOWNVAL:
584
+ rb_raise(rb_const_get(ph_error, rb_intern("UnknownValue")), "Unknown or Invalid Value");
585
+ break;
586
+ case EPHIDGET_NOTATTACHED:
587
+ rb_raise(rb_const_get(ph_error, rb_intern("DeviceNotAttached")), "Device not Attached");
588
+ break;
589
+ case EPHIDGET_INVALIDPACKET:
590
+ rb_raise(rb_const_get(ph_error, rb_intern("InvalidPacket")), "Invalid or Unexpected Packet");
591
+ break;
592
+ case EPHIDGET_2BIG:
593
+ rb_raise(rb_const_get(ph_error, rb_intern("ArgListTooLong")), "Argument List Too Long");
594
+ break;
595
+ case EPHIDGET_BADVERSION:
596
+ rb_raise(rb_const_get(ph_error, rb_intern("BadVersion")), "Bad Version");
597
+ break;
598
+ case EPHIDGET_CLOSED:
599
+ rb_raise(rb_const_get(ph_error, rb_intern("Closed")), "Closed");
600
+ break;
601
+ case EPHIDGET_NOTCONFIGURED:
602
+ rb_raise(rb_const_get(ph_error, rb_intern("NotConfigured")), "Not Configured");
603
+ break;
604
+ case EPHIDGET_EOF:
605
+ rb_raise(rb_const_get(ph_error, rb_intern("EndOfFile")), "End of File");
606
+ break;
607
+ case EPHIDGET_NOTIMPLEMENTED:
608
+ rb_raise(rb_const_get(ph_error, rb_intern("NotImplemented")), "This functionality has not been implemented yet");
609
+ break;
610
+ default:
611
+ rb_raise(rb_const_get(ph_error, rb_intern("UnknownError")), "Unknown Error");
612
+ }
223
613
  }
224
- if(err_code == EPHIDGET_NOTIMPLEMENTED) {
225
- rb_raise(ph_errors[EPHIDGET_NOTIMPLEMENTED], "This functionality has not been implemented yet");
614
+ }
615
+
616
+
617
+ VALUE ph_get_instance_from_handle(PhidgetHandle ph_handle) {
618
+ VALUE ph_module = rb_const_get(rb_cModule, rb_intern("Phidgets"));
619
+ VALUE klass;
620
+ VALUE argv[0];
621
+ Phidget_ChannelClass ch_class;
622
+ Phidget_getChannelClass(ph_handle, &ch_class);
623
+
624
+ switch( ch_class ) {
625
+ case PHIDCHCLASS_ACCELEROMETER:
626
+ klass = rb_const_get(ph_module, rb_intern("Accelerometer"));
627
+ break;
628
+ case PHIDCHCLASS_BLDCMOTOR:
629
+ klass = rb_const_get(ph_module, rb_intern("BLDCMotor"));
630
+ break;
631
+ case PHIDCHCLASS_CAPACITIVETOUCH:
632
+ klass = rb_const_get(ph_module, rb_intern("CapacitiveTouch"));
633
+ break;
634
+ case PHIDCHCLASS_CURRENTINPUT:
635
+ klass = rb_const_get(ph_module, rb_intern("CurrentInput"));
636
+ break;
637
+ case PHIDCHCLASS_DCMOTOR:
638
+ klass = rb_const_get(ph_module, rb_intern("DCMotor"));
639
+ break;
640
+ case PHIDCHCLASS_DIGITALINPUT:
641
+ klass = rb_const_get(ph_module, rb_intern("DigitalInput"));
642
+ break;
643
+ case PHIDCHCLASS_DIGITALOUTPUT:
644
+ klass = rb_const_get(ph_module, rb_intern("DigitalOutput"));
645
+ break;
646
+ case PHIDCHCLASS_DISTANCESENSOR:
647
+ klass = rb_const_get(ph_module, rb_intern("DistanceSensor"));
648
+ break;
649
+ case PHIDCHCLASS_ENCODER:
650
+ klass = rb_const_get(ph_module, rb_intern("Encoder"));
651
+ break;
652
+ case PHIDCHCLASS_FREQUENCYCOUNTER:
653
+ klass = rb_const_get(ph_module, rb_intern("FrequencyCounter"));
654
+ break;
655
+ case PHIDCHCLASS_GPS:
656
+ klass = rb_const_get(ph_module, rb_intern("GPS"));
657
+ break;
658
+ case PHIDCHCLASS_GYROSCOPE:
659
+ klass = rb_const_get(ph_module, rb_intern("Gyroscope"));
660
+ break;
661
+ case PHIDCHCLASS_HUB:
662
+ klass = rb_const_get(ph_module, rb_intern("Hub"));
663
+ break;
664
+ case PHIDCHCLASS_HUMIDITYSENSOR:
665
+ klass = rb_const_get(ph_module, rb_intern("HumiditySensor"));
666
+ break;
667
+ case PHIDCHCLASS_IR:
668
+ klass = rb_const_get(ph_module, rb_intern("IR"));
669
+ break;
670
+ case PHIDCHCLASS_LCD:
671
+ klass = rb_const_get(ph_module, rb_intern("LCD"));
672
+ break;
673
+ case PHIDCHCLASS_LIGHTSENSOR:
674
+ klass = rb_const_get(ph_module, rb_intern("LightSensor"));
675
+ break;
676
+ case PHIDCHCLASS_MAGNETOMETER:
677
+ klass = rb_const_get(ph_module, rb_intern("Magnetometer"));
678
+ break;
679
+ case PHIDCHCLASS_MOTORPOSITIONCONTROLLER:
680
+ klass = rb_const_get(ph_module, rb_intern("MotorPositionController"));
681
+ break;
682
+ case PHIDCHCLASS_PHSENSOR:
683
+ klass = rb_const_get(ph_module, rb_intern("PHSensor"));
684
+ break;
685
+ case PHIDCHCLASS_POWERGUARD:
686
+ klass = rb_const_get(ph_module, rb_intern("PowerGuard"));
687
+ break;
688
+ case PHIDCHCLASS_PRESSURESENSOR:
689
+ klass = rb_const_get(ph_module, rb_intern("PressureSensor"));
690
+ break;
691
+ case PHIDCHCLASS_RCSERVO:
692
+ klass = rb_const_get(ph_module, rb_intern("RCServo"));
693
+ break;
694
+ case PHIDCHCLASS_RESISTANCEINPUT:
695
+ klass = rb_const_get(ph_module, rb_intern("ResistanceInput"));
696
+ break;
697
+ case PHIDCHCLASS_RFID:
698
+ klass = rb_const_get(ph_module, rb_intern("RFID"));
699
+ break;
700
+ case PHIDCHCLASS_SOUNDSENSOR:
701
+ klass = rb_const_get(ph_module, rb_intern("SoundSensor"));
702
+ break;
703
+ case PHIDCHCLASS_SPATIAL:
704
+ klass = rb_const_get(ph_module, rb_intern("Spatial"));
705
+ break;
706
+ case PHIDCHCLASS_STEPPER:
707
+ klass = rb_const_get(ph_module, rb_intern("Stepper"));
708
+ break;
709
+ case PHIDCHCLASS_TEMPERATURESENSOR:
710
+ klass = rb_const_get(ph_module, rb_intern("TemperatureSensor"));
711
+ break;
712
+ case PHIDCHCLASS_VOLTAGEINPUT:
713
+ klass = rb_const_get(ph_module, rb_intern("VoltageInput"));
714
+ break;
715
+ case PHIDCHCLASS_VOLTAGEOUTPUT:
716
+ klass = rb_const_get(ph_module, rb_intern("VoltageOutput"));
717
+ break;
718
+ case PHIDCHCLASS_VOLTAGERATIOINPUT:
719
+ klass = rb_const_get(ph_module, rb_intern("VoltageRatioInput"));
720
+ break;
721
+ case PHIDCHCLASS_DICTIONARY:
722
+ klass = rb_const_get(ph_module, rb_intern("Dictionary"));
723
+ break;
724
+ default:
725
+ klass = Qnil;
226
726
  }
727
+
728
+ return rb_class_new_instance(0, argv, klass);
227
729
  }
228
730
 
229
- VALUE ph_get_library_version(VALUE self) {
230
- const char *lib_version;
231
- ph_raise(CPhidget_getLibraryVersion(&lib_version));
232
- return rb_str_new2(lib_version);
731
+
732
+ VALUE ph_get_int(PhidgetHandle handle, PhidgetReturnCode (*func)(PhidgetHandle, int *))
733
+ {
734
+ int value;
735
+ ph_raise(func(handle, &value));
736
+ return INT2NUM(value);
233
737
  }
234
738
 
235
- VALUE ph_enable_logging(VALUE self, VALUE level, VALUE output_file) {
236
- ph_raise(CPhidget_enableLogging(FIX2INT(level), StringValueCStr(output_file)));
237
- return Qnil;
739
+
740
+ VALUE ph_get_uint(PhidgetHandle handle, PhidgetReturnCode (*func)(PhidgetHandle, uint32_t *))
741
+ {
742
+ uint32_t value;
743
+ ph_raise(func(handle, &value));
744
+ return UINT2NUM(value);
238
745
  }
239
746
 
240
- VALUE ph_disable_logging(VALUE self) {
241
- ph_raise(CPhidget_disableLogging());
242
- return Qnil;
747
+
748
+ VALUE ph_get_int64(PhidgetHandle handle, PhidgetReturnCode (*func)(PhidgetHandle, int64_t *))
749
+ {
750
+ int64_t value;
751
+ ph_raise(func(handle, &value));
752
+ return LL2NUM(value);
243
753
  }
244
754
 
245
- VALUE ph_log(VALUE self, VALUE level, VALUE msg_id, VALUE message) {
246
- ph_raise(CPhidget_log(FIX2INT(level), StringValueCStr(msg_id), StringValueCStr(message)));
247
- return Qnil;
755
+
756
+ VALUE ph_get_uint64(PhidgetHandle handle, PhidgetReturnCode (*func)(PhidgetHandle, uint64_t *))
757
+ {
758
+ uint64_t value;
759
+ ph_raise(func(handle, &value));
760
+ return ULL2NUM(value);
761
+ }
762
+
763
+
764
+ VALUE ph_get_bool(PhidgetHandle handle, PhidgetReturnCode (*func)(PhidgetHandle, int *))
765
+ {
766
+ int value;
767
+ ph_raise(func(handle, &value));
768
+ return value == PTRUE ? Qtrue : Qfalse;
769
+ }
770
+
771
+
772
+ VALUE ph_get_double(PhidgetHandle handle, PhidgetReturnCode (*func)(PhidgetHandle, double *))
773
+ {
774
+ double value;
775
+ ph_raise(func(handle, &value));
776
+ return DBL2NUM(value);
777
+ }
778
+
779
+
780
+ VALUE ph_get_string(PhidgetHandle handle, PhidgetReturnCode (*func)(PhidgetHandle, const char **))
781
+ {
782
+ const char *value;
783
+ ph_raise(func(handle, &value));
784
+ if(value == NULL) return Qnil;
785
+ return rb_str_new2(value);
248
786
  }
249
787
 
250
788
 
251
- #ifdef PH_CALLBACK
252
789
  void ph_callback_thread(ph_callback_data_t *callback_data) {
253
790
  while(! callback_data->exit) {
254
- #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
255
791
  rb_thread_call_without_gvl(wait_for_callback, (void *)callback_data, cancel_wait_for_callback, (void *)callback_data);
256
- #else
257
- rb_thread_blocking_region(wait_for_callback, (void *)callback_data, cancel_wait_for_callback, (void *)callback_data);
258
- #endif
259
- if(TYPE(callback_data->callback) != T_NIL) rb_funcall(callback_data->callback, rb_intern("call"), 1, callback_data->phidget);
260
- callback_data->called = false;
792
+ if(TYPE(callback_data->callback) != T_NIL) rb_funcall(callback_data->callback, rb_intern("call"), 5, callback_data->phidget, callback_data->arg1, callback_data->arg2, callback_data->arg3, callback_data->arg4);
261
793
  };
262
794
  }
263
795
 
264
- ph_callback_return_t wait_for_callback(void *arg) {
796
+ void *wait_for_callback(void *arg) {
265
797
  ph_callback_data_t *callback_data = (ph_callback_data_t *)arg;
266
798
  while(! callback_data->exit) {
267
- usleep(PH_CALLBACK_POLLING_INTERVAL);
268
- if(callback_data->called) return (ph_callback_return_t)Qnil;
799
+ sem_post(&callback_data->handler_ready);
800
+ while(sem_wait(&callback_data->callback_called)!=0) {};
801
+ return (void *)Qnil;
269
802
  };
270
- return (ph_callback_return_t)Qnil;
803
+ return (void *)Qnil;
271
804
  }
272
805
 
273
806
  void cancel_wait_for_callback(void *arg) {
274
807
  ph_callback_data_t *callback_data = (ph_callback_data_t *)arg;
808
+ callback_data->callback = T_NIL;
275
809
  callback_data->exit = true;
810
+ sem_post(&callback_data->handler_ready);
811
+ sem_post(&callback_data->callback_called);
276
812
  }
277
- #endif
278
813