phidgets 0.0.4 → 0.0.5

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.0.5 2010-10-28
2
+ * Added Manager class
3
+ * Added phidget executable
4
+ * Fixed a few bugs in the RFID class, but it is still untested.
5
+
1
6
  == 0.0.4 2010-09-10
2
7
  * Updated for compatability with Ruby 1.9
3
8
  * Removed all support for callbacks
data/Manifest.txt CHANGED
@@ -5,7 +5,10 @@ PostInstall.txt
5
5
  README.txt
6
6
  README.rdoc
7
7
  Rakefile
8
+ bin/phidget
8
9
  lib/phidgets.rb
10
+ lib/phidgets/phidgets.rb
11
+ lib/phidgets/manager.rb
9
12
  lib/phidgets/common.rb
10
13
  lib/phidgets/interfacekit.rb
11
14
  lib/phidgets/rfid.rb
data/README.rdoc CHANGED
@@ -13,7 +13,7 @@ This gem provides a ruby interface to the phidgets library.
13
13
  * The gem has been tested to work on both Linux and Windows.
14
14
  * Not all the devices have been implemented, and not all of the devices that have been implemented have been fully tested.
15
15
  * The gem will attempt to guess the name of the phidgets library based on the platform it is run on (Linux, Windows or OS X).
16
- If it guessesincorrectly please leave a message to let me know what your platform sets for Config::CONFIG['target_os'] and
16
+ If it guesses incorrectly please leave a message to let me know what your platform sets for Config::CONFIG['target_os'] and
17
17
  what is the name of the phidgets library.
18
18
 
19
19
  == SYNOPSIS:
@@ -34,6 +34,33 @@ This gem provides a ruby interface to the phidgets library.
34
34
  end
35
35
 
36
36
 
37
+ The gem now installs a command line program that will list all phidgets devices that are attached, as well as allowing any
38
+ valid method for a given phidget type to be called. For example:
39
+
40
+ To list all phidgets attached to the local computer:
41
+ => phidget list
42
+ ----------------------------------------------------------------------
43
+ | SerialNumber | Device Name |
44
+ ----------------------------------------------------------------------
45
+ | 73723 | Phidget InterfaceKit 0/0/8 |
46
+ | 88103 | Phidget InterfaceKit 0/0/4 |
47
+ ----------------------------------------------------------------------
48
+
49
+ To list all phidgets attached to a remote computer:
50
+ => phidget 192.168.100.67 list
51
+ ----------------------------------------------------------------------
52
+ | SerialNumber | Device Name |
53
+ ----------------------------------------------------------------------
54
+ | 73782 | Phidget InterfaceKit 0/0/8 |
55
+ ----------------------------------------------------------------------
56
+
57
+ To call a method for a specific local phidget:
58
+ => phidget 73723 setOutputState 0 1
59
+
60
+ To call a method for a specific remote phidget:
61
+ => phidget 192.168.100.67:73782 setOuputState 2 0
62
+
63
+
37
64
  == REQUIREMENTS:
38
65
 
39
66
  * The Phidgets library (http://www.phidgets.com/)
data/README.txt CHANGED
@@ -13,7 +13,7 @@ This gem provides a ruby interface to the phidgets library.
13
13
  * The gem has been tested to work on both Linux and Windows.
14
14
  * Not all the devices have been implemented, and not all of the devices that have been implemented have been fully tested.
15
15
  * The gem will attempt to guess the name of the phidgets library based on the platform it is run on (Linux, Windows or OS X).
16
- If it guessesincorrectly please leave a message to let me know what your platform sets for Config::CONFIG['target_os'] and
16
+ If it guesses incorrectly please leave a message to let me know what your platform sets for Config::CONFIG['target_os'] and
17
17
  what is the name of the phidgets library.
18
18
 
19
19
  == SYNOPSIS:
@@ -34,6 +34,32 @@ This gem provides a ruby interface to the phidgets library.
34
34
  end
35
35
 
36
36
 
37
+ The gem now installs a command line program that will list all phidgets devices that are attached, as well as allowing any
38
+ valid method for a given phidget type to be called. For example:
39
+
40
+ To list all phidgets attached to the local computer:
41
+ => phidget list
42
+ ----------------------------------------------------------------------
43
+ | SerialNumber | Device Name |
44
+ ----------------------------------------------------------------------
45
+ | 73723 | Phidget InterfaceKit 0/0/8 |
46
+ | 88103 | Phidget InterfaceKit 0/0/4 |
47
+ ----------------------------------------------------------------------
48
+
49
+ To list all phidgets attached to a remote computer:
50
+ => phidget 192.168.100.67 list
51
+ ----------------------------------------------------------------------
52
+ | SerialNumber | Device Name |
53
+ ----------------------------------------------------------------------
54
+ | 73782 | Phidget InterfaceKit 0/0/8 |
55
+ ----------------------------------------------------------------------
56
+
57
+ To call a method for a specific local phidget:
58
+ => phidget 73723 setOutputState 0 1
59
+
60
+ To call a method for a specific remote phidget:
61
+ => phidget 192.168.100.67:73782 setOuputState 2 0
62
+
37
63
  == REQUIREMENTS:
38
64
 
39
65
  * The Phidgets library (http://www.phidgets.com/)
data/bin/phidget ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'phidgets'
5
+
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 setOutputState 0 1'
16
+ $stdout.puts ' phidget 34619 getDeviceName'
17
+ end
18
+
19
+ begin
20
+ list = false
21
+ host = nil
22
+ id = nil
23
+
24
+ case ARGV[0]
25
+ when /^(-1|\d+)$/
26
+ id = $1.to_i
27
+ when /^(\w|.+):(-1|\d+)$/
28
+ host = $1
29
+ id = $2.to_i
30
+ when /^list$/i
31
+ list = true
32
+ when /^(\w|.+)$/
33
+ if ARGV[1].downcase == 'list'
34
+ list = true
35
+ host = $1
36
+ else
37
+ raise "Invalid Arguments."
38
+ end
39
+ else
40
+ raise "Invalid Arguments."
41
+ end
42
+
43
+ manager = Phidgets::Manager.new
44
+
45
+ if host
46
+ manager.openRemoteIP(host)
47
+ else
48
+ manager.open
49
+ end
50
+
51
+ devices = manager.getAttachedDevices
52
+ manager.close
53
+
54
+ if devices.count == 0
55
+ $stdout.puts
56
+ $stdout.puts 'There are no phidgets attached.'
57
+ $stdout.puts
58
+ exit
59
+ end
60
+
61
+ if list
62
+ $stdout.puts
63
+ $stdout.puts "----------------------------------------------------------------------"
64
+ $stdout.puts "| SerialNumber | Device Name |"
65
+ $stdout.puts "----------------------------------------------------------------------"
66
+ devices.each_pair { |serial,phidget|
67
+ d_str = "| #{serial}"
68
+ d_str += " " * (24 - d_str.length)
69
+ d_str += "| #{phidget.getDeviceName}"
70
+ d_str += " " * (69 - d_str.length) + "|"
71
+ $stdout.puts d_str
72
+ }
73
+ $stdout.puts "----------------------------------------------------------------------"
74
+ $stdout.puts
75
+
76
+ else
77
+ phidget = id==-1 ? devices.first[1] : devices[id]
78
+
79
+ $stdout.puts case ARGV.count
80
+ when 2
81
+ phidget.send(ARGV[1])
82
+ when 3
83
+ phidget.send(ARGV[1], ARGV[2])
84
+ when 4
85
+ phidget.send(ARGV[1], ARGV[2], ARGV[3])
86
+ else
87
+ raise "Invalid Arguments."
88
+ end
89
+ end
90
+
91
+ rescue SystemExit
92
+ rescue Exception => e
93
+ $stdout.puts "#{e}\n#{e.backtrace.join("\n")}"
94
+ $stdout.puts
95
+ usage
96
+ $stdout.puts
97
+ end
98
+
data/lib/phidgets.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
+ require File.dirname(__FILE__) + '/phidgets/phidgets.rb'
4
5
  require File.dirname(__FILE__) + '/phidgets/common.rb'
5
6
  require File.dirname(__FILE__) + '/phidgets/interfacekit.rb'
6
7
  require File.dirname(__FILE__) + '/phidgets/rfid.rb'
7
8
  require File.dirname(__FILE__) + '/phidgets/servo.rb'
9
+ require File.dirname(__FILE__) + '/phidgets/manager.rb'
8
10
 
9
11
  module Phidgets
10
- VERSION = '0.0.4'
12
+ VERSION = '0.0.5'
11
13
  end
@@ -1,247 +1,37 @@
1
1
 
2
- require 'dl'
3
- require 'dl/import'
4
- require 'rbconfig'
5
-
6
-
7
2
  module Phidgets
8
3
 
9
- if RUBY_VERSION < "1.9"
10
- extend DL::Importable
11
- SIZEOF_INT = DL.sizeof('I')
12
- SIZEOF_VOIDP = DL.sizeof('P')
13
- SIZEOF_DOUBLE = DL.sizeof('D')
14
- FUNCTION_PREFIX = 'c'
15
- def Phidgets.malloc size
16
- DL.malloc(size)
17
- end
18
- else
19
- extend DL::Importer
20
- SIZEOF_INT = DL::SIZEOF_INT
21
- SIZEOF_VOIDP = DL::SIZEOF_VOIDP
22
- SIZEOF_DOUBLE = DL::SIZEOF_DOUBLE
23
- FUNCTION_PREFIX = 'C'
24
- def Phidgets.malloc size
25
- DL::CPtr.malloc(size)
26
- end
27
- end
28
-
29
- PFALSE = 0
30
- PTRUE = 1
31
-
32
- NOTATTACHED = 0
33
- ATTACHED = 1
34
-
35
- CLASS_NOTHING = 1
36
- CLASS_ACCELEROMETER = 2
37
- CLASS_ADVANCEDSERVO = 3
38
- CLASS_ENCODER = 4
39
- CLASS_GPS = 5
40
- CLASS_GYROSCOPE = 6
41
- CLASS_INTERFACEKIT = 7
42
- CLASS_LED = 8
43
- CLASS_MOTORCONTROL = 9
44
- CLASS_PHSENSOR = 10
45
- CLASS_RFID = 11
46
- CLASS_SERVO = 12
47
- CLASS_STEPPER = 13
48
- CLASS_TEMPERATURESENSOR = 14
49
- CLASS_TEXTLCD = 15
50
- CLASS_TEXTLED = 16
51
- CLASS_WEIGHTSENSOR = 17
52
-
53
- ID_ACCELEROMETER_2AXIS = 0x071
54
- ID_ACCELEROMETER_3AXIS = 0x07E
55
- ID_ADVANCEDSERVO_8MOTOR = 0x03A
56
- ID_BIPOLAR_STEPPER_1MOTOR = 0x07B
57
- ID_ENCODER_1ENCODER_1INPUT = 0x04B
58
- ID_ENCODER_HS_1ENCODER = 0x080
59
- ID_INTERFACEKIT_0_0_4 = 0x040
60
- ID_INTERFACEKIT_0_0_8 = 0x081
61
- ID_INTERFACEKIT_0_16_16 = 0x044
62
- ID_INTERFACEKIT_8_8_8 = 0x045
63
- ID_INTERFACEKIT_8_8_8_w_LCD = 0x07D
64
- ID_LED_64 = 0x04A
65
- ID_LINEAR_TOUCH = 0x076
66
- ID_MOTORCONTROL_HC_2MOTOR = 0x059
67
- ID_MOTORCONTROL_LV_2MOTOR_4INPUT = 0x058
68
- ID_PHSENSOR = 0x074
69
- ID_RFID_2OUTPUT = 0x031
70
- ID_ROTARY_TOUCH = 0x077
71
- ID_SERVO_1MOTOR = 0x039
72
- ID_TEMPERATURESENSOR = 0x070
73
- ID_TEXTLCD_2x20_w_8_8_8 = 0x17D
74
- ID_UNIPOLAR_STEPPER_4MOTOR = 0x07A
75
- ID_INTERFACEKIT_0_8_8_w_LCD = 0x053
76
- ID_INTERFACEKIT_4_8_8 = 0x004
77
- ID_RFID = 0x030
78
- ID_SERVO_1MOTOR_OLD = 0x002
79
- ID_SERVO_4MOTOR = 0x038
80
- ID_SERVO_4MOTOR_OLD = 0x003
81
- ID_TEXTLCD_2x20 = 0x052
82
- ID_TEXTLCD_2x20_w_0_8_8 = 0x153
83
- ID_TEXTLED_1x8 = 0x049
84
- ID_TEXTLED_4x8 = 0x048
85
- ID_WEIGHTSENSOR = 0x072
86
-
87
- PHIDGET_LOG_CRITICAL = 1
88
- PHIDGET_LOG_ERROR = 2
89
- PHIDGET_LOG_WARNING = 3
90
- PHIDGET_LOG_DEBUG = 4
91
- PHIDGET_LOG_INFO = 5
92
- PHIDGET_LOG_VERBOSE = 6
93
-
94
- class Exception < RuntimeError
95
- attr_reader :code
96
-
97
- EPHIDGET_LOAD_LIB_FAIL = -2
98
- EPHIDGET_LIBNAME = -1
99
- EPHIDGET_NOTFOUND = 1
100
- EPHIDGET_NOMEMORY = 2
101
- EPHIDGET_UNEXPECTED = 3
102
- EPHIDGET_INVALIDARG = 4
103
- EPHIDGET_NOTATTACHED = 5
104
- EPHIDGET_INTERRUPTED = 6
105
- EPHIDGET_INVALID = 7
106
- EPHIDGET_NETWORK = 8
107
- EPHIDGET_UNKNOWNVAL = 9
108
- EPHIDGET_BADPASSWORD = 10
109
- EPHIDGET_UNSUPPORTED = 11
110
- EPHIDGET_DUPLICATE = 12
111
- EPHIDGET_TIMEOUT = 13
112
- EPHIDGET_OUTOFBOUNDS = 14
113
- EPHIDGET_EVENT = 15
114
- EPHIDGET_NETWORK_NOTCONNECTED = 16
115
- EPHIDGET_WRONGDEVICE = 17
116
- EPHIDGET_CLOSED = 18
117
- EPHIDGET_BADVERSION = 19
118
-
119
- def initialize(code)
120
- @code = code
121
- case code
122
- when EPHIDGET_LOAD_LIB_FAIL
123
- super('Failed to load Phidgets Library')
124
- when EPHIDGET_LIBNAME
125
- super('Unable to determine Phidgets Library name.')
126
- when EPHIDGET_NOTFOUND
127
- super('A Phidget matching the type and or serial number could not be found.')
128
- when EPHIDGET_NOMEMORY
129
- super('Memory could not be allocated.')
130
- when EPHIDGET_UNEXPECTED
131
- super('Unexpected Error. Contact Phidgets Inc. for support.')
132
- when EPHIDGET_INVALIDARG
133
- super('Invalid argument passed to function.')
134
- when EPHIDGET_NOTATTACHED
135
- super('Phidget not physically attached.')
136
- when EPHIDGET_INTERRUPTED
137
- super('Read/Write operation was interrupted.')
138
- when EPHIDGET_INVALID
139
- super('The Error Code is not defined.')
140
- when EPHIDGET_NETWORK
141
- super('Network Error.')
142
- when EPHIDGET_UNKNOWNVAL
143
- super('Value is Unknown (State not yet received from device, or not yet set by user).')
144
- when EPHIDGET_BADPASSWORD
145
- super('Authorization Failed.')
146
- when EPHIDGET_UNSUPPORTED
147
- super('Not Supported.')
148
- when EPHIDGET_DUPLICATE
149
- super('Duplicated request.')
150
- when EPHIDGET_TIMEOUT
151
- super('Given timeout has been exceeded.')
152
- when EPHIDGET_OUTOFBOUNDS
153
- super('Index out of Bounds.')
154
- when EPHIDGET_EVENT
155
- super('A non-null error code was returned from an event handler.')
156
- when EPHIDGET_NETWORK_NOTCONNECTED
157
- super('A connection to the server does not exist.')
158
- when EPHIDGET_WRONGDEVICE
159
- super('Function is not applicable for this device.')
160
- when EPHIDGET_CLOSED
161
- super('Phidget handle was closed.')
162
- when EPHIDGET_BADVERSION
163
- super("Webservice and Client protocol versions don't match. Update to newest release.")
164
- end
165
- end
166
-
167
- end
168
-
169
- begin
170
- case Config::CONFIG['target_os']
171
- when /linux/
172
- dlload 'libphidget21.so'
173
- when /mswin/, /mingw/
174
- dlload 'phidget21.dll'
175
- when /darwin/
176
- dlload '/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21'
177
- else
178
- raise Phidgets::Exception.new(Exception::EPHIDGET_LIBNAME)
179
- end
180
- rescue
181
- raise Phidgets::Exception.new(Exception::EPHIDGET_LOAD_LIB_FAIL)
182
- end
183
-
4
+ extern "int CPhidget_open(void *, int)"
184
5
  extern "int CPhidget_openRemote(void *, int, void *, void *)"
185
6
  extern "int CPhidget_openRemoteIP(void *, int, void *, int, void *)"
186
- extern "int CPhidget_open(void *, int)"
187
7
  extern "int CPhidget_close(void *)"
188
8
  extern "int CPhidget_delete(void *)"
189
9
  extern "int CPhidget_getDeviceName(void *, void *)"
190
10
  extern "int CPhidget_getSerialNumber(void *, int *)"
191
11
  extern "int CPhidget_getDeviceVersion(void *, int *)"
192
12
  extern "int CPhidget_getDeviceStatus(void *, int *)"
193
- extern "int CPhidget_getLibraryVersion(void *)"
194
13
  extern "int CPhidget_getDeviceType(void *, void *)"
195
14
  extern "int CPhidget_getDeviceLabel(void *, void *)"
196
15
  extern "int CPhidget_setDeviceLabel(void *, void *)"
197
- extern "int CPhidget_getErrorDescription(int, void *)"
198
16
  extern "int CPhidget_waitForAttachment(void *, int)"
199
17
  extern "int CPhidget_getServerID(void *, void *)"
200
18
  extern "int CPhidget_getServerAddress(void *, void *, int *)"
201
19
  extern "int CPhidget_getServerStatus(void *, int *)"
202
20
  extern "int CPhidget_getDeviceID(void *, int *)"
203
21
  extern "int CPhidget_getDeviceClass(void *, int *)"
204
- extern "int CPhidget_enableLogging(int, char *)"
205
- extern "int CPhidget_disableLogging()"
206
-
207
- # Gets the library version. This contains a version number and a build date.
208
- def Phidgets.getLibraryVersion
209
- ptr = malloc(SIZEOF_VOIDP)
210
- r = self.send(FUNCTION_PREFIX + 'Phidget_getLibraryVersion', ptr.ref)
211
- raise Phidgets::Exception.new(r) if r != 0
212
- ptr.free = nil
213
- ptr.to_s
214
- end
215
-
216
- # Gets the description for an error code.
217
- def Phidgets.getErrorDescription(error_code)
218
- ptr = malloc(SIZEOF_VOIDP)
219
- r = self.send(FUNCTION_PREFIX + 'Phidget_getErrorDescription', error_code, ptr.ref)
220
- raise Phidgets::Exception.new(r) if r != 0
221
- ptr.free = nil
222
- ptr.to_s
223
- end
224
-
225
- # Enables logging. Logging is provided mainly for debugging purposes. Enabling logging will output internal library
226
- # information that can be used to find bugs with the help of Phidgetd Inc. Alternatively, the user can enable
227
- # and write to the log for their own uses.
228
- # === Parameters
229
- # * _level_ = The highest level of logging to output. All lower levels will also be output.
230
- # * _file_ = File to output log to. This should be a full pathname, not a relative pathname.
231
- def Phidgets.enableLogging(level, file)
232
- r = self.send(FUNCTION_PREFIX + 'Phidget_enableLogging', level, file)
233
- raise Phidgets::Exception.new(r) if r != 0
234
- end
235
-
236
- # Disables logging.
237
- def Phidgets.disableLogging
238
- r = self.send(FUNCTION_PREFIX + 'Phidget_disableLogging')
239
- raise Phidgets::Exception.new(r) if r != 0
240
- end
241
-
242
22
 
243
23
  class Common
244
24
 
25
+ # Opens a Phidget.
26
+ # === Parameters
27
+ # * _serial_number_ = Serial number. Specify -1 to open any.
28
+ # * _timeout_ = Time to wait for attachment. Specify 0 to not wait.
29
+ def open(serial_number=-1, timeout=0)
30
+ r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_open', @handle, serial_number.to_i)
31
+ raise Phidgets::Exception.new(r) if r != 0
32
+ waitForAttachment(timeout) if timeout > 0
33
+ end
34
+
245
35
  # Opens a Phidget remotely by ServerID. Note that this requires Bonjour (mDNS) to be running on both the host and the server.
246
36
  # === Parameters
247
37
  # * _serial_number_ = Serial number. Specify -1 to open any.
@@ -249,7 +39,7 @@ module Phidgets
249
39
  # * _password_ = Password. Can be nil if the server is running unsecured.
250
40
  # * _timeout_ = Time to wait for attachment. Specify 0 to not wait.
251
41
  def openRemote(serial_number=-1, server=nil, password=nil, timeout=0)
252
- r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_openRemote', @handle, serial_number, server, password)
42
+ r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_openRemote', @handle, serial_number.to_i, server, password)
253
43
  raise Phidgets::Exception.new(r) if r != 0
254
44
  waitForAttachment(timeout) if timeout > 0
255
45
  end
@@ -262,17 +52,7 @@ module Phidgets
262
52
  # * _password_ = Password. Can be nil if the server is running unsecured.
263
53
  # * _timeout_ = Time to wait for attachment. Specify 0 to not wait.
264
54
  def openRemoteIP(serial_number, address, port=5001, password=nil, timeout=0)
265
- r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_openRemoteIP', @handle, serial_number, address, port, password)
266
- raise Phidgets::Exception.new(r) if r != 0
267
- waitForAttachment(timeout) if timeout > 0
268
- end
269
-
270
- # Opens a Phidget.
271
- # === Parameters
272
- # * _serial_number_ = Serial number. Specify -1 to open any.
273
- # * _timeout_ = Time to wait for attachment. Specify 0 to not wait.
274
- def open(serial_number=-1, timeout=0)
275
- r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_open', @handle, serial_number)
55
+ r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_openRemoteIP', @handle, serial_number.to_i, address, port.to_i, password)
276
56
  raise Phidgets::Exception.new(r) if r != 0
277
57
  waitForAttachment(timeout) if timeout > 0
278
58
  end
@@ -356,7 +136,7 @@ module Phidgets
356
136
  # === Parameters
357
137
  # * _timeout_ = Time to wait for the attachment. Specify 0 to wait forever.
358
138
  def waitForAttachment(timeout)
359
- r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_waitForAttachment', @handle, timeout)
139
+ r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_waitForAttachment', @handle, timeout.to_i)
360
140
  raise Phidgets::Exception.new(r) if r != 0
361
141
  end
362
142
 
@@ -17,7 +17,7 @@ module Phidgets
17
17
 
18
18
  class InterfaceKit < Common
19
19
 
20
- # Create a new interface kit object.
20
+ # Create a new InterfaceKit object.
21
21
  # === Parameters
22
22
  # * _serial_number_ = Serial number of the phidget board to open. Specify -1 to open any.
23
23
  # * _timeout_ = Time to wait for attachment. Specify 0 to not call open.
@@ -41,7 +41,7 @@ module Phidgets
41
41
  # * _index_ = The input index.
42
42
  def getInputState(index)
43
43
  state = Phidgets.malloc(SIZEOF_INT)
44
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getInputState', @handle, index, state.ref)
44
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getInputState', @handle, index.to_i, state.ref)
45
45
  raise Phidgets::Exception.new(r) if r != 0
46
46
  state.free = nil
47
47
  state.to_i
@@ -61,7 +61,7 @@ module Phidgets
61
61
  # * _index_ = The output index.
62
62
  def getOutputState(index)
63
63
  state = Phidgets.malloc(SIZEOF_INT)
64
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getOutputState', @handle, index, state.ref)
64
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getOutputState', @handle, index.to_i, state.ref)
65
65
  raise Phidgets::Exception.new(r) if r != 0
66
66
  state.free = nil
67
67
  state.to_i
@@ -70,9 +70,9 @@ module Phidgets
70
70
  # Sets the state of a digital output.
71
71
  # === Parameters
72
72
  # * _index_ = The output index.
73
- # * _state_ = The output state. Possible values are PTRUE and PFALSE.
73
+ # * _state_ = The output state. Possible values are PTRUE and PFALSE.
74
74
  def setOutputState(index, state)
75
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_setOutputState', @handle, index, state)
75
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_setOutputState', @handle, index.to_i, state.to_i)
76
76
  raise Phidgets::Exception.new(r) if r != 0
77
77
  end
78
78
 
@@ -90,7 +90,7 @@ module Phidgets
90
90
  # * _index_ = The sensor index.
91
91
  def getSensorValue(index)
92
92
  state = Phidgets.malloc(SIZEOF_INT)
93
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getSensorValue', @handle, index, state.ref)
93
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getSensorValue', @handle, index.to_i, state.ref)
94
94
  raise Phidgets::Exception.new(r) if r != 0
95
95
  state.free = nil
96
96
  state.to_i
@@ -101,7 +101,7 @@ module Phidgets
101
101
  # * _index_ = The sensor index.
102
102
  def getSensorRawValue(index)
103
103
  state = Phidgets.malloc(SIZEOF_INT)
104
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getSensorRawValue', @handle, index, state.ref)
104
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getSensorRawValue', @handle, index.to_i, state.ref)
105
105
  raise Phidgets::Exception.new(r) if r != 0
106
106
  state.free = nil
107
107
  state.to_i
@@ -120,7 +120,7 @@ module Phidgets
120
120
  # === Parameters
121
121
  # * _ratiometric_ = The ratiometric state. Possible values are PTRUE and PFALSE.
122
122
  def setRatiometric(ratiometric)
123
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_setRatiometric', @handle, ratiometric)
123
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_setRatiometric', @handle, ratiometric.to_i)
124
124
  raise Phidgets::Exception.new(r) if r != 0
125
125
  end
126
126
 
@@ -0,0 +1,132 @@
1
+
2
+ module Phidgets
3
+
4
+ extern "int CPhidgetManager_create(void *)"
5
+ extern "int CPhidgetManager_open(void *)"
6
+ extern "int CPhidgetManager_close(void *)"
7
+ extern "int CPhidgetManager_delete(void *)"
8
+ extern "int CPhidgetManager_getAttachedDevices(void *, void *, int *)"
9
+ extern "int CPhidgetManager_freeAttachedDevicesArray(void *)"
10
+ extern "int CPhidgetManager_openRemote(void *, void *, void *)"
11
+ extern "int CPhidgetManager_openRemoteIP(void *, char *, int, void *)"
12
+
13
+
14
+ class Manager
15
+
16
+ # Creates a new Manager object.
17
+ def initialize
18
+ @server = nil
19
+ @port = nil
20
+ @password = nil
21
+ @handle = Phidgets.malloc(SIZEOF_VOIDP)
22
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetManager_create', @handle.ref)
23
+ raise Phidgets::Exception.new(r) if r != 0
24
+ end
25
+
26
+ # Opens a Manager.
27
+ def open
28
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetManager_open', @handle)
29
+ raise Phidgets::Exception.new(r) if r != 0
30
+
31
+ # a delay is required between the time the manager is opened and when it is used, otherwise it will report that no phidgets are attached. there really should be a better way.
32
+ sleep 1
33
+ end
34
+
35
+ # Opens a Manager remotely by ServerID. Note that this requires Bonjour (mDNS) to be running on both the host and the server.
36
+ # === Parameters
37
+ # * _server_ = Server ID. Specify nil to open any.
38
+ # * _password_ = Password. Can be nil if the server is running unsecured.
39
+ def openRemote(server=nil, password=nil)
40
+ @server = server
41
+ @password = password
42
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetManager_openRemote', @handle, server, password)
43
+ raise Phidgets::Exception.new(r) if r != 0
44
+
45
+ # a delay is required between the time the manager is opened and when it is used, otherwise it will report that no phidgets are attached. there really should be a better way.
46
+ sleep 2
47
+ end
48
+
49
+ # Opens a Manager remotely by address and port.
50
+ # === Parameters
51
+ # * _address_ = Address. This can be a hostname or IP address.
52
+ # * _port_ = Port number. Default is 5001.
53
+ # * _password_ = Password. Can be nil if the server is running unsecured.
54
+ def openRemoteIP(address, port=5001, password=nil)
55
+ @server = address
56
+ @port = port.to_i
57
+ @password = password
58
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetManager_openRemoteIP', @handle, address, port.to_i, password)
59
+ raise Phidgets::Exception.new(r) if r != 0
60
+
61
+ # a delay is required between the time the manager is opened and when it is used, otherwise it will report that no phidgets are attached. there really should be a better way.
62
+ sleep 2
63
+ end
64
+
65
+ # Closes a Manager.
66
+ def close
67
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetManager_close', @handle)
68
+ raise Phidgets::Exception.new(r) if r != 0
69
+ end
70
+
71
+ # Frees a Manager handle.
72
+ def delete
73
+ @handle.free = nil
74
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetManager_delete', @handle)
75
+ raise Phidgets::Exception.new(r) if r != 0
76
+ end
77
+
78
+ # Gets a hash of all currently attached Phidgets. The indices into the hash are the serial numbers of the Phidgets.
79
+ def getAttachedDevices
80
+ handles = Phidgets.malloc(SIZEOF_VOIDP)
81
+ count = Phidgets.malloc(SIZEOF_INT)
82
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetManager_getAttachedDevices', @handle, handles.ref, count.ref)
83
+ raise Phidgets::Exception.new(r) if r != 0
84
+ count.free = nil
85
+
86
+ devices = {}
87
+ count.to_i.times { |i|
88
+ handle = handles + (i * SIZEOF_VOIDP)
89
+ serial = getSerialNumber(handle)
90
+
91
+ devices[serial] = case getDeviceClass(handle)
92
+ when CLASS_INTERFACEKIT
93
+ InterfaceKit.new
94
+ when CLASS_RFID
95
+ RFID.new
96
+ when CLASS_SERVO
97
+ Servo.new
98
+ end
99
+
100
+ devices[serial].open(serial, 3000) unless @server
101
+ devices[serial].openRemote(serial, @server, @password, 4000) if @server and !@port
102
+ devices[serial].openRemoteIP(serial, @server, @port, @password, 4000) if @server and @port
103
+ }
104
+
105
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetManager_freeAttachedDevicesArray', handles)
106
+ raise Phidgets::Exception.new(r) if r != 0
107
+
108
+ devices
109
+ end
110
+
111
+ private
112
+
113
+ def getDeviceClass handle
114
+ dev_class = Phidgets.malloc(SIZEOF_INT)
115
+ r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getDeviceClass', handle.ptr, dev_class.ref)
116
+ raise Phidgets::Exception.new(r) if r != 0
117
+ dev_class.free = nil
118
+ dev_class.to_i
119
+ end
120
+
121
+ def getSerialNumber handle
122
+ sn = Phidgets.malloc(SIZEOF_INT)
123
+ r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getSerialNumber', handle.ptr, sn.ref)
124
+ raise Phidgets::Exception.new(r) if r != 0
125
+ sn.free = nil
126
+ sn.to_i
127
+ end
128
+
129
+ end
130
+
131
+ end
132
+
@@ -0,0 +1,225 @@
1
+
2
+ require 'dl'
3
+ require 'dl/import'
4
+ require 'rbconfig'
5
+
6
+
7
+ module Phidgets
8
+
9
+ if RUBY_VERSION < "1.9"
10
+ extend DL::Importable
11
+ SIZEOF_INT = DL.sizeof('I')
12
+ SIZEOF_VOIDP = DL.sizeof('P')
13
+ SIZEOF_DOUBLE = DL.sizeof('D')
14
+ FUNCTION_PREFIX = 'c'
15
+ def Phidgets.malloc size
16
+ DL.malloc(size)
17
+ end
18
+ else
19
+ extend DL::Importer
20
+ SIZEOF_INT = DL::SIZEOF_INT
21
+ SIZEOF_VOIDP = DL::SIZEOF_VOIDP
22
+ SIZEOF_DOUBLE = DL::SIZEOF_DOUBLE
23
+ FUNCTION_PREFIX = 'C'
24
+ def Phidgets.malloc size
25
+ DL::CPtr.malloc(size)
26
+ end
27
+ end
28
+
29
+ PFALSE = 0
30
+ PTRUE = 1
31
+
32
+ NOTATTACHED = 0
33
+ ATTACHED = 1
34
+
35
+ CLASS_NOTHING = 1
36
+ CLASS_ACCELEROMETER = 2
37
+ CLASS_ADVANCEDSERVO = 3
38
+ CLASS_ENCODER = 4
39
+ CLASS_GPS = 5
40
+ CLASS_GYROSCOPE = 6
41
+ CLASS_INTERFACEKIT = 7
42
+ CLASS_LED = 8
43
+ CLASS_MOTORCONTROL = 9
44
+ CLASS_PHSENSOR = 10
45
+ CLASS_RFID = 11
46
+ CLASS_SERVO = 12
47
+ CLASS_STEPPER = 13
48
+ CLASS_TEMPERATURESENSOR = 14
49
+ CLASS_TEXTLCD = 15
50
+ CLASS_TEXTLED = 16
51
+ CLASS_WEIGHTSENSOR = 17
52
+
53
+ ID_ACCELEROMETER_2AXIS = 0x071
54
+ ID_ACCELEROMETER_3AXIS = 0x07E
55
+ ID_ADVANCEDSERVO_8MOTOR = 0x03A
56
+ ID_BIPOLAR_STEPPER_1MOTOR = 0x07B
57
+ ID_ENCODER_1ENCODER_1INPUT = 0x04B
58
+ ID_ENCODER_HS_1ENCODER = 0x080
59
+ ID_INTERFACEKIT_0_0_4 = 0x040
60
+ ID_INTERFACEKIT_0_0_8 = 0x081
61
+ ID_INTERFACEKIT_0_16_16 = 0x044
62
+ ID_INTERFACEKIT_8_8_8 = 0x045
63
+ ID_INTERFACEKIT_8_8_8_w_LCD = 0x07D
64
+ ID_LED_64 = 0x04A
65
+ ID_LINEAR_TOUCH = 0x076
66
+ ID_MOTORCONTROL_HC_2MOTOR = 0x059
67
+ ID_MOTORCONTROL_LV_2MOTOR_4INPUT = 0x058
68
+ ID_PHSENSOR = 0x074
69
+ ID_RFID_2OUTPUT = 0x031
70
+ ID_ROTARY_TOUCH = 0x077
71
+ ID_SERVO_1MOTOR = 0x039
72
+ ID_TEMPERATURESENSOR = 0x070
73
+ ID_TEXTLCD_2x20_w_8_8_8 = 0x17D
74
+ ID_UNIPOLAR_STEPPER_4MOTOR = 0x07A
75
+ ID_INTERFACEKIT_0_8_8_w_LCD = 0x053
76
+ ID_INTERFACEKIT_4_8_8 = 0x004
77
+ ID_RFID = 0x030
78
+ ID_SERVO_1MOTOR_OLD = 0x002
79
+ ID_SERVO_4MOTOR = 0x038
80
+ ID_SERVO_4MOTOR_OLD = 0x003
81
+ ID_TEXTLCD_2x20 = 0x052
82
+ ID_TEXTLCD_2x20_w_0_8_8 = 0x153
83
+ ID_TEXTLED_1x8 = 0x049
84
+ ID_TEXTLED_4x8 = 0x048
85
+ ID_WEIGHTSENSOR = 0x072
86
+
87
+ PHIDGET_LOG_CRITICAL = 1
88
+ PHIDGET_LOG_ERROR = 2
89
+ PHIDGET_LOG_WARNING = 3
90
+ PHIDGET_LOG_DEBUG = 4
91
+ PHIDGET_LOG_INFO = 5
92
+ PHIDGET_LOG_VERBOSE = 6
93
+
94
+ class Exception < RuntimeError
95
+ attr_reader :code
96
+
97
+ EPHIDGET_LOAD_LIB_FAIL = -2
98
+ EPHIDGET_LIBNAME = -1
99
+ EPHIDGET_NOTFOUND = 1
100
+ EPHIDGET_NOMEMORY = 2
101
+ EPHIDGET_UNEXPECTED = 3
102
+ EPHIDGET_INVALIDARG = 4
103
+ EPHIDGET_NOTATTACHED = 5
104
+ EPHIDGET_INTERRUPTED = 6
105
+ EPHIDGET_INVALID = 7
106
+ EPHIDGET_NETWORK = 8
107
+ EPHIDGET_UNKNOWNVAL = 9
108
+ EPHIDGET_BADPASSWORD = 10
109
+ EPHIDGET_UNSUPPORTED = 11
110
+ EPHIDGET_DUPLICATE = 12
111
+ EPHIDGET_TIMEOUT = 13
112
+ EPHIDGET_OUTOFBOUNDS = 14
113
+ EPHIDGET_EVENT = 15
114
+ EPHIDGET_NETWORK_NOTCONNECTED = 16
115
+ EPHIDGET_WRONGDEVICE = 17
116
+ EPHIDGET_CLOSED = 18
117
+ EPHIDGET_BADVERSION = 19
118
+
119
+ def initialize(code)
120
+ @code = code
121
+ case code
122
+ when EPHIDGET_LOAD_LIB_FAIL
123
+ super('Failed to load Phidgets Library')
124
+ when EPHIDGET_LIBNAME
125
+ super('Unable to determine Phidgets Library name.')
126
+ when EPHIDGET_NOTFOUND
127
+ super('A Phidget matching the type and or serial number could not be found.')
128
+ when EPHIDGET_NOMEMORY
129
+ super('Memory could not be allocated.')
130
+ when EPHIDGET_UNEXPECTED
131
+ super('Unexpected Error. Contact Phidgets Inc. for support.')
132
+ when EPHIDGET_INVALIDARG
133
+ super('Invalid argument passed to function.')
134
+ when EPHIDGET_NOTATTACHED
135
+ super('Phidget not physically attached.')
136
+ when EPHIDGET_INTERRUPTED
137
+ super('Read/Write operation was interrupted.')
138
+ when EPHIDGET_INVALID
139
+ super('The Error Code is not defined.')
140
+ when EPHIDGET_NETWORK
141
+ super('Network Error.')
142
+ when EPHIDGET_UNKNOWNVAL
143
+ super('Value is Unknown (State not yet received from device, or not yet set by user).')
144
+ when EPHIDGET_BADPASSWORD
145
+ super('Authorization Failed.')
146
+ when EPHIDGET_UNSUPPORTED
147
+ super('Not Supported.')
148
+ when EPHIDGET_DUPLICATE
149
+ super('Duplicated request.')
150
+ when EPHIDGET_TIMEOUT
151
+ super('Given timeout has been exceeded.')
152
+ when EPHIDGET_OUTOFBOUNDS
153
+ super('Index out of Bounds.')
154
+ when EPHIDGET_EVENT
155
+ super('A non-null error code was returned from an event handler.')
156
+ when EPHIDGET_NETWORK_NOTCONNECTED
157
+ super('A connection to the server does not exist.')
158
+ when EPHIDGET_WRONGDEVICE
159
+ super('Function is not applicable for this device.')
160
+ when EPHIDGET_CLOSED
161
+ super('Phidget handle was closed.')
162
+ when EPHIDGET_BADVERSION
163
+ super("Webservice and Client protocol versions don't match. Update to newest release.")
164
+ end
165
+ end
166
+
167
+ end
168
+
169
+ begin
170
+ case Config::CONFIG['target_os']
171
+ when /linux/
172
+ dlload 'libphidget21.so'
173
+ when /mswin/, /mingw/
174
+ dlload 'phidget21.dll'
175
+ when /darwin/
176
+ dlload '/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21'
177
+ else
178
+ raise Phidgets::Exception.new(Exception::EPHIDGET_LIBNAME)
179
+ end
180
+ rescue
181
+ raise Phidgets::Exception.new(Exception::EPHIDGET_LOAD_LIB_FAIL)
182
+ end
183
+
184
+ extern "int CPhidget_getLibraryVersion(void *)"
185
+ extern "int CPhidget_getErrorDescription(int, void *)"
186
+ extern "int CPhidget_enableLogging(int, char *)"
187
+ extern "int CPhidget_disableLogging()"
188
+
189
+ # Gets the library version. This contains a version number and a build date.
190
+ def Phidgets.getLibraryVersion
191
+ ptr = malloc(SIZEOF_VOIDP)
192
+ r = self.send(FUNCTION_PREFIX + 'Phidget_getLibraryVersion', ptr.ref)
193
+ raise Phidgets::Exception.new(r) if r != 0
194
+ ptr.free = nil
195
+ ptr.to_s
196
+ end
197
+
198
+ # Gets the description for an error code.
199
+ def Phidgets.getErrorDescription(error_code)
200
+ ptr = malloc(SIZEOF_VOIDP)
201
+ r = self.send(FUNCTION_PREFIX + 'Phidget_getErrorDescription', error_code.to_i, ptr.ref)
202
+ raise Phidgets::Exception.new(r) if r != 0
203
+ ptr.free = nil
204
+ ptr.to_s
205
+ end
206
+
207
+ # Enables logging. Logging is provided mainly for debugging purposes. Enabling logging will output internal library
208
+ # information that can be used to find bugs with the help of Phidgetd Inc. Alternatively, the user can enable
209
+ # and write to the log for their own uses.
210
+ # === Parameters
211
+ # * _level_ = The highest level of logging to output. All lower levels will also be output.
212
+ # * _file_ = File to output log to. This should be a full pathname, not a relative pathname.
213
+ def Phidgets.enableLogging(level, file)
214
+ r = self.send(FUNCTION_PREFIX + 'Phidget_enableLogging', level.to_i, file)
215
+ raise Phidgets::Exception.new(r) if r != 0
216
+ end
217
+
218
+ # Disables logging.
219
+ def Phidgets.disableLogging
220
+ r = self.send(FUNCTION_PREFIX + 'Phidget_disableLogging')
221
+ raise Phidgets::Exception.new(r) if r != 0
222
+ end
223
+
224
+ end
225
+
data/lib/phidgets/rfid.rb CHANGED
@@ -5,18 +5,18 @@ module Phidgets
5
5
  extern "int CPhidgetRFID_create(void *)"
6
6
  extern "int CPhidgetRFID_getOutputCount(void *, int *)"
7
7
  extern "int CPhidgetRFID_getOutputState(void *, int, int *)"
8
- extern "int CPhidgetRFID_setOutputState(void *, int *)"
9
- extern "int CPhidgetRFID_getAntennaOn(void *, int, int *)"
10
- extern "int CPhidgetRFID_setAntennaOn(void *, int, int)"
8
+ extern "int CPhidgetRFID_setOutputState(void *, int, int)"
9
+ extern "int CPhidgetRFID_getAntennaOn(void *, int *)"
10
+ extern "int CPhidgetRFID_setAntennaOn(void *, int)"
11
11
  extern "int CPhidgetRFID_getLEDOn(void *, int *)"
12
- extern "int CPhidgetRFID_setLEDOn(void *, int, int *)"
13
- extern "int CPhidgetRFID_getLastTag(void *, int, int *)"
12
+ extern "int CPhidgetRFID_setLEDOn(void *, int)"
13
+ extern "int CPhidgetRFID_getLastTag(void *, void *)"
14
14
  extern "int CPhidgetRFID_getTagStatus(void *, int *)"
15
15
 
16
16
 
17
17
  class RFID < Common
18
18
 
19
- # Create a new rfid object.
19
+ # Create a new RFID object.
20
20
  # === Parameters
21
21
  # * _serial_number_ = Serial number of the phidget board to open. Specify -1 to open any.
22
22
  # * _timeout_ = Time to wait for attachment. Specify 0 to not call open.
@@ -40,7 +40,7 @@ module Phidgets
40
40
  # * _index_ = The output index.
41
41
  def getOutputState(index)
42
42
  state = Phidgets.malloc(SIZEOF_INT)
43
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getOutputState', @handle, index, state.ref)
43
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getOutputState', @handle, index.to_i, state.ref)
44
44
  raise Phidgets::Exception.new(r) if r != 0
45
45
  state.free = nil
46
46
  state.to_i
@@ -51,7 +51,7 @@ module Phidgets
51
51
  # * _index_ = The output index.
52
52
  # * _state_ = The output state. Possible values are PTRUE and PFALSE.
53
53
  def setOutputState(index, state)
54
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_setOutputState', @handle, index, state)
54
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_setOutputState', @handle, index.to_i, state.to_i)
55
55
  raise Phidgets::Exception.new(r) if r != 0
56
56
  end
57
57
 
@@ -68,7 +68,7 @@ module Phidgets
68
68
  # === Parameters
69
69
  # * _state_ = The antenna state. Possible values are PTRUE and PFALSE.
70
70
  def setAntennaOn(state)
71
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_setAntennaOn', @handle, state)
71
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_setAntennaOn', @handle, state.to_i)
72
72
  raise Phidgets::Exception.new(r) if r != 0
73
73
  end
74
74
 
@@ -85,16 +85,17 @@ module Phidgets
85
85
  # === Parameters
86
86
  # * _state_ = The LED state. Possible values are PTRUE and PFALSE.
87
87
  def setLedOn(state)
88
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_setLEDOn', @handle, state)
88
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_setLEDOn', @handle, state.to_i)
89
89
  raise Phidgets::Exception.new(r) if r != 0
90
90
  end
91
91
 
92
92
  # Gets the last tag read by the reader. This tag may or may not still be on the reader.
93
93
  def getLastTag
94
- tag = Phidgets.malloc(5)
95
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getLastTag', @handle, tag)
94
+ tag = Phidgets.malloc(SIZEOF_VOIDP)
95
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getLastTag', @handle, tag.ref)
96
96
  raise Phidgets::Exception.new(r) if r != 0
97
- tag
97
+ tag.free = nil
98
+ tag.to_s
98
99
  end
99
100
 
100
101
  # Gets the tag present status. This is whether or not a tag is being read by the reader.
@@ -12,7 +12,7 @@ module Phidgets
12
12
 
13
13
  class Servo < Common
14
14
 
15
- # Create a new servo object.
15
+ # Create a new Servo object.
16
16
  # === Parameters
17
17
  # * _serial_number_ = Serial number of the phidget board to open. Specify -1 to open any.
18
18
  # * _timeout_ = Time to wait for attachment. Specify 0 to not call open.
@@ -36,7 +36,7 @@ module Phidgets
36
36
  # * _index_ = The motor index.
37
37
  def getPosition(index)
38
38
  pos = Phidgets.malloc(SIZEOF_DOUBLE)
39
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getPosition', @handle, index, pos.ref)
39
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getPosition', @handle, index.to_i, pos.ref)
40
40
  raise Phidgets::Exception.new(r) if r != 0
41
41
  pos.free = nil
42
42
  pos.to_f
@@ -47,7 +47,7 @@ module Phidgets
47
47
  # * _index_ = The motor index.
48
48
  # * _position = The motor position.
49
49
  def setPosition(index, position)
50
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_setPosition', @handle, index, position)
50
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_setPosition', @handle, index.to_i, position.to_f)
51
51
  raise Phidgets::Exception.new(r) if r != 0
52
52
  end
53
53
 
@@ -56,7 +56,7 @@ module Phidgets
56
56
  # * _index_ = The motor index.
57
57
  def getPositionMax(index)
58
58
  pos = Phidgets.malloc(SIZEOF_DOUBLE)
59
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getPositionMax', @handle, index, pos.ref)
59
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getPositionMax', @handle, index.to_i, pos.ref)
60
60
  raise Phidgets::Exception.new(r) if r != 0
61
61
  pos.free = nil
62
62
  pos.to_f
@@ -67,7 +67,7 @@ module Phidgets
67
67
  # * _index_ = The motor index.
68
68
  def getPositionMin(index)
69
69
  pos = Phidgets.malloc(SIZEOF_DOUBLE)
70
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getPositionMin', @handle, index, pos.ref)
70
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getPositionMin', @handle, index.to_i, pos.ref)
71
71
  raise Phidgets::Exception.new(r) if r != 0
72
72
  pos.free = nil
73
73
  pos.to_f
@@ -78,7 +78,7 @@ module Phidgets
78
78
  # * _index_ = The motor index.
79
79
  def getEngaged(index)
80
80
  eng = Phidgets.malloc(SIZEOF_INT)
81
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getEngaged', @handle, index, eng.ref)
81
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getEngaged', @handle, index.to_i, eng.ref)
82
82
  raise Phidgets::Exception.new(r) if r != 0
83
83
  eng.free = nil
84
84
  eng.to_i
@@ -89,7 +89,7 @@ module Phidgets
89
89
  # * _index_ = The motor index.
90
90
  # * _state_ = The engaged state. Possible values are PTRUE and PFALSE.
91
91
  def setEngaged(index, state)
92
- r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_setEngaged', @handle, index, state)
92
+ r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_setEngaged', @handle, index.to_i, state.to_i)
93
93
  raise Phidgets::Exception.new(r) if r != 0
94
94
  end
95
95
 
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phidgets
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 4
9
- version: 0.0.4
4
+ version: 0.0.5
10
5
  platform: ruby
11
6
  authors:
12
7
  - Craig DeHaan
@@ -14,44 +9,36 @@ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2010-09-14 00:00:00 -04:00
12
+ date: 2010-09-29 00:00:00 -04:00
18
13
  default_executable:
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: rubyforge
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
24
20
  requirements:
25
21
  - - ">="
26
22
  - !ruby/object:Gem::Version
27
- segments:
28
- - 2
29
- - 0
30
- - 4
31
23
  version: 2.0.4
32
- type: :development
33
- version_requirements: *id001
24
+ version:
34
25
  - !ruby/object:Gem::Dependency
35
26
  name: hoe
36
- prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
38
30
  requirements:
39
31
  - - ">="
40
32
  - !ruby/object:Gem::Version
41
- segments:
42
- - 2
43
- - 6
44
- - 0
45
33
  version: 2.6.0
46
- type: :development
47
- version_requirements: *id002
34
+ version:
48
35
  description: |-
49
36
  Phidgets are a set of "plug and play" building blocks for low cost USB sensing and control from your PC.
50
37
  This gem provides a ruby interface to the phidgets library.
51
38
  email:
52
39
  - craig.s.dehaan@gmail.com
53
- executables: []
54
-
40
+ executables:
41
+ - phidget
55
42
  extensions: []
56
43
 
57
44
  extra_rdoc_files:
@@ -68,7 +55,10 @@ files:
68
55
  - README.txt
69
56
  - README.rdoc
70
57
  - Rakefile
58
+ - bin/phidget
71
59
  - lib/phidgets.rb
60
+ - lib/phidgets/phidgets.rb
61
+ - lib/phidgets/manager.rb
72
62
  - lib/phidgets/common.rb
73
63
  - lib/phidgets/interfacekit.rb
74
64
  - lib/phidgets/rfid.rb
@@ -93,24 +83,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
83
  requirements:
94
84
  - - ">="
95
85
  - !ruby/object:Gem::Version
96
- segments:
97
- - 0
98
86
  version: "0"
87
+ version:
99
88
  required_rubygems_version: !ruby/object:Gem::Requirement
100
89
  requirements:
101
90
  - - ">="
102
91
  - !ruby/object:Gem::Version
103
- segments:
104
- - 0
105
92
  version: "0"
93
+ version:
106
94
  requirements: []
107
95
 
108
96
  rubyforge_project: phidgets
109
- rubygems_version: 1.3.6
97
+ rubygems_version: 1.3.5
110
98
  signing_key:
111
99
  specification_version: 3
112
100
  summary: Phidgets are a set of "plug and play" building blocks for low cost USB sensing and control from your PC
113
101
  test_files:
114
- - test/test_interfacekit.rb
115
- - test/test_helper.rb
116
102
  - test/test_phidgets.rb
103
+ - test/test_helper.rb
104
+ - test/test_interfacekit.rb