phidgets 0.0.3 → 0.0.4
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 +4 -0
- data/README.rdoc +0 -26
- data/README.txt +0 -26
- data/lib/phidgets.rb +1 -1
- data/lib/phidgets/common.rb +59 -90
- data/lib/phidgets/interfacekit.rb +19 -19
- data/lib/phidgets/rfid.rb +16 -18
- data/lib/phidgets/servo.rb +13 -13
- metadata +30 -15
data/History.txt
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== 0.0.4 2010-09-10
|
2
|
+
* Updated for compatability with Ruby 1.9
|
3
|
+
* Removed all support for callbacks
|
4
|
+
|
1
5
|
== 0.0.3 2010-08-09
|
2
6
|
* Moved the Phidgets::Exception class before the initialization code so that the init code can throw an exception
|
3
7
|
* Fixed bugs in Common::openRemote and Common::openRemoteIP that prevented them from being called
|
data/README.rdoc
CHANGED
@@ -12,8 +12,6 @@ This gem provides a ruby interface to the phidgets library.
|
|
12
12
|
* This gem uses DL to call the c functions in the Phidgets shared library, so the library must be installed and working.
|
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
|
-
* The callback functionality of the Phidgets library is working but should be used with caution. I have found that the callback
|
16
|
-
will cause a stack overflow exception if it is too big (not sure exactly what the limit is, but it isn't much).
|
17
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).
|
18
16
|
If it guessesincorrectly please leave a message to let me know what your platform sets for Config::CONFIG['target_os'] and
|
19
17
|
what is the name of the phidgets library.
|
@@ -35,30 +33,6 @@ This gem provides a ruby interface to the phidgets library.
|
|
35
33
|
puts "Phidgets Error (#{e.code}). #{e}"
|
36
34
|
end
|
37
35
|
|
38
|
-
=== <b>or to use a callback:</b>
|
39
|
-
|
40
|
-
require 'phidgets'
|
41
|
-
|
42
|
-
def onConnect(handle, data)
|
43
|
-
# the ruby object passed in to the callback is converted to an object id.
|
44
|
-
# Now convert it back to an object reference
|
45
|
-
ik = ObjectSpace._id2ref(data.to_i)
|
46
|
-
puts ik.getDeviceName
|
47
|
-
return 0
|
48
|
-
end
|
49
|
-
|
50
|
-
begin
|
51
|
-
ik = Phidgets::InterfaceKit.new
|
52
|
-
ik.setOnAttachHandler("onConnect", ik)
|
53
|
-
ik.open
|
54
|
-
|
55
|
-
# do something else
|
56
|
-
sleep 4
|
57
|
-
|
58
|
-
rescue Phidgets::Exception => e
|
59
|
-
puts "Phidgets Error (#{e.code}). #{e}"
|
60
|
-
end
|
61
|
-
|
62
36
|
|
63
37
|
== REQUIREMENTS:
|
64
38
|
|
data/README.txt
CHANGED
@@ -12,8 +12,6 @@ This gem provides a ruby interface to the phidgets library.
|
|
12
12
|
* This gem uses DL to call the c functions in the Phidgets shared library, so the library must be installed and working.
|
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
|
-
* The callback functionality of the Phidgets library is working but should be used with caution. I have found that the callback
|
16
|
-
will cause a stack overflow exception if it is too big (not sure exactly what the limit is, but it isn't much).
|
17
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).
|
18
16
|
If it guessesincorrectly please leave a message to let me know what your platform sets for Config::CONFIG['target_os'] and
|
19
17
|
what is the name of the phidgets library.
|
@@ -35,30 +33,6 @@ This gem provides a ruby interface to the phidgets library.
|
|
35
33
|
puts "Phidgets Error (#{e.code}). #{e}"
|
36
34
|
end
|
37
35
|
|
38
|
-
=== <b>or to use a callback:</b>
|
39
|
-
|
40
|
-
require 'phidgets'
|
41
|
-
|
42
|
-
def onConnect(handle, data)
|
43
|
-
# the ruby object passed in to the callback is converted to an object id.
|
44
|
-
# Now convert it back to an object reference
|
45
|
-
ik = ObjectSpace._id2ref(data.to_i)
|
46
|
-
puts ik.getDeviceName
|
47
|
-
return 0
|
48
|
-
end
|
49
|
-
|
50
|
-
begin
|
51
|
-
ik = Phidgets::InterfaceKit.new
|
52
|
-
ik.setOnAttachHandler("onConnect", ik)
|
53
|
-
ik.open
|
54
|
-
|
55
|
-
# do something else
|
56
|
-
sleep 4
|
57
|
-
|
58
|
-
rescue Phidgets::Exception => e
|
59
|
-
puts "Phidgets Error (#{e.code}). #{e}"
|
60
|
-
end
|
61
|
-
|
62
36
|
|
63
37
|
== REQUIREMENTS:
|
64
38
|
|
data/lib/phidgets.rb
CHANGED
data/lib/phidgets/common.rb
CHANGED
@@ -5,7 +5,26 @@ require 'rbconfig'
|
|
5
5
|
|
6
6
|
|
7
7
|
module Phidgets
|
8
|
-
|
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
|
9
28
|
|
10
29
|
PFALSE = 0
|
11
30
|
PTRUE = 1
|
@@ -141,7 +160,7 @@ module Phidgets
|
|
141
160
|
when EPHIDGET_CLOSED
|
142
161
|
super('Phidget handle was closed.')
|
143
162
|
when EPHIDGET_BADVERSION
|
144
|
-
super(
|
163
|
+
super("Webservice and Client protocol versions don't match. Update to newest release.")
|
145
164
|
end
|
146
165
|
end
|
147
166
|
|
@@ -151,7 +170,7 @@ module Phidgets
|
|
151
170
|
case Config::CONFIG['target_os']
|
152
171
|
when /linux/
|
153
172
|
dlload 'libphidget21.so'
|
154
|
-
when /mswin/
|
173
|
+
when /mswin/, /mingw/
|
155
174
|
dlload 'phidget21.dll'
|
156
175
|
when /darwin/
|
157
176
|
dlload '/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21'
|
@@ -167,11 +186,6 @@ module Phidgets
|
|
167
186
|
extern "int CPhidget_open(void *, int)"
|
168
187
|
extern "int CPhidget_close(void *)"
|
169
188
|
extern "int CPhidget_delete(void *)"
|
170
|
-
extern "int CPhidget_set_OnDetach_Handler(void *, void *, void *)"
|
171
|
-
extern "int CPhidget_set_OnAttach_Handler(void *, void *, void *)"
|
172
|
-
extern "int CPhidget_set_OnServerConnect_Handler(void *, void *, void *)"
|
173
|
-
extern "int CPhidget_set_OnServerDisconnect_Handler(void *, void *, void *)"
|
174
|
-
extern "int CPhidget_set_OnError_Handler(void *, void *, void *)"
|
175
189
|
extern "int CPhidget_getDeviceName(void *, void *)"
|
176
190
|
extern "int CPhidget_getSerialNumber(void *, int *)"
|
177
191
|
extern "int CPhidget_getDeviceVersion(void *, int *)"
|
@@ -192,8 +206,8 @@ module Phidgets
|
|
192
206
|
|
193
207
|
# Gets the library version. This contains a version number and a build date.
|
194
208
|
def Phidgets.getLibraryVersion
|
195
|
-
ptr =
|
196
|
-
r =
|
209
|
+
ptr = malloc(SIZEOF_VOIDP)
|
210
|
+
r = self.send(FUNCTION_PREFIX + 'Phidget_getLibraryVersion', ptr.ref)
|
197
211
|
raise Phidgets::Exception.new(r) if r != 0
|
198
212
|
ptr.free = nil
|
199
213
|
ptr.to_s
|
@@ -201,8 +215,8 @@ module Phidgets
|
|
201
215
|
|
202
216
|
# Gets the description for an error code.
|
203
217
|
def Phidgets.getErrorDescription(error_code)
|
204
|
-
ptr =
|
205
|
-
r =
|
218
|
+
ptr = malloc(SIZEOF_VOIDP)
|
219
|
+
r = self.send(FUNCTION_PREFIX + 'Phidget_getErrorDescription', error_code, ptr.ref)
|
206
220
|
raise Phidgets::Exception.new(r) if r != 0
|
207
221
|
ptr.free = nil
|
208
222
|
ptr.to_s
|
@@ -215,13 +229,13 @@ module Phidgets
|
|
215
229
|
# * _level_ = The highest level of logging to output. All lower levels will also be output.
|
216
230
|
# * _file_ = File to output log to. This should be a full pathname, not a relative pathname.
|
217
231
|
def Phidgets.enableLogging(level, file)
|
218
|
-
r =
|
232
|
+
r = self.send(FUNCTION_PREFIX + 'Phidget_enableLogging', level, file)
|
219
233
|
raise Phidgets::Exception.new(r) if r != 0
|
220
234
|
end
|
221
235
|
|
222
236
|
# Disables logging.
|
223
237
|
def Phidgets.disableLogging
|
224
|
-
r =
|
238
|
+
r = self.send(FUNCTION_PREFIX + 'Phidget_disableLogging')
|
225
239
|
raise Phidgets::Exception.new(r) if r != 0
|
226
240
|
end
|
227
241
|
|
@@ -235,7 +249,7 @@ module Phidgets
|
|
235
249
|
# * _password_ = Password. Can be nil if the server is running unsecured.
|
236
250
|
# * _timeout_ = Time to wait for attachment. Specify 0 to not wait.
|
237
251
|
def openRemote(serial_number=-1, server=nil, password=nil, timeout=0)
|
238
|
-
r = Phidgets.
|
252
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_openRemote', @handle, serial_number, server, password)
|
239
253
|
raise Phidgets::Exception.new(r) if r != 0
|
240
254
|
waitForAttachment(timeout) if timeout > 0
|
241
255
|
end
|
@@ -248,7 +262,7 @@ module Phidgets
|
|
248
262
|
# * _password_ = Password. Can be nil if the server is running unsecured.
|
249
263
|
# * _timeout_ = Time to wait for attachment. Specify 0 to not wait.
|
250
264
|
def openRemoteIP(serial_number, address, port=5001, password=nil, timeout=0)
|
251
|
-
r = Phidgets.
|
265
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_openRemoteIP', @handle, serial_number, address, port, password)
|
252
266
|
raise Phidgets::Exception.new(r) if r != 0
|
253
267
|
waitForAttachment(timeout) if timeout > 0
|
254
268
|
end
|
@@ -258,73 +272,28 @@ module Phidgets
|
|
258
272
|
# * _serial_number_ = Serial number. Specify -1 to open any.
|
259
273
|
# * _timeout_ = Time to wait for attachment. Specify 0 to not wait.
|
260
274
|
def open(serial_number=-1, timeout=0)
|
261
|
-
r = Phidgets.
|
275
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_open', @handle, serial_number)
|
262
276
|
raise Phidgets::Exception.new(r) if r != 0
|
263
277
|
waitForAttachment(timeout) if timeout > 0
|
264
278
|
end
|
265
279
|
|
266
280
|
# Closes a Phidget.
|
267
281
|
def close
|
268
|
-
r = Phidgets.
|
282
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_close', @handle)
|
269
283
|
raise Phidgets::Exception.new(r) if r != 0
|
270
284
|
end
|
271
285
|
|
272
286
|
# Frees a Phidget handle.
|
273
287
|
def delete
|
274
288
|
@handle.free = nil
|
275
|
-
r = Phidgets.
|
276
|
-
raise Phidgets::Exception.new(r) if r != 0
|
277
|
-
end
|
278
|
-
|
279
|
-
# Sets a detach handler callback function. This is called when this Phidget is unplugged from the system.
|
280
|
-
# === Parameters
|
281
|
-
# * _callback_func_ = Callback function.
|
282
|
-
# * _data_ = Data for use by the user - this object is passed back into the callback function.
|
283
|
-
def setOnDetachHandler(callback_func, data)
|
284
|
-
r = Phidgets.cPhidget_set_OnDetach_Handler(@handle, Phidgets.callback("int #{callback_func}(void *, void *)"), DL::PtrData.new(data.object_id))
|
285
|
-
raise Phidgets::Exception.new(r) if r != 0
|
286
|
-
end
|
287
|
-
|
288
|
-
# Sets an attach handler callback function. This is called when this Phidget is plugged into the system, and is ready for use.
|
289
|
-
# === Parameters
|
290
|
-
# * _callback_func_ = Callback function.
|
291
|
-
# * _data_ = Data for use by the user - this object is passed back into the callback function.
|
292
|
-
def setOnAttachHandler(callback_func, data)
|
293
|
-
r = Phidgets.cPhidget_set_OnAttach_Handler(@handle, Phidgets.callback("int #{callback_func}(void *, void *)"), DL::PtrData.new(data.object_id))
|
294
|
-
raise Phidgets::Exception.new(r) if r != 0
|
295
|
-
end
|
296
|
-
|
297
|
-
# Sets a server connect handler callback function. This is used for opening Phidgets remotely, and is called when a connection to the sever has been made.
|
298
|
-
# === Parameters
|
299
|
-
# * _callback_func_ = Callback function.
|
300
|
-
# * _data_ = Data for use by the user - this object is passed back into the callback function.
|
301
|
-
def setOnConnectHandler(callback_func, data)
|
302
|
-
r = Phidgets.cPhidget_set_OnServerConnect_Handler(@handle, Phidgets.callback("int #{callback_func}(void *, void *)"), DL::PtrData.new(data.object_id))
|
303
|
-
raise Phidgets::Exception.new(r) if r != 0
|
304
|
-
end
|
305
|
-
|
306
|
-
# Sets a server disconnect handler callback function. This is used for opening Phidgets remotely, and is called when a connection to the server has been lost.
|
307
|
-
# === Parameters
|
308
|
-
# * _callback_func_ = Callback function.
|
309
|
-
# * _data_ = Data for use by the user - this object is passed back into the callback function.
|
310
|
-
def setOnDisconnectHandler(callback_func, data)
|
311
|
-
r = Phidgets.cPhidget_set_OnServerDisconnect_Handler(@handle, Phidgets.callback("int #{callback_func}(void *, void *)"), DL::PtrData.new(data.object_id))
|
312
|
-
raise Phidgets::Exception.new(r) if r != 0
|
313
|
-
end
|
314
|
-
|
315
|
-
# Sets the error handler callback function. This is called when an asynchronous error occurs.
|
316
|
-
# === Parameters
|
317
|
-
# * _callback_func_ = Callback function.
|
318
|
-
# * _data_ = Data for use by the user - this object is passed back into the callback function.
|
319
|
-
def setOnErrorHandler(callback_func, data)
|
320
|
-
r = Phidgets.cPhidget_set_OnError_Handler(@handle, Phidgets.callback("int #{callback_func}(void *, void *, int, const char *)"), DL::PtrData.new(data.object_id))
|
289
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_delete', @handle)
|
321
290
|
raise Phidgets::Exception.new(r) if r != 0
|
322
291
|
end
|
323
292
|
|
324
293
|
# Gets the specific name of a Phidget.
|
325
294
|
def getDeviceName
|
326
|
-
ptr =
|
327
|
-
r = Phidgets.
|
295
|
+
ptr = Phidgets.malloc(SIZEOF_VOIDP)
|
296
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getDeviceName', @handle, ptr.ref)
|
328
297
|
raise Phidgets::Exception.new(r) if r != 0
|
329
298
|
ptr.free = nil
|
330
299
|
ptr.to_s
|
@@ -332,8 +301,8 @@ module Phidgets
|
|
332
301
|
|
333
302
|
# Gets the serial number of a Phidget.
|
334
303
|
def getSerialNumber
|
335
|
-
sn =
|
336
|
-
r = Phidgets.
|
304
|
+
sn = Phidgets.malloc(SIZEOF_INT)
|
305
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getSerialNumber', @handle, sn.ref)
|
337
306
|
raise Phidgets::Exception.new(r) if r != 0
|
338
307
|
sn.free = nil
|
339
308
|
sn.to_i
|
@@ -341,8 +310,8 @@ module Phidgets
|
|
341
310
|
|
342
311
|
# Gets the firmware version of a Phidget.
|
343
312
|
def getDeviceVersion
|
344
|
-
ver =
|
345
|
-
r = Phidgets.
|
313
|
+
ver = Phidgets.malloc(SIZEOF_INT)
|
314
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getDeviceVersion', @handle, ver.ref)
|
346
315
|
raise Phidgets::Exception.new(r) if r != 0
|
347
316
|
ver.free = nil
|
348
317
|
ver.to_i
|
@@ -350,8 +319,8 @@ module Phidgets
|
|
350
319
|
|
351
320
|
# Gets the attached status of a Phidget.
|
352
321
|
def getDeviceStatus
|
353
|
-
stat =
|
354
|
-
r = Phidgets.
|
322
|
+
stat = Phidgets.malloc(SIZEOF_INT)
|
323
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getDeviceStatus', @handle, stat.ref)
|
355
324
|
raise Phidgets::Exception.new(r) if r != 0
|
356
325
|
stat.free = nil
|
357
326
|
stat.to_i
|
@@ -359,8 +328,8 @@ module Phidgets
|
|
359
328
|
|
360
329
|
# Gets the type (class) of a Phidget.
|
361
330
|
def getDeviceType
|
362
|
-
ptr =
|
363
|
-
r = Phidgets.
|
331
|
+
ptr = Phidgets.malloc(SIZEOF_VOIDP)
|
332
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getDeviceType', @handle, ptr.ref)
|
364
333
|
raise Phidgets::Exception.new(r) if r != 0
|
365
334
|
ptr.free = nil
|
366
335
|
ptr.to_s
|
@@ -368,8 +337,8 @@ module Phidgets
|
|
368
337
|
|
369
338
|
# Gets the label of a Phidget.
|
370
339
|
def getDeviceLabel
|
371
|
-
ptr =
|
372
|
-
r = Phidgets.
|
340
|
+
ptr = Phidgets.malloc(SIZEOF_VOIDP)
|
341
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getDeviceLabel', @handle, ptr.ref)
|
373
342
|
raise Phidgets::Exception.new(r) if r != 0
|
374
343
|
ptr.free = nil
|
375
344
|
ptr.to_s
|
@@ -379,7 +348,7 @@ module Phidgets
|
|
379
348
|
# === Parameters
|
380
349
|
# * _label_ = A string containing the label to be set.
|
381
350
|
def setDeviceLabel(label)
|
382
|
-
r = Phidgets.
|
351
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_setDeviceLabel', @handle, label)
|
383
352
|
raise Phidgets::Exception.new(r) if r != 0
|
384
353
|
end
|
385
354
|
|
@@ -387,14 +356,14 @@ module Phidgets
|
|
387
356
|
# === Parameters
|
388
357
|
# * _timeout_ = Time to wait for the attachment. Specify 0 to wait forever.
|
389
358
|
def waitForAttachment(timeout)
|
390
|
-
r = Phidgets.
|
359
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_waitForAttachment', @handle, timeout)
|
391
360
|
raise Phidgets::Exception.new(r) if r != 0
|
392
361
|
end
|
393
362
|
|
394
363
|
# Gets the server ID of a remotely opened Phidget. This will fail if the Phidget was opened locally.
|
395
364
|
def getServerID
|
396
|
-
ptr =
|
397
|
-
r = Phidgets.
|
365
|
+
ptr = Phidgets.malloc(SIZEOF_VOIDP)
|
366
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getServerID', @handle, ptr.ref)
|
398
367
|
raise Phidgets::Exception.new(r) if r != 0
|
399
368
|
ptr.free = nil
|
400
369
|
ptr.to_s
|
@@ -402,9 +371,9 @@ module Phidgets
|
|
402
371
|
|
403
372
|
# Gets the address and port of a remotely opened Phidget. This will fail if the Phidget was opened locally.
|
404
373
|
def getServerAddress
|
405
|
-
ptr =
|
406
|
-
port =
|
407
|
-
r = Phidgets.
|
374
|
+
ptr = Phidgets.malloc(SIZEOF_VOIDP)
|
375
|
+
port = Phidgets.malloc(SIZEOF_INT)
|
376
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getServerAddress', @handle, ptr.ref, port.ref)
|
408
377
|
raise Phidgets::Exception.new(r) if r != 0
|
409
378
|
ptr.free = nil
|
410
379
|
port.free = nil
|
@@ -413,8 +382,8 @@ module Phidgets
|
|
413
382
|
|
414
383
|
# Gets the connected to server status of a remotely opened Phidget. This will fail if the Phidget was opened locally.
|
415
384
|
def getServerStatus
|
416
|
-
stat =
|
417
|
-
r = Phidgets.
|
385
|
+
stat = Phidgets.malloc(SIZEOF_INT)
|
386
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getServerStatus', @handle, stat.ref)
|
418
387
|
raise Phidgets::Exception.new(r) if r != 0
|
419
388
|
stat.free = nil
|
420
389
|
stat.to_i
|
@@ -422,8 +391,8 @@ module Phidgets
|
|
422
391
|
|
423
392
|
# Gets the device ID of a Phidget.
|
424
393
|
def getDeviceID
|
425
|
-
dev =
|
426
|
-
r = Phidgets.
|
394
|
+
dev = Phidgets.malloc(SIZEOF_INT)
|
395
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getDeviceID', @handle, dev.ref)
|
427
396
|
raise Phidgets::Exception.new(r) if r != 0
|
428
397
|
dev.free = nil
|
429
398
|
dev.to_i
|
@@ -431,8 +400,8 @@ module Phidgets
|
|
431
400
|
|
432
401
|
# Gets the class of a Phidget.
|
433
402
|
def getDeviceClass
|
434
|
-
dev =
|
435
|
-
r = Phidgets.
|
403
|
+
dev = Phidgets.malloc(SIZEOF_INT)
|
404
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getDeviceClass', @handle, dev.ref)
|
436
405
|
raise Phidgets::Exception.new(r) if r != 0
|
437
406
|
dev.free = nil
|
438
407
|
dev.to_i
|
@@ -442,7 +411,7 @@ module Phidgets
|
|
442
411
|
private
|
443
412
|
|
444
413
|
def initialize
|
445
|
-
@handle =
|
414
|
+
@handle = Phidgets.malloc(SIZEOF_VOIDP)
|
446
415
|
end
|
447
416
|
|
448
417
|
end
|
@@ -29,8 +29,8 @@ module Phidgets
|
|
29
29
|
|
30
30
|
# Gets the number of digital inputs supported by this board.
|
31
31
|
def getInputCount
|
32
|
-
cnt =
|
33
|
-
r = Phidgets.
|
32
|
+
cnt = Phidgets.malloc(SIZEOF_INT)
|
33
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getInputCount', @handle, cnt.ref)
|
34
34
|
raise Phidgets::Exception.new(r) if r != 0
|
35
35
|
cnt.free = nil
|
36
36
|
cnt.to_i
|
@@ -40,8 +40,8 @@ module Phidgets
|
|
40
40
|
# === Parameters
|
41
41
|
# * _index_ = The input index.
|
42
42
|
def getInputState(index)
|
43
|
-
state =
|
44
|
-
r = Phidgets.
|
43
|
+
state = Phidgets.malloc(SIZEOF_INT)
|
44
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getInputState', @handle, index, state.ref)
|
45
45
|
raise Phidgets::Exception.new(r) if r != 0
|
46
46
|
state.free = nil
|
47
47
|
state.to_i
|
@@ -49,8 +49,8 @@ module Phidgets
|
|
49
49
|
|
50
50
|
# Gets the number of digital outputs supported by this board.
|
51
51
|
def getOutputCount
|
52
|
-
cnt =
|
53
|
-
r = Phidgets.
|
52
|
+
cnt = Phidgets.malloc(SIZEOF_INT)
|
53
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getOutputCount', @handle, cnt.ref)
|
54
54
|
raise Phidgets::Exception.new(r) if r != 0
|
55
55
|
cnt.free = nil
|
56
56
|
cnt.to_i
|
@@ -60,8 +60,8 @@ module Phidgets
|
|
60
60
|
# === Parameters
|
61
61
|
# * _index_ = The output index.
|
62
62
|
def getOutputState(index)
|
63
|
-
state =
|
64
|
-
r = Phidgets.
|
63
|
+
state = Phidgets.malloc(SIZEOF_INT)
|
64
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getOutputState', @handle, index, state.ref)
|
65
65
|
raise Phidgets::Exception.new(r) if r != 0
|
66
66
|
state.free = nil
|
67
67
|
state.to_i
|
@@ -72,14 +72,14 @@ module Phidgets
|
|
72
72
|
# * _index_ = The output index.
|
73
73
|
# * _state_ = The output state. Possible values are PTRUE and PFALSE.
|
74
74
|
def setOutputState(index, state)
|
75
|
-
r = Phidgets.
|
75
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_setOutputState', @handle, index, state)
|
76
76
|
raise Phidgets::Exception.new(r) if r != 0
|
77
77
|
end
|
78
78
|
|
79
79
|
# Gets the number of sensor (analog) inputs supported by this board.
|
80
80
|
def getSensorCount
|
81
|
-
cnt =
|
82
|
-
r = Phidgets.
|
81
|
+
cnt = Phidgets.malloc(SIZEOF_INT)
|
82
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getSensorCount', @handle, cnt.ref)
|
83
83
|
raise Phidgets::Exception.new(r) if r != 0
|
84
84
|
cnt.free = nil
|
85
85
|
cnt.to_i
|
@@ -89,8 +89,8 @@ module Phidgets
|
|
89
89
|
# === Parameters
|
90
90
|
# * _index_ = The sensor index.
|
91
91
|
def getSensorValue(index)
|
92
|
-
state =
|
93
|
-
r = Phidgets.
|
92
|
+
state = Phidgets.malloc(SIZEOF_INT)
|
93
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getSensorValue', @handle, index, state.ref)
|
94
94
|
raise Phidgets::Exception.new(r) if r != 0
|
95
95
|
state.free = nil
|
96
96
|
state.to_i
|
@@ -100,8 +100,8 @@ module Phidgets
|
|
100
100
|
# === Parameters
|
101
101
|
# * _index_ = The sensor index.
|
102
102
|
def getSensorRawValue(index)
|
103
|
-
state =
|
104
|
-
r = Phidgets.
|
103
|
+
state = Phidgets.malloc(SIZEOF_INT)
|
104
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getSensorRawValue', @handle, index, state.ref)
|
105
105
|
raise Phidgets::Exception.new(r) if r != 0
|
106
106
|
state.free = nil
|
107
107
|
state.to_i
|
@@ -109,8 +109,8 @@ module Phidgets
|
|
109
109
|
|
110
110
|
# Gets the ratiometric state for this board.
|
111
111
|
def getRatiometric
|
112
|
-
ratio =
|
113
|
-
r = Phidgets.
|
112
|
+
ratio = Phidgets.malloc(SIZEOF_INT)
|
113
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_getRatiometric', @handle, ratio.ref)
|
114
114
|
raise Phidgets::Exception.new(r) if r != 0
|
115
115
|
ratio.free = nil
|
116
116
|
ratio.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.
|
123
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_setRatiometric', @handle, ratiometric)
|
124
124
|
raise Phidgets::Exception.new(r) if r != 0
|
125
125
|
end
|
126
126
|
|
@@ -129,7 +129,7 @@ module Phidgets
|
|
129
129
|
|
130
130
|
# Creates a Phidget InterfaceKit handle.
|
131
131
|
def create
|
132
|
-
r = Phidgets.
|
132
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetInterfaceKit_create', @handle.ref)
|
133
133
|
raise Phidgets::Exception.new(r) if r != 0
|
134
134
|
end
|
135
135
|
|
data/lib/phidgets/rfid.rb
CHANGED
@@ -12,8 +12,6 @@ module Phidgets
|
|
12
12
|
extern "int CPhidgetRFID_setLEDOn(void *, int, int *)"
|
13
13
|
extern "int CPhidgetRFID_getLastTag(void *, int, int *)"
|
14
14
|
extern "int CPhidgetRFID_getTagStatus(void *, int *)"
|
15
|
-
extern "int CPhidgetRFID_set_OnTag_Handler(void *, int)"
|
16
|
-
extern "int CPhidgetRFID_set_OnTagLost_Handler(void *, int)"
|
17
15
|
|
18
16
|
|
19
17
|
class RFID < Common
|
@@ -30,8 +28,8 @@ module Phidgets
|
|
30
28
|
|
31
29
|
# Gets the number of outputs supported by this board.
|
32
30
|
def getOutputCount
|
33
|
-
cnt =
|
34
|
-
r = Phidgets.
|
31
|
+
cnt = Phidgets.malloc(SIZEOF_INT)
|
32
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getOutputCount', @handle, cnt.ref)
|
35
33
|
raise Phidgets::Exception.new(r) if r != 0
|
36
34
|
cnt.free = nil
|
37
35
|
cnt.to_i
|
@@ -41,8 +39,8 @@ module Phidgets
|
|
41
39
|
# === Parameters
|
42
40
|
# * _index_ = The output index.
|
43
41
|
def getOutputState(index)
|
44
|
-
state =
|
45
|
-
r = Phidgets.
|
42
|
+
state = Phidgets.malloc(SIZEOF_INT)
|
43
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getOutputState', @handle, index, state.ref)
|
46
44
|
raise Phidgets::Exception.new(r) if r != 0
|
47
45
|
state.free = nil
|
48
46
|
state.to_i
|
@@ -53,14 +51,14 @@ module Phidgets
|
|
53
51
|
# * _index_ = The output index.
|
54
52
|
# * _state_ = The output state. Possible values are PTRUE and PFALSE.
|
55
53
|
def setOutputState(index, state)
|
56
|
-
r = Phidgets.
|
54
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_setOutputState', @handle, index, state)
|
57
55
|
raise Phidgets::Exception.new(r) if r != 0
|
58
56
|
end
|
59
57
|
|
60
58
|
# Gets the state of the antenna.
|
61
59
|
def getAntennaOn
|
62
|
-
state =
|
63
|
-
r = Phidgets.
|
60
|
+
state = Phidgets.malloc(SIZEOF_INT)
|
61
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getAntennaOn', @handle, state.ref)
|
64
62
|
raise Phidgets::Exception.new(r) if r != 0
|
65
63
|
state.free = nil
|
66
64
|
state.to_i
|
@@ -70,14 +68,14 @@ module Phidgets
|
|
70
68
|
# === Parameters
|
71
69
|
# * _state_ = The antenna state. Possible values are PTRUE and PFALSE.
|
72
70
|
def setAntennaOn(state)
|
73
|
-
r = Phidgets.
|
71
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_setAntennaOn', @handle, state)
|
74
72
|
raise Phidgets::Exception.new(r) if r != 0
|
75
73
|
end
|
76
74
|
|
77
75
|
# Gets the state of the onboard LED.
|
78
76
|
def getLedOn
|
79
|
-
state =
|
80
|
-
r = Phidgets.
|
77
|
+
state = Phidgets.malloc(SIZEOF_INT)
|
78
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getLEDOn', @handle, state.ref)
|
81
79
|
raise Phidgets::Exception.new(r) if r != 0
|
82
80
|
state.free = nil
|
83
81
|
state.to_i
|
@@ -87,22 +85,22 @@ module Phidgets
|
|
87
85
|
# === Parameters
|
88
86
|
# * _state_ = The LED state. Possible values are PTRUE and PFALSE.
|
89
87
|
def setLedOn(state)
|
90
|
-
r = Phidgets.
|
88
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_setLEDOn', @handle, state)
|
91
89
|
raise Phidgets::Exception.new(r) if r != 0
|
92
90
|
end
|
93
91
|
|
94
92
|
# Gets the last tag read by the reader. This tag may or may not still be on the reader.
|
95
93
|
def getLastTag
|
96
|
-
tag =
|
97
|
-
r = Phidgets.
|
94
|
+
tag = Phidgets.malloc(5)
|
95
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getLastTag', @handle, tag)
|
98
96
|
raise Phidgets::Exception.new(r) if r != 0
|
99
97
|
tag
|
100
98
|
end
|
101
99
|
|
102
100
|
# Gets the tag present status. This is whether or not a tag is being read by the reader.
|
103
101
|
def getTagStatus
|
104
|
-
stat =
|
105
|
-
r = Phidgets.
|
102
|
+
stat = Phidgets.malloc(SIZEOF_INT)
|
103
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getTagStatus', @handle, stat.ref)
|
106
104
|
raise Phidgets::Exception.new(r) if r != 0
|
107
105
|
stat.free = nil
|
108
106
|
stat.to_i
|
@@ -113,7 +111,7 @@ module Phidgets
|
|
113
111
|
|
114
112
|
# Creates a Phidget RFID handle.
|
115
113
|
def create
|
116
|
-
r = Phidgets.
|
114
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_create', @handle.ref)
|
117
115
|
raise Phidgets::Exception.new(r) if r != 0
|
118
116
|
end
|
119
117
|
|
data/lib/phidgets/servo.rb
CHANGED
@@ -24,8 +24,8 @@ module Phidgets
|
|
24
24
|
|
25
25
|
# Gets the number of motors supported by this controller.
|
26
26
|
def getMotorCount
|
27
|
-
cnt =
|
28
|
-
r = Phidgets.
|
27
|
+
cnt = Phidgets.malloc(SIZEOF_INT)
|
28
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getMotorCount', @handle, cnt.ref)
|
29
29
|
raise Phidgets::Exception.new(r) if r != 0
|
30
30
|
cnt.free = nil
|
31
31
|
cnt.to_i
|
@@ -35,8 +35,8 @@ module Phidgets
|
|
35
35
|
# === Parameters
|
36
36
|
# * _index_ = The motor index.
|
37
37
|
def getPosition(index)
|
38
|
-
pos =
|
39
|
-
r = Phidgets.
|
38
|
+
pos = Phidgets.malloc(SIZEOF_DOUBLE)
|
39
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getPosition', @handle, index, 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.
|
50
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_setPosition', @handle, index, position)
|
51
51
|
raise Phidgets::Exception.new(r) if r != 0
|
52
52
|
end
|
53
53
|
|
@@ -55,8 +55,8 @@ module Phidgets
|
|
55
55
|
# === Parameters
|
56
56
|
# * _index_ = The motor index.
|
57
57
|
def getPositionMax(index)
|
58
|
-
pos =
|
59
|
-
r = Phidgets.
|
58
|
+
pos = Phidgets.malloc(SIZEOF_DOUBLE)
|
59
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getPositionMax', @handle, index, pos.ref)
|
60
60
|
raise Phidgets::Exception.new(r) if r != 0
|
61
61
|
pos.free = nil
|
62
62
|
pos.to_f
|
@@ -66,8 +66,8 @@ module Phidgets
|
|
66
66
|
# === Parameters
|
67
67
|
# * _index_ = The motor index.
|
68
68
|
def getPositionMin(index)
|
69
|
-
pos =
|
70
|
-
r = Phidgets.
|
69
|
+
pos = Phidgets.malloc(SIZEOF_DOUBLE)
|
70
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getPositionMin', @handle, index, pos.ref)
|
71
71
|
raise Phidgets::Exception.new(r) if r != 0
|
72
72
|
pos.free = nil
|
73
73
|
pos.to_f
|
@@ -77,8 +77,8 @@ module Phidgets
|
|
77
77
|
# === Parameters
|
78
78
|
# * _index_ = The motor index.
|
79
79
|
def getEngaged(index)
|
80
|
-
eng =
|
81
|
-
r = Phidgets.
|
80
|
+
eng = Phidgets.malloc(SIZEOF_INT)
|
81
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getEngaged', @handle, index, 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.
|
92
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_setEngaged', @handle, index, state)
|
93
93
|
raise Phidgets::Exception.new(r) if r != 0
|
94
94
|
end
|
95
95
|
|
@@ -97,7 +97,7 @@ module Phidgets
|
|
97
97
|
|
98
98
|
# Creates a Phidget Servo handle.
|
99
99
|
def create
|
100
|
-
r = Phidgets.
|
100
|
+
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_create', @handle.ref)
|
101
101
|
raise Phidgets::Exception.new(r) if r != 0
|
102
102
|
end
|
103
103
|
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phidgets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Craig DeHaan
|
@@ -9,29 +14,37 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-09-14 00:00:00 -04:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: rubyforge
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 0
|
30
|
+
- 4
|
23
31
|
version: 2.0.4
|
24
|
-
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: hoe
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 6
|
44
|
+
- 0
|
33
45
|
version: 2.6.0
|
34
|
-
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
35
48
|
description: |-
|
36
49
|
Phidgets are a set of "plug and play" building blocks for low cost USB sensing and control from your PC.
|
37
50
|
This gem provides a ruby interface to the phidgets library.
|
@@ -80,22 +93,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
93
|
requirements:
|
81
94
|
- - ">="
|
82
95
|
- !ruby/object:Gem::Version
|
96
|
+
segments:
|
97
|
+
- 0
|
83
98
|
version: "0"
|
84
|
-
version:
|
85
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - ">="
|
88
102
|
- !ruby/object:Gem::Version
|
103
|
+
segments:
|
104
|
+
- 0
|
89
105
|
version: "0"
|
90
|
-
version:
|
91
106
|
requirements: []
|
92
107
|
|
93
108
|
rubyforge_project: phidgets
|
94
|
-
rubygems_version: 1.3.
|
109
|
+
rubygems_version: 1.3.6
|
95
110
|
signing_key:
|
96
111
|
specification_version: 3
|
97
112
|
summary: Phidgets are a set of "plug and play" building blocks for low cost USB sensing and control from your PC
|
98
113
|
test_files:
|
99
|
-
- test/test_phidgets.rb
|
100
|
-
- test/test_helper.rb
|
101
114
|
- test/test_interfacekit.rb
|
115
|
+
- test/test_helper.rb
|
116
|
+
- test/test_phidgets.rb
|