Esempio n. 1
0
    def __init__(self, id, port):
        self.id = id
        self.port = port
        self.serial_numbers = (
            262305,  # 4-port, shelf 6
            262295,  # 4-port, shelf 6
            318471,  # 8-port, shelf 2
            312226,  # 8-port, shelf 4
            259764,  # 4-port, shelf 8
            319749,  # 8-port, shelf 10
            259763,  # 4-port, shelf 6
        )
        self.serial_num = self.serial_numbers[id]
        self.lockfile = "/var/run/lock/phidget-%s.lock" % self.id
        self.lock_fp = open(self.lockfile, "w")
        self.lock_fd = self.lock_fp.fileno()
        fcntl.lockf(self.lock_fd, fcntl.LOCK_EX)
        if debug:
            print "[%.2f] Aquired lock for Phidget %s" % (time.time(), self.id)

        try:
            self.device = InterfaceKit()
        except RuntimeError as e:
            print("Runtime Error: %s" % e.message)

        try:
            self.device.openPhidget(serial=self.serial_num)
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.detail))
            fcntl.lockf(self.lock_fd, fcntl.LOCK_UN)
            exit(1)

        self.device.waitForAttach(10000)
Esempio n. 2
0
 def __init__(self):
     rospy.init_node('interface_kit', anonymous=True)
     self.name = rospy.get_param('~name', '')
     self.serial = rospy.get_param('~serial_number', -1)
     
     if self.serial == -1:
         rospy.logwarn('No serial number specified. This node will connect to the first interface kit attached.')
     self.interface_kit = InterfaceKit()
Esempio n. 3
0
    def __init__(self):
        """
        Instantiate the InterfaceKit object and open it.
        """
        self.logger = tosLogger

        self.ifkit = InterfaceKit()

        # open ifkit
        try:
            self.ifkit.openPhidget()
        except PhidgetException, e:
            self.logger.log(self, 3,
                            "Phidget Exception %i: %s" % (e.code, e.message))
            exit(1)
Esempio n. 4
0
def connect_phidget():
    try:
        log_info('creating the interface kit')
        device = InterfaceKit()
    except RuntimeError as e:
        log_error("Error when trying to create the device: %s" % e.message)

    #This connects to the device.
    try:
        #print 'connecting to the device!'
        device.openPhidget()
    except PhidgetException as e:
        log_warning("Exception when trying to connect %i: %s" %
                    (e.code, e.detail))
        exit(1)

    return device
Esempio n. 5
0
def start_sensors_for_changes():
    #Create and connect to the device using the InterfaceKit() method.
    #This method depends on the device that we are using. For us, it
    #happens to be the interfacekit.
    try:
        print 'creating the interface kit'
        device = InterfaceKit()
    except RuntimeError as e:
        print("Error when trying to create the device: %s" % e.message)

    #This connects to the device.
    try:
        print 'connecting to the device!'
        device.openPhidget()
    except PhidgetException as e:
        print("Exception when trying to connect %i: %s" % (e.code, e.detail))
        exit(1)

    device.setOnSensorChangeHandler(sensorChanged)
Esempio n. 6
0
from ctypes import *
import sys
import random
from dbconnect import dbconnect
#Phidget specific imports
from Phidgets.PhidgetException import *
from Phidgets.Events.Events import *
from Phidgets.Devices.InterfaceKit import *

connect = dbconnect()
controllerID = 902
connect.disconnected(controllerID)

#Create an interfacekit object
try:
    interfaceKit = InterfaceKit()
except RuntimeError as e:
    print("Runtime Exception: %s" % e.details)
    print("Exiting....")
    exit(1)


#Event Handler Callback Functions
def inferfaceKitAttached(e):
    connect.connected(controllerID)
    attached = e.device
    print("InterfaceKit %i Attached!" % (attached.getSerialNum()))


def interfaceKitDetached(e):
    connect.disconnected(controllerID)
Esempio n. 7
0
    return 0
 
def LocalErrorCatcher(event):
    print("Phidget Exception: " + str(e.code) + " - " + str(e.details) + ", Exiting...")
    exit(1)


if __name__ == '__main__':

#    f = open('sonar.txt','a')
#    f.write('********************************\n')
#    f.close()

    # Create
    try:
        device = InterfaceKit()	
    except RuntimeError as e:
        print("Runtime Error: %s" % e.message)
        
    try:
        device.setOnAttachHandler(AttachHandler)
        device.setOnDetachHandler(DetachHandler)
        device.openPhidget()
        device.setOnSensorChangeHandler(sensorChanged)
    except PhidgetException as e: 
        LocalErrorCatcher(e)

    try:
        pub = rospy.Publisher('sonar', Float32)
        rospy.init_node('sonar')
    except rospy.ROSInterruptException:
Esempio n. 8
0
import cgitb
 
cgitb.enable()
errors = ""
 
# Print the HTML header
print("Content-type: text/html\n\n")
print("<html><title>FULL INTERFACE KIT</title><body>\n")
print('<center><b><font size="16" color="#0000ff">FULL INTERFACEKIT</font></b></center><br>')
print('<font size="4">THIS PROJECT WILL DEVELOP IN A FULL FUNCTIONAL WEB APPLICATION TO CONTROL THE PHIDGETS SBC</font>')
print('<br>&#169 J J Slabbert') 
print('<br><a href="mailto:[email protected]">[email protected]</a><br><br>')

# Create, Open, and Attach the Interface Kit
try:
    ifk = InterfaceKit()
except RuntimeError as e:
    errors = errors + "<h5>Runtime Exception on object creation: " + e.details + "</h5>\n"
try:
    ifk.openRemoteIP('192.168.10.106',5001)
except PhidgetException as e:
    errors = errors + "<h5>Phidget Exception on Open: " + e.details + "</h5>\n"
try:
    ifk.waitForAttach(10000)
except PhidgetException as e:
    errors = errors + "<h5>Phidget Exception on Attach: " + e.details + "</h5>\n"
    errors = errors + "<h5>If Phidget is 'Not Physically Attached' it may be in use</h5>\n"

print('<table><tr><td>')