Class: Phidgets::Common
- Inherits:
-
Object
show all
- Defined in:
- lib/phidgets/common.rb
Constant Summary
collapse
- @@libname =
nil
- @@lib =
nil
- @@open_remote =
nil
- @@open_remote_ip =
nil
- @@open =
nil
- @@close =
nil
- @@delete =
nil
- @@detach_handler =
nil
- @@attach_handler =
nil
- @@connect_handler =
nil
- @@disconnect_handler =
nil
- @@error_handler =
nil
- @@name =
nil
- @@serial =
nil
- @@version =
nil
- @@status =
nil
- @@lib_version =
nil
- @@type =
nil
- @@get_label =
nil
- @@set_label =
nil
- @@error_description =
nil
- @@wait =
nil
- @@server_id =
nil
- @@server_addr =
nil
- @@server_status =
nil
- @@device_id =
nil
- @@device_class =
nil
Class Method Summary
collapse
Instance Method Summary
collapse
-
#close ⇒ Object
-
#delete ⇒ Object
-
#getDeviceClass ⇒ Object
-
#getDeviceID ⇒ Object
-
#getDeviceLabel ⇒ Object
-
#getDeviceName ⇒ Object
-
#getDeviceStatus ⇒ Object
-
#getDeviceType ⇒ Object
-
#getDeviceVersion ⇒ Object
-
#getErrorDescription(error_code) ⇒ Object
-
#getLibraryVersion ⇒ Object
-
#getSerialNumber ⇒ Object
-
#getServerAddress ⇒ Object
-
#getServerID ⇒ Object
-
#getServerStatus ⇒ Object
-
#initialize ⇒ Common
constructor
A new instance of Common.
-
#open(serial_number = -1,, timeout = 0) ⇒ Object
-
#openRemote(serial_number = -1,, server = nil, password = nil, timeout = 0) ⇒ Object
-
#openRemoteIP(serial_number, address, port = 5001, password = nil, timeout = 0) ⇒ Object
-
#setDeviceLabel(label) ⇒ Object
-
#setOnAttachHandler(callback, data) ⇒ Object
-
#setOnConnectHandler(callback, data) ⇒ Object
-
#setOnDetachHandler(callback, data) ⇒ Object
-
#setOnDisconnectHandler(callback, data) ⇒ Object
-
#setOnErrorHandler(callback, data) ⇒ Object
-
#waitForAttachment(timeout) ⇒ Object
Constructor Details
#initialize ⇒ Common
Returns a new instance of Common.
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/phidgets/common.rb', line 167
def initialize
if @@libname == nil
case Config::CONFIG['target_os']
when 'linux'
@@libname = 'libphidget21.so'
when 'linux-eabi'
@@libname = 'libphidget21.so'
when 'mswin32'
@@libname = 'phidget21.dll'
when 'darwin10.2.0'
@@libname = '/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21'
when 'darwin10.3.0'
@@libname = '/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21'
else
raise Phidgets::Exception.new(-1)
end
end
begin
@@lib = DL.dlopen(@@libname)
rescue
raise Phidgets::Exception.new(-2)
end
@handle = DL.malloc(DL.sizeof('P'))
end
|
Class Method Details
.setLibName(name) ⇒ Object
288
289
290
|
# File 'lib/phidgets/common.rb', line 288
def Common.setLibName(name)
@@libname = name
end
|
Instance Method Details
#close ⇒ Object
307
308
309
|
# File 'lib/phidgets/common.rb', line 307
def close
call_IX(@@close, 'CPhidget_close', 'IP', @handle)
end
|
#delete ⇒ Object
311
312
313
314
|
# File 'lib/phidgets/common.rb', line 311
def delete
@handle.free = nil
call_IX(@@delete, 'CPhidget_delete', 'IP', @handle)
end
|
#getDeviceClass ⇒ Object
409
410
411
|
# File 'lib/phidgets/common.rb', line 409
def getDeviceClass
call_IPi(@@device_class, 'CPhidget_getDeviceClass', @handle)
end
|
#getDeviceID ⇒ Object
405
406
407
|
# File 'lib/phidgets/common.rb', line 405
def getDeviceID
call_IPi(@@device_id, 'CPhidget_getDeviceID', @handle)
end
|
#getDeviceLabel ⇒ Object
365
366
367
|
# File 'lib/phidgets/common.rb', line 365
def getDeviceLabel
call_IPs(@@get_label, 'CPhidget_getDeviceLabel', @handle)
end
|
#getDeviceName ⇒ Object
336
337
338
|
# File 'lib/phidgets/common.rb', line 336
def getDeviceName
call_IPs(@@name, 'CPhidget_getDeviceName', @handle)
end
|
#getDeviceStatus ⇒ Object
348
349
350
|
# File 'lib/phidgets/common.rb', line 348
def getDeviceStatus
call_IPi(@@status, 'CPhidget_getDeviceStatus', @handle)
end
|
#getDeviceType ⇒ Object
361
362
363
|
# File 'lib/phidgets/common.rb', line 361
def getDeviceType
call_IPs(@@type, 'CPhidget_getDeviceType', @handle)
end
|
#getDeviceVersion ⇒ Object
344
345
346
|
# File 'lib/phidgets/common.rb', line 344
def getDeviceVersion
call_IPi(@@version, 'CPhidget_getDeviceVersion', @handle)
end
|
#getErrorDescription(error_code) ⇒ Object
373
374
375
376
377
378
379
380
|
# File 'lib/phidgets/common.rb', line 373
def getErrorDescription(error_code)
@@error_description = sym('CPhidget_getErrorDescription', 'IIp') if @@error_description == nil
error_description_ptr = DL.malloc(DL.sizeof('P'))
r,rs = @@error_description.call(error_code, error_description_ptr.ref)
raise Phidgets::Exception.new(r) if r != 0
error_description_ptr.free = nil
error_description_ptr.to_s
end
|
#getLibraryVersion ⇒ Object
352
353
354
355
356
357
358
359
|
# File 'lib/phidgets/common.rb', line 352
def getLibraryVersion
@@lib_version = sym('CPhidget_getLibraryVersion', 'Ip') if @@lib_version == nil
lib_version_ptr = DL.malloc(DL.sizeof('P'))
r,rs = @@lib_version.call(lib_version_ptr.ref)
raise Phidgets::Exception.new(r) if r != 0
lib_version_ptr.free = nil
lib_version_ptr.to_s
end
|
#getSerialNumber ⇒ Object
340
341
342
|
# File 'lib/phidgets/common.rb', line 340
def getSerialNumber
call_IPi(@@serial, 'CPhidget_getSerialNumber', @handle)
end
|
#getServerAddress ⇒ Object
390
391
392
393
394
395
396
397
398
399
|
# File 'lib/phidgets/common.rb', line 390
def getServerAddress
@@server_addr = sym('CPhidget_getServerAddress', 'IPpi') if @@server_addr == nil
server_addr_ptr = DL.malloc(DL.sizeof('P'))
server_port = 0
r,rs = @@server_addr.call(@handle, server_addr_ptr.ref, server_port)
raise Phidgets::Exception.new(r) if r != 0
server_addr_ptr.free = nil
a = [server_addr_ptr.to_s, rs[2]]
a
end
|
#getServerID ⇒ Object
386
387
388
|
# File 'lib/phidgets/common.rb', line 386
def getServerID
call_IPs(@@server_id, 'CPhidget_getServerID', @handle)
end
|
#getServerStatus ⇒ Object
401
402
403
|
# File 'lib/phidgets/common.rb', line 401
def getServerStatus
call_IPi(@@server_status, 'CPhidget_getServerStatus', @handle)
end
|
#open(serial_number = -1,, timeout = 0) ⇒ Object
302
303
304
305
|
# File 'lib/phidgets/common.rb', line 302
def open(serial_number=-1, timeout=0)
call_IXX(@@open, 'CPhidget_open', 'IPI', @handle, serial_number)
waitForAttachment(timeout) if timeout > 0
end
|
#openRemote(serial_number = -1,, server = nil, password = nil, timeout = 0) ⇒ Object
292
293
294
295
|
# File 'lib/phidgets/common.rb', line 292
def openRemote(serial_number=-1, server=nil, password=nil, timeout=0)
call_IXXXX(@@open_remote, 'CPhidget_openRemote', 'IPISS', @handle, serial_number, server, password)
waitForAttachment(timeout) if timeout > 0
end
|
#openRemoteIP(serial_number, address, port = 5001, password = nil, timeout = 0) ⇒ Object
297
298
299
300
|
# File 'lib/phidgets/common.rb', line 297
def openRemoteIP(serial_number, address, port=5001, password=nil, timeout=0)
call_IXXXXX(@@open_remote_ip, 'CPhidget_openRemoteIP', 'IPISIS', @handle, serial_number, address, port, password)
waitForAttachment(timeout) if timeout > 0
end
|
#setDeviceLabel(label) ⇒ Object
369
370
371
|
# File 'lib/phidgets/common.rb', line 369
def setDeviceLabel(label)
call_IXX(@@set_label, 'CPhidget_setDeviceLabel', 'IPS', @handle, label)
end
|
#setOnAttachHandler(callback, data) ⇒ Object
320
321
322
|
# File 'lib/phidgets/common.rb', line 320
def setOnAttachHandler(callback, data)
call_IXXX(@@attach_handler, 'CPhidget_set_OnAttach_Handler', 'IPPP', @handle, createCallback(callback), DL::PtrData.new(data.object_id))
end
|
#setOnConnectHandler(callback, data) ⇒ Object
324
325
326
|
# File 'lib/phidgets/common.rb', line 324
def setOnConnectHandler(callback, data)
call_IXXX(@@connect_handler, 'CPhidget_set_OnServerConnect_Handler', 'IPPP', @handle, createCallback(callback), DL::PtrData.new(data.object_id))
end
|
#setOnDetachHandler(callback, data) ⇒ Object
316
317
318
|
# File 'lib/phidgets/common.rb', line 316
def setOnDetachHandler(callback, data)
call_IXXX(@@detach_handler, 'CPhidget_set_OnDetach_Handler', 'IPPP', @handle, createCallback(callback), DL::PtrData.new(data.object_id))
end
|
#setOnDisconnectHandler(callback, data) ⇒ Object
328
329
330
|
# File 'lib/phidgets/common.rb', line 328
def setOnDisconnectHandler(callback, data)
call_IXXX(@@disconnect_handler, 'CPhidget_set_OnServerDisconnect_Handler', 'IPPP', @handle, createCallback(callback), DL::PtrData.new(data.object_id))
end
|
#setOnErrorHandler(callback, data) ⇒ Object
332
333
334
|
# File 'lib/phidgets/common.rb', line 332
def setOnErrorHandler(callback, data)
call_IXXX(@@error_handler, 'CPhidget_set_OnError_Handler', 'IPPP', @handle, createErrorCallback(callback), DL::PtrData.new(data.object_id))
end
|
#waitForAttachment(timeout) ⇒ Object
382
383
384
|
# File 'lib/phidgets/common.rb', line 382
def waitForAttachment(timeout)
call_IXX(@@wait, 'CPhidget_waitForAttachment', 'IPI', @handle, timeout)
end
|