The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Uisng multiple phidget interfacekit in single python program
Discuss Uisng multiple phidget interfacekit in single python program in the Python Programming forum on Dev Shed. Uisng multiple phidget interfacekit in single python program Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 18th, 2012, 01:46 AM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 1
Time spent in forums: 4 m 24 sec
Reputation Power: 0
|
|
|
Uisng multiple phidget interfacekit in single python program
im trying to use multiple interfacekit pidget in a single python program here my coding but der the single phidget oly getting attache. and working.
#Basic imports
from ctypes import *
import sys
import random
#Phidget specific imports
from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException
from Phidgets.Events.Events import AttachEventArgs, DetachEventArgs, ErrorEventArgs, InputChangeEventArgs, OutputChangeEventArgs, SensorChangeEventArgs
from Phidgets.Devices.InterfaceKit import InterfaceKit
from time import sleep
#Create an interfacekit object
try:
interfaceKit = InterfaceKit()
except RuntimeError as e:
print("Runtime Exception: %s" % e.details)
print("Exiting....")
exit(1)
def inferfaceKitAttached(e):
attached = e.device
print("InterfaceKit %i Attached!" % (attached.getSerialNum()))
def interfaceKitDetached(e):
detached = e.device
print("InterfaceKit %i Detached!" % (detached.getSerialNum()))
def interfaceKitError(e):
try:
source = e.device
print("InterfaceKit %i: Phidget Error %i: %s" % (source.getSerialNum(), e.eCode, e.description))
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
#def interfaceKitInputChanged(e):
# source = e.device
# print("InterfaceKit %i: Input %i: %s" % (source.getSerialNum(), e.index, e.state))
#def interfaceKitOutputChanged(e):
# source = e.device
# print("InterfaceKit %i: Output %i: %s" % (source.getSerialNum(), e.index, e.state))
#Main Program Code
try:
interfaceKit.setOnAttachHandler(inferfaceKitAttached)
interfaceKit.setOnDetachHandler(interfaceKitDetached)
interfaceKit.setOnErrorhandler(interfaceKitError)
# interfaceKit.setOnInputChangeHandler(interfaceKitInputChanged)
#interfaceKit.setOnOutputChangeHandler(interfaceKitOutputChanged)
# interfaceKit.setOnSensorChangeHandler(interfaceKitSensorChanged)
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Exiting....")
exit(1)
print("Opening phidget object....")
try:
#interfaceKit.openPhidget(277983)
interfaceKit.openPhidget()
#interfaceKit.openPhidget(273506)
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Exiting....")
exit(1)
print("Waiting for attach....")
try:
interfaceKit.waitForAttach(10000)
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
try:
interfaceKit.closePhidget()
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Exiting....")
exit(1)
print("Exiting....")
exit(1)
else:
interfaceKit.setOutputState(0,1);
interfaceKit.setOutputState(1,1);
interfaceKit.closePhidget()
|

October 18th, 2012, 08:49 AM
|
 |
Contributing User
|
|
|
|
|
Lesson learned!
phidgets are some sort of usb hardware.
You're more likely to get a reasonable answer if you ask your question at the phidgets web site, if they support customers.
Also, You've made me realize a new great reason to avoid
from module import *
It's about impossible to read your program because I need to know the entire name spaces of these modules. I certainly hope to remember this lesson and never ever again even consider import * .
You might have intended this python program?
Code:
#http://www.phidgets.com/
#Basic imports
from ctypes import *
import sys
import random
#Phidget specific imports
from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException
from Phidgets.Events.Events import AttachEventArgs, DetachEventArgs, ErrorEventArgs, InputChangeEventArgs, OutputChangeEventArgs, SensorChangeEventArgs
from Phidgets.Devices.InterfaceKit import InterfaceKit
from time import sleep
#Create an interfacekit object
try:
interfaceKit = InterfaceKit()
except RuntimeError as e:
print("Runtime Exception: %s" % e.details)
print("Exiting....")
exit(1)
def inferfaceKitAttached(e):
attached = e.device
print("InterfaceKit %i Attached!" % (attached.getSerialNum()))
def interfaceKitDetached(e):
detached = e.device
print("InterfaceKit %i Detached!" % (detached.getSerialNum()))
def interfaceKitError(e):
try:
source = e.device
print("InterfaceKit %i: Phidget Error %i: %s" % (source.getSerialNum(), e.eCode, e.description))
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
#def interfaceKitInputChanged(e):
# source = e.device
# print("InterfaceKit %i: Input %i: %s" % (source.getSerialNum(), e.index, e.state))
#def interfaceKitOutputChanged(e):
# source = e.device
# print("InterfaceKit %i: Output %i: %s" % (source.getSerialNum(), e.index, e.state))
#Main Program Code
try:
interfaceKit.setOnAttachHandler(inferfaceKitAttached)
interfaceKit.setOnDetachHandler(interfaceKitDetached)
interfaceKit.setOnErrorhandler(interfaceKitError)
# interfaceKit.setOnInputChangeHandler(interfaceKitInputChanged)
#interfaceKit.setOnOutputChangeHandler(interfaceKitOutputChanged)
# interfaceKit.setOnSensorChangeHandler(interfaceKitSensorChanged)
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Exiting....")
exit(1)
print("Opening phidget object....")
try:
#interfaceKit.openPhidget(277983)
interfaceKit.openPhidget()
#interfaceKit.openPhidget(273506)
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Exiting....")
exit(1)
print("Waiting for attach....")
try:
interfaceKit.waitForAttach(10000)
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
try:
interfaceKit.closePhidget()
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Exiting....")
exit(1)
print("Exiting....")
exit(1)
else:
interfaceKit.setOutputState(0,1);
interfaceKit.setOutputState(1,1);
interfaceKit.closePhidget()
__________________
[code] Code tags[/code] are essential for python code!
Last edited by b49P23TIvg : October 18th, 2012 at 08:56 AM.
Reason: reorganized for clarity
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|