phidgets4r 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/GNU_GPL.txt +340 -0
- data/README.rdoc +72 -0
- data/Rakefile +67 -0
- data/lib/phidgets/common.rb +409 -0
- data/lib/phidgets/interfacekit.rb +78 -0
- data/lib/phidgets/rfid.rb +83 -0
- data/lib/phidgets/servo.rb +64 -0
- data/lib/phidgets.rb +11 -0
- data/test/test_helper.rb +3 -0
- data/test/test_interfacekit.rb +194 -0
- data/test/test_phidgets.rb +5 -0
- data/test/test_servo.rb +146 -0
- metadata +73 -0
@@ -0,0 +1,409 @@
|
|
1
|
+
|
2
|
+
require 'dl'
|
3
|
+
require 'rbconfig'
|
4
|
+
|
5
|
+
module Phidgets
|
6
|
+
|
7
|
+
NOTATTACHED = 0
|
8
|
+
ATTACHED = 1
|
9
|
+
|
10
|
+
CLASS_NOTHING = 1
|
11
|
+
CLASS_ACCELEROMETER = 2
|
12
|
+
CLASS_ADVANCEDSERVO = 3
|
13
|
+
CLASS_ENCODER = 4
|
14
|
+
CLASS_GPS = 5
|
15
|
+
CLASS_GYROSCOPE = 6
|
16
|
+
CLASS_INTERFACEKIT = 7
|
17
|
+
CLASS_LED = 8
|
18
|
+
CLASS_MOTORCONTROL = 9
|
19
|
+
CLASS_PHSENSOR = 10
|
20
|
+
CLASS_RFID = 11
|
21
|
+
CLASS_SERVO = 12
|
22
|
+
CLASS_STEPPER = 13
|
23
|
+
CLASS_TEMPERATURESENSOR = 14
|
24
|
+
CLASS_TEXTLCD = 15
|
25
|
+
CLASS_TEXTLED = 16
|
26
|
+
CLASS_WEIGHTSENSOR = 17
|
27
|
+
|
28
|
+
ID_ACCELEROMETER_2AXIS = 0x071
|
29
|
+
ID_ACCELEROMETER_3AXIS = 0x07E
|
30
|
+
ID_ADVANCEDSERVO_8MOTOR = 0x03A
|
31
|
+
ID_BIPOLAR_STEPPER_1MOTOR = 0x07B
|
32
|
+
ID_ENCODER_1ENCODER_1INPUT = 0x04B
|
33
|
+
ID_ENCODER_HS_1ENCODER = 0x080
|
34
|
+
ID_INTERFACEKIT_0_0_4 = 0x040
|
35
|
+
ID_INTERFACEKIT_0_0_8 = 0x081
|
36
|
+
ID_INTERFACEKIT_0_16_16 = 0x044
|
37
|
+
ID_INTERFACEKIT_8_8_8 = 0x045
|
38
|
+
ID_INTERFACEKIT_8_8_8_w_LCD = 0x07D
|
39
|
+
ID_LED_64 = 0x04A
|
40
|
+
ID_LINEAR_TOUCH = 0x076
|
41
|
+
ID_MOTORCONTROL_HC_2MOTOR = 0x059
|
42
|
+
ID_MOTORCONTROL_LV_2MOTOR_4INPUT = 0x058
|
43
|
+
ID_PHSENSOR = 0x074
|
44
|
+
ID_RFID_2OUTPUT = 0x031
|
45
|
+
ID_ROTARY_TOUCH = 0x077
|
46
|
+
ID_SERVO_1MOTOR = 0x039
|
47
|
+
ID_TEMPERATURESENSOR = 0x070
|
48
|
+
ID_TEXTLCD_2x20_w_8_8_8 = 0x17D
|
49
|
+
ID_UNIPOLAR_STEPPER_4MOTOR = 0x07A
|
50
|
+
ID_INTERFACEKIT_0_8_8_w_LCD = 0x053
|
51
|
+
ID_INTERFACEKIT_4_8_8 = 0x004
|
52
|
+
ID_RFID = 0x030
|
53
|
+
ID_SERVO_1MOTOR_OLD = 0x002
|
54
|
+
ID_SERVO_4MOTOR = 0x038
|
55
|
+
ID_SERVO_4MOTOR_OLD = 0x003
|
56
|
+
ID_TEXTLCD_2x20 = 0x052
|
57
|
+
ID_TEXTLCD_2x20_w_0_8_8 = 0x153
|
58
|
+
ID_TEXTLED_1x8 = 0x049
|
59
|
+
ID_TEXTLED_4x8 = 0x048
|
60
|
+
ID_WEIGHTSENSOR = 0x072
|
61
|
+
|
62
|
+
def Phidgets.setLibName(name)
|
63
|
+
Common.setLibName(name)
|
64
|
+
end
|
65
|
+
|
66
|
+
class Exception < RuntimeError
|
67
|
+
attr_reader :code
|
68
|
+
|
69
|
+
EPHIDGET_NOTFOUND = 1
|
70
|
+
EPHIDGET_NOMEMORY = 2
|
71
|
+
EPHIDGET_UNEXPECTED = 3
|
72
|
+
EPHIDGET_INVALIDARG = 4
|
73
|
+
EPHIDGET_NOTATTACHED = 5
|
74
|
+
EPHIDGET_INTERRUPTED = 6
|
75
|
+
EPHIDGET_INVALID = 7
|
76
|
+
EPHIDGET_NETWORK = 8
|
77
|
+
EPHIDGET_UNKNOWNVAL = 9
|
78
|
+
EPHIDGET_BADPASSWORD = 10
|
79
|
+
EPHIDGET_UNSUPPORTED = 11
|
80
|
+
EPHIDGET_DUPLICATE = 12
|
81
|
+
EPHIDGET_TIMEOUT = 13
|
82
|
+
EPHIDGET_OUTOFBOUNDS = 14
|
83
|
+
EPHIDGET_EVENT = 15
|
84
|
+
EPHIDGET_NETWORK_NOTCONNECTED = 16
|
85
|
+
EPHIDGET_WRONGDEVICE = 17
|
86
|
+
EPHIDGET_CLOSED = 18
|
87
|
+
EPHIDGET_BADVERSION = 19
|
88
|
+
|
89
|
+
def initialize(code)
|
90
|
+
@code = code
|
91
|
+
case code
|
92
|
+
when -2
|
93
|
+
super('Failed to load Phidgets Library')
|
94
|
+
when -1
|
95
|
+
super('Unable to determine Phidgets Library name.')
|
96
|
+
when EPHIDGET_NOTFOUND
|
97
|
+
super('A Phidget matching the type and or serial number could not be found.')
|
98
|
+
when EPHIDGET_NOMEMORY
|
99
|
+
super('Memory could not be allocated.')
|
100
|
+
when EPHIDGET_UNEXPECTED
|
101
|
+
super('Unexpected Error. Contact Phidgets Inc. for support.')
|
102
|
+
when EPHIDGET_INVALIDARG
|
103
|
+
super('Invalid argument passed to function.')
|
104
|
+
when EPHIDGET_NOTATTACHED
|
105
|
+
super('Phidget not physically attached.')
|
106
|
+
when EPHIDGET_INTERRUPTED
|
107
|
+
super('Read/Write operation was interrupted.')
|
108
|
+
when EPHIDGET_INVALID
|
109
|
+
super('The Error Code is not defined.')
|
110
|
+
when EPHIDGET_NETWORK
|
111
|
+
super('Network Error.')
|
112
|
+
when EPHIDGET_UNKNOWNVAL
|
113
|
+
super('Value is Unknown (State not yet received from device, or not yet set by user).')
|
114
|
+
when EPHIDGET_BADPASSWORD
|
115
|
+
super('Authorization Failed.')
|
116
|
+
when EPHIDGET_UNSUPPORTED
|
117
|
+
super('Not Supported.')
|
118
|
+
when EPHIDGET_DUPLICATE
|
119
|
+
super('Duplicated request.')
|
120
|
+
when EPHIDGET_TIMEOUT
|
121
|
+
super('Given timeout has been exceeded.')
|
122
|
+
when EPHIDGET_OUTOFBOUNDS
|
123
|
+
super('Index out of Bounds.')
|
124
|
+
when EPHIDGET_EVENT
|
125
|
+
super('A non-null error code was returned from an event handler.')
|
126
|
+
when EPHIDGET_NETWORK_NOTCONNECTED
|
127
|
+
super('A connection to the server does not exist.')
|
128
|
+
when EPHIDGET_WRONGDEVICE
|
129
|
+
super('Function is not applicable for this device.')
|
130
|
+
when EPHIDGET_CLOSED
|
131
|
+
super('Phidget handle was closed.')
|
132
|
+
when EPHIDGET_BADVERSION
|
133
|
+
super('Webservice and Client protocol versions don’t match. Update to newest release.')
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
class Common
|
140
|
+
@@libname = nil
|
141
|
+
@@lib = nil
|
142
|
+
@@open_remote = nil
|
143
|
+
@@open_remote_ip = nil
|
144
|
+
@@open = nil
|
145
|
+
@@close = nil
|
146
|
+
@@delete = nil
|
147
|
+
@@detach_handler = nil
|
148
|
+
@@attach_handler = nil
|
149
|
+
@@connect_handler = nil
|
150
|
+
@@disconnect_handler = nil
|
151
|
+
@@error_handler = nil
|
152
|
+
@@name = nil
|
153
|
+
@@serial = nil
|
154
|
+
@@version = nil
|
155
|
+
@@status = nil
|
156
|
+
@@lib_version = nil
|
157
|
+
@@type = nil
|
158
|
+
@@get_label = nil
|
159
|
+
@@set_label = nil
|
160
|
+
@@error_description = nil
|
161
|
+
@@wait = nil
|
162
|
+
@@server_id = nil
|
163
|
+
@@server_addr = nil
|
164
|
+
@@server_status = nil
|
165
|
+
@@device_id = nil
|
166
|
+
@@device_class = nil
|
167
|
+
|
168
|
+
def initialize
|
169
|
+
if @@libname == nil
|
170
|
+
case Config::CONFIG['target_os']
|
171
|
+
when 'linux'
|
172
|
+
@@libname = 'libphidget21.so'
|
173
|
+
when 'mswin32'
|
174
|
+
@@libname = 'phidget21.dll'
|
175
|
+
when 'darwin10.2.0'
|
176
|
+
@@libname = '/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21'
|
177
|
+
when 'darwin10.3.0'
|
178
|
+
@@libname = '/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21'
|
179
|
+
else
|
180
|
+
raise Phidgets::Exception.new(-1)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
begin
|
185
|
+
@@lib = DL.dlopen(@@libname)
|
186
|
+
rescue
|
187
|
+
raise Phidgets::Exception.new(-2)
|
188
|
+
end
|
189
|
+
|
190
|
+
@handle = DL.malloc(DL.sizeof('P'))
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
private
|
195
|
+
|
196
|
+
def sym(name, interface)
|
197
|
+
@@lib[name, interface]
|
198
|
+
end
|
199
|
+
|
200
|
+
def call_IX(sym_name, func_name, format, arg1)
|
201
|
+
sym_name = sym(func_name, format) if sym_name == nil
|
202
|
+
r,rs = sym_name.call(arg1)
|
203
|
+
raise Phidgets::Exception.new(r) if r != 0
|
204
|
+
end
|
205
|
+
|
206
|
+
def call_IXX(sym_name, func_name, format, arg1, arg2)
|
207
|
+
sym_name = sym(func_name, format) if sym_name == nil
|
208
|
+
r,rs = sym_name.call(arg1, arg2)
|
209
|
+
raise Phidgets::Exception.new(r) if r != 0
|
210
|
+
end
|
211
|
+
|
212
|
+
def call_IXXX(sym_name, func_name, format, arg1, arg2, arg3)
|
213
|
+
puts "in call_IXXX format: #{format}"
|
214
|
+
sym_name = sym(func_name, format) if sym_name == nil
|
215
|
+
r,rs = sym_name.call(arg1, arg2, arg3)
|
216
|
+
puts "r: #{r} - rs: #{rs[2]}"
|
217
|
+
raise Phidgets::Exception.new(r) if r != 0
|
218
|
+
end
|
219
|
+
|
220
|
+
def call_IXXXX(sym_name, func_name, format, arg1, arg2, arg3, arg4)
|
221
|
+
sym_name = sym(func_name, format) if sym_name == nil
|
222
|
+
r,rs = sym_name.call(arg1, arg2, arg3, arg4)
|
223
|
+
raise Phidgets::Exception.new(r) if r != 0
|
224
|
+
end
|
225
|
+
|
226
|
+
def call_IXXXXX(sym_name, func_name, format, arg1, arg2, arg3, arg4, arg5)
|
227
|
+
sym_name = sym(func_name, format) if sym_name == nil
|
228
|
+
r,rs = sym_name.call(arg1, arg2, arg3, arg4, arg5)
|
229
|
+
raise Phidgets::Exception.new(r) if r != 0
|
230
|
+
end
|
231
|
+
|
232
|
+
def call_IPi(sym_name, func_name, arg1)
|
233
|
+
sym_name = sym(func_name, 'IPi') if sym_name == nil
|
234
|
+
return_arg = 0
|
235
|
+
r,rs = sym_name.call(arg1, return_arg)
|
236
|
+
raise Phidgets::Exception.new(r) if r != 0
|
237
|
+
rs[1]
|
238
|
+
end
|
239
|
+
|
240
|
+
def call_IPIi(sym_name, func_name, arg1, arg2)
|
241
|
+
sym_name = sym(func_name, 'IPIi') if sym_name == nil
|
242
|
+
return_arg = 0
|
243
|
+
r,rs = sym_name.call(arg1, arg2, return_arg)
|
244
|
+
raise Phidgets::Exception.new(r) if r != 0
|
245
|
+
rs[2]
|
246
|
+
end
|
247
|
+
|
248
|
+
def call_IPId(sym_name, func_name, arg1, arg2)
|
249
|
+
sym_name = sym(func_name, 'IPId') if sym_name == nil
|
250
|
+
return_arg = 0.0
|
251
|
+
r,rs = sym_name.call(arg1, arg2, return_arg)
|
252
|
+
raise Phidgets::Exception.new(r) if r != 0.0
|
253
|
+
rs[2]
|
254
|
+
end
|
255
|
+
|
256
|
+
def call_IPs(sym_name, func_name, arg1)
|
257
|
+
sym_name = sym(func_name, 'IPp') if sym_name == nil
|
258
|
+
arg_ptr = DL.malloc(DL.sizeof('P'))
|
259
|
+
r,rs = sym_name.call(arg1, arg_ptr.ref)
|
260
|
+
raise Phidgets::Exception.new(r) if r != 0
|
261
|
+
arg_ptr.free = nil
|
262
|
+
arg_ptr.to_s
|
263
|
+
end
|
264
|
+
|
265
|
+
def createCallback(callback)
|
266
|
+
DL.callback('IPP') {|handle,data|
|
267
|
+
data = ObjectSpace._id2ref(data.to_i)
|
268
|
+
eval("#{callback}(data)")
|
269
|
+
}
|
270
|
+
end
|
271
|
+
|
272
|
+
def createErrorCallback(callback)
|
273
|
+
DL.callback('IPPIS') {|handle,data,error_code,error_string|
|
274
|
+
data = ObjectSpace._id2ref(data.to_i)
|
275
|
+
eval("#{callback}(data,error_code,error_string)")
|
276
|
+
}
|
277
|
+
end
|
278
|
+
|
279
|
+
public
|
280
|
+
|
281
|
+
def Common.setLibName(name)
|
282
|
+
@@libname = name
|
283
|
+
end
|
284
|
+
|
285
|
+
def openRemote(serial_number=-1, server=nil, password=nil, timeout=0)
|
286
|
+
call_IXXXX(@@open_remote, 'CPhidget_openRemote', 'IPISS', @handle, serial_number, server, password)
|
287
|
+
waitForAttachment(timeout) if timeout > 0
|
288
|
+
end
|
289
|
+
|
290
|
+
def openRemoteIP(serial_number, address, port=5001, password=nil, timeout=0)
|
291
|
+
call_IXXXXX(@@open_remote_ip, 'CPhidget_openRemoteIP', 'IPISIS', @handle, serial_number, address, port, password)
|
292
|
+
waitForAttachment(timeout) if timeout > 0
|
293
|
+
end
|
294
|
+
|
295
|
+
def open(serial_number=-1, timeout=0)
|
296
|
+
call_IXX(@@open, 'CPhidget_open', 'IPI', @handle, serial_number)
|
297
|
+
waitForAttachment(timeout) if timeout > 0
|
298
|
+
end
|
299
|
+
|
300
|
+
def close
|
301
|
+
call_IX(@@close, 'CPhidget_close', 'IP', @handle)
|
302
|
+
end
|
303
|
+
|
304
|
+
def delete
|
305
|
+
@handle.free = nil
|
306
|
+
call_IX(@@delete, 'CPhidget_delete', 'IP', @handle)
|
307
|
+
end
|
308
|
+
|
309
|
+
def setOnDetachHandler(callback, data)
|
310
|
+
call_IXXX(@@detach_handler, 'CPhidget_set_OnDetach_Handler', 'IPPP', @handle, createCallback(callback), DL::PtrData.new(data.object_id))
|
311
|
+
end
|
312
|
+
|
313
|
+
def setOnAttachHandler(callback, data)
|
314
|
+
call_IXXX(@@attach_handler, 'CPhidget_set_OnAttach_Handler', 'IPPP', @handle, createCallback(callback), DL::PtrData.new(data.object_id))
|
315
|
+
end
|
316
|
+
|
317
|
+
def setOnConnectHandler(callback, data)
|
318
|
+
call_IXXX(@@connect_handler, 'CPhidget_set_OnServerConnect_Handler', 'IPPP', @handle, createCallback(callback), DL::PtrData.new(data.object_id))
|
319
|
+
end
|
320
|
+
|
321
|
+
def setOnDisconnectHandler(callback, data)
|
322
|
+
call_IXXX(@@disconnect_handler, 'CPhidget_set_OnServerDisconnect_Handler', 'IPPP', @handle, createCallback(callback), DL::PtrData.new(data.object_id))
|
323
|
+
end
|
324
|
+
|
325
|
+
def setOnErrorHandler(callback, data)
|
326
|
+
call_IXXX(@@error_handler, 'CPhidget_set_OnError_Handler', 'IPPP', @handle, createErrorCallback(callback), DL::PtrData.new(data.object_id))
|
327
|
+
end
|
328
|
+
|
329
|
+
def getDeviceName
|
330
|
+
call_IPs(@@name, 'CPhidget_getDeviceName', @handle)
|
331
|
+
end
|
332
|
+
|
333
|
+
def getSerialNumber
|
334
|
+
call_IPi(@@serial, 'CPhidget_getSerialNumber', @handle)
|
335
|
+
end
|
336
|
+
|
337
|
+
def getDeviceVersion
|
338
|
+
call_IPi(@@version, 'CPhidget_getDeviceVersion', @handle)
|
339
|
+
end
|
340
|
+
|
341
|
+
def getDeviceStatus
|
342
|
+
call_IPi(@@status, 'CPhidget_getDeviceStatus', @handle)
|
343
|
+
end
|
344
|
+
|
345
|
+
def getLibraryVersion
|
346
|
+
@@lib_version = sym('CPhidget_getLibraryVersion', 'Ip') if @@lib_version == nil
|
347
|
+
lib_version_ptr = DL.malloc(DL.sizeof('P'))
|
348
|
+
r,rs = @@lib_version.call(lib_version_ptr.ref)
|
349
|
+
raise Phidgets::Exception.new(r) if r != 0
|
350
|
+
lib_version_ptr.free = nil
|
351
|
+
lib_version_ptr.to_s
|
352
|
+
end
|
353
|
+
|
354
|
+
def getDeviceType
|
355
|
+
call_IPs(@@type, 'CPhidget_getDeviceType', @handle)
|
356
|
+
end
|
357
|
+
|
358
|
+
def getDeviceLabel
|
359
|
+
call_IPs(@@get_label, 'CPhidget_getDeviceLabel', @handle)
|
360
|
+
end
|
361
|
+
|
362
|
+
def setDeviceLabel(label)
|
363
|
+
call_IXX(@@set_label, 'CPhidget_setDeviceLabel', 'IPS', @handle, label)
|
364
|
+
end
|
365
|
+
|
366
|
+
def getErrorDescription(error_code)
|
367
|
+
@@error_description = sym('CPhidget_getErrorDescription', 'IIp') if @@error_description == nil
|
368
|
+
error_description_ptr = DL.malloc(DL.sizeof('P'))
|
369
|
+
r,rs = @@error_description.call(error_code, error_description_ptr.ref)
|
370
|
+
raise Phidgets::Exception.new(r) if r != 0
|
371
|
+
error_description_ptr.free = nil
|
372
|
+
error_description_ptr.to_s
|
373
|
+
end
|
374
|
+
|
375
|
+
def waitForAttachment(timeout)
|
376
|
+
call_IXX(@@wait, 'CPhidget_waitForAttachment', 'IPI', @handle, timeout)
|
377
|
+
end
|
378
|
+
|
379
|
+
def getServerID
|
380
|
+
call_IPs(@@server_id, 'CPhidget_getServerID', @handle)
|
381
|
+
end
|
382
|
+
|
383
|
+
def getServerAddress
|
384
|
+
@@server_addr = sym('CPhidget_getServerAddress', 'IPpi') if @@server_addr == nil
|
385
|
+
server_addr_ptr = DL.malloc(DL.sizeof('P'))
|
386
|
+
server_port = 0
|
387
|
+
r,rs = @@server_addr.call(@handle, server_addr_ptr.ref, server_port)
|
388
|
+
raise Phidgets::Exception.new(r) if r != 0
|
389
|
+
server_addr_ptr.free = nil
|
390
|
+
a = [server_addr_ptr.to_s, rs[2]]
|
391
|
+
a
|
392
|
+
end
|
393
|
+
|
394
|
+
def getServerStatus
|
395
|
+
call_IPi(@@server_status, 'CPhidget_getServerStatus', @handle)
|
396
|
+
end
|
397
|
+
|
398
|
+
def getDeviceID
|
399
|
+
call_IPi(@@device_id, 'CPhidget_getDeviceID', @handle)
|
400
|
+
end
|
401
|
+
|
402
|
+
def getDeviceClass
|
403
|
+
call_IPi(@@device_class, 'CPhidget_getDeviceClass', @handle)
|
404
|
+
end
|
405
|
+
|
406
|
+
end
|
407
|
+
|
408
|
+
end
|
409
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
|
2
|
+
#require 'phidgets/common'
|
3
|
+
|
4
|
+
module Phidgets
|
5
|
+
|
6
|
+
class InterfaceKit < Common
|
7
|
+
@@create = nil
|
8
|
+
@@input_count = nil
|
9
|
+
@@input_state = nil
|
10
|
+
@@output_count = nil
|
11
|
+
@@get_output_state = nil
|
12
|
+
@@set_output_state = nil
|
13
|
+
@@sensor_count = nil
|
14
|
+
@@sensor_value = nil
|
15
|
+
@@sensor_raw_value = nil
|
16
|
+
@@get_ratiometric = nil
|
17
|
+
@@set_ratiometric = nil
|
18
|
+
|
19
|
+
def initialize(serial_number=-1, timeout=0)
|
20
|
+
super()
|
21
|
+
create
|
22
|
+
open(serial_number, timeout) if timeout > 0
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def create
|
28
|
+
@@create = sym('CPhidgetInterfaceKit_create', 'Ip') if @@create == nil
|
29
|
+
r,rs = @@create.call(@handle.ref)
|
30
|
+
raise Phidgets::Exception.new(r) if r != 0
|
31
|
+
end
|
32
|
+
|
33
|
+
public
|
34
|
+
|
35
|
+
def getInputCount
|
36
|
+
call_IPi(@@input_count, 'CPhidgetInterfaceKit_getInputCount', @handle)
|
37
|
+
end
|
38
|
+
|
39
|
+
def getInputState(index)
|
40
|
+
call_IPIi(@@input_state, 'CPhidgetInterfaceKit_getInputState', @handle, index)
|
41
|
+
end
|
42
|
+
|
43
|
+
def getOutputCount
|
44
|
+
call_IPi(@@output_count, 'CPhidgetInterfaceKit_getOutputCount', @handle)
|
45
|
+
end
|
46
|
+
|
47
|
+
def getOutputState(index)
|
48
|
+
call_IPIi(@@get_output_state, 'CPhidgetInterfaceKit_getOutputState', @handle, index)
|
49
|
+
end
|
50
|
+
|
51
|
+
def setOutputState(index, state)
|
52
|
+
call_IXXX(@@set_output_state, 'CPhidgetInterfaceKit_setOutputState', 'IPII', @handle, index, state)
|
53
|
+
end
|
54
|
+
|
55
|
+
def getSensorCount
|
56
|
+
call_IPi(@@sensor_count, 'CPhidgetInterfaceKit_getSensorCount', @handle)
|
57
|
+
end
|
58
|
+
|
59
|
+
def getSensorValue(index)
|
60
|
+
call_IPIi(@@sensor_value, 'CPhidgetInterfaceKit_getSensorValue', @handle, index)
|
61
|
+
end
|
62
|
+
|
63
|
+
def getSensorRawValue(index)
|
64
|
+
call_IPIi(@@sensor_raw_value, 'CPhidgetInterfaceKit_getSensorRawValue', @handle, index)
|
65
|
+
end
|
66
|
+
|
67
|
+
def getRatiometric
|
68
|
+
call_IPi(@@get_ratiometric, 'CPhidgetInterfaceKit_getRatiometric', @handle)
|
69
|
+
end
|
70
|
+
|
71
|
+
def setRatiometric(ratiometric)
|
72
|
+
call_IXX(@@set_ratiometric, 'CPhidgetInterfaceKit_setRatiometric', 'IPI', @handle, ratiometric)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
|
2
|
+
#require 'phidgets/common'
|
3
|
+
|
4
|
+
module Phidgets
|
5
|
+
|
6
|
+
class RFID < Common
|
7
|
+
@@create = nil
|
8
|
+
@@output_count = nil
|
9
|
+
@@get_output_state = nil
|
10
|
+
@@set_output_state = nil
|
11
|
+
@@get_antenna_on = nil
|
12
|
+
@@set_antenna_on = nil
|
13
|
+
@@get_led_on = nil
|
14
|
+
@@set_led_on = nil
|
15
|
+
@@get_last_tag = nil
|
16
|
+
@@get_tag_status = nil
|
17
|
+
@@on_tag_handler = nil
|
18
|
+
@@tag_lost_handler = nil
|
19
|
+
|
20
|
+
def initialize(serial_number=-1, timeout=0)
|
21
|
+
super()
|
22
|
+
create
|
23
|
+
open(serial_number, timeout) if timeout > 0
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def create
|
29
|
+
@@create = sym('CPhidgetRFID_create', 'Ip') if @@create == nil
|
30
|
+
r,rs = @@create.call(@handle.ref)
|
31
|
+
raise Phidgets::Exception.new(r) if r != 0
|
32
|
+
end
|
33
|
+
|
34
|
+
public
|
35
|
+
|
36
|
+
def getOutputCount
|
37
|
+
call_IPi(@@output_count, 'CPhidgetRFID_getOutputCount', @handle)
|
38
|
+
end
|
39
|
+
|
40
|
+
def getOutputState(index)
|
41
|
+
call_IPIi(@@get_output_state, 'CPhidgetRFID_getOutputState', @handle, index)
|
42
|
+
end
|
43
|
+
|
44
|
+
def setOutputState(index, state)
|
45
|
+
call_IXXX(@@set_output_state, 'CPhidgetRFID_setOutputState', 'IPII', @handle, index, state)
|
46
|
+
end
|
47
|
+
|
48
|
+
def getAntennaOn
|
49
|
+
call_IPi(@@get_antenna_on, 'CPhidgetRFID_getAntennaOn', @handle)
|
50
|
+
end
|
51
|
+
|
52
|
+
def setAntennaOn(state)
|
53
|
+
call_IPX(@@set_antenna_on, 'CPhidgetRFID_setAntennaOn', 'IPI', @handle, state)
|
54
|
+
end
|
55
|
+
|
56
|
+
def getLedOn
|
57
|
+
call_IPi(@@get_led_on, 'CPhidgetRFID_getLEDOn', @handle)
|
58
|
+
end
|
59
|
+
|
60
|
+
def setLedOn(state)
|
61
|
+
call_IPX(@@set_led_on, 'CPhidgetRFID_setLEDOn', 'IPI', @handle, state)
|
62
|
+
end
|
63
|
+
|
64
|
+
def getLastTag
|
65
|
+
call_IPs(@@get_last_tag, 'CPhidgetRFID_getLastTag', @handle)
|
66
|
+
end
|
67
|
+
|
68
|
+
def getTagStatus
|
69
|
+
call_IPi(@@get_tag_status, 'CPhidgetRFID_getTagStatus', @handle)
|
70
|
+
end
|
71
|
+
|
72
|
+
def setOnTagHandler(callback, data)
|
73
|
+
call_IXXX(@@on_tag_handler, 'CPhidgetRFID_set_OnTag_Handler', 'IPPP', @handle, createCallback(callback), DL::PtrData.new(data.object_id))
|
74
|
+
end
|
75
|
+
|
76
|
+
def setOnTagLostHandler(callback, data)
|
77
|
+
call_IXXX(@@tag_lost_handler, 'CPhidgetRFID_set_OnTagLost_Handler', 'IPPP', @handle, createCallback(callback), DL::PtrData.new(data.object_id))
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
#require 'phidgets/common'
|
3
|
+
|
4
|
+
module Phidgets
|
5
|
+
|
6
|
+
class Servo < Common
|
7
|
+
@@create = nil
|
8
|
+
@@get_motor_count = nil
|
9
|
+
@@get_position = nil
|
10
|
+
@@set_position = nil
|
11
|
+
@@get_position_max = nil
|
12
|
+
@@get_position_min = nil
|
13
|
+
@@get_servo_type = nil
|
14
|
+
@@set_servo_type = nil
|
15
|
+
@@get_engaged = nil
|
16
|
+
@@set_engaged = nil
|
17
|
+
def initialize(serial_number=-1, timeout=0)
|
18
|
+
super()
|
19
|
+
create
|
20
|
+
open(serial_number, timeout) if timeout > 0
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def create
|
26
|
+
@@create = sym('CPhidgetServo_create', 'Ip') if @@create == nil
|
27
|
+
r,rs = @@create.call(@handle.ref)
|
28
|
+
raise Phidgets::Exception.new(r) if r != 0
|
29
|
+
end
|
30
|
+
|
31
|
+
public
|
32
|
+
|
33
|
+
def getMotorCount
|
34
|
+
call_IPi(@@get_motor_count, 'CPhidgetServo_getMotorCount', @handle)
|
35
|
+
end
|
36
|
+
|
37
|
+
def getPosition(index)
|
38
|
+
call_IPId(@@get_position, 'CPhidgetServo_getPosition', @handle, index)
|
39
|
+
end
|
40
|
+
|
41
|
+
def setPosition(index, position)
|
42
|
+
puts "calling call_IXXX"
|
43
|
+
call_IXXX(@@set_position, 'CPhidgetServo_setPosition', 'IPII', @handle, index, position)
|
44
|
+
end
|
45
|
+
|
46
|
+
def getPositionMax(index)
|
47
|
+
call_IPId(@@get_position_max, 'CPhidgetServo_getPositionMax', @handle, index)
|
48
|
+
end
|
49
|
+
|
50
|
+
def getPositionMin(index)
|
51
|
+
call_IPId(@@get_position_min, 'CPhidgetServo_getPositionMin', @handle, index)
|
52
|
+
end
|
53
|
+
|
54
|
+
def getEngaged(index)
|
55
|
+
call_IPIi(@@get_engaged, 'CPhidgetServo_getEngaged', @handle, index)
|
56
|
+
end
|
57
|
+
|
58
|
+
def setEngaged(index, state)
|
59
|
+
call_IXXX(@@set_engaged, 'CPhidgetServo_setEngaged', 'IPII', @handle, index, state)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/lib/phidgets.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/phidgets/common.rb'
|
5
|
+
require File.dirname(__FILE__) + '/phidgets/interfacekit.rb'
|
6
|
+
require File.dirname(__FILE__) + '/phidgets/rfid.rb'
|
7
|
+
require File.dirname(__FILE__) + '/phidgets/servo.rb'
|
8
|
+
|
9
|
+
module Phidgets
|
10
|
+
VERSION = '0.0.2'
|
11
|
+
end
|
data/test/test_helper.rb
ADDED