当前位置: 首页>>代码示例>>Python>>正文


Python ip_connection.IPConnection类代码示例

本文整理汇总了Python中tinkerforge.ip_connection.IPConnection的典型用法代码示例。如果您正苦于以下问题:Python IPConnection类的具体用法?Python IPConnection怎么用?Python IPConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IPConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Window

class Window(QtGui.QWidget):
    qtcb_temperature = QtCore.pyqtSignal(int)

    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.button = QtGui.QPushButton('Refresh', self)
        self.button.clicked.connect(self.handle_button)
        self.label = QtGui.QLabel('TBD')
        layout = QtGui.QVBoxLayout(self)
        layout.addWidget(self.button)
        layout.addWidget(self.label)

        self.ipcon = IPConnection()
        self.temperature = Temperature(UID_TEMPERATURE, self.ipcon)
        self.ipcon.connect(HOST, PORT)

        # We send the callback through the Qt signal/slot
        # system to make sure that we can change the label
        self.qtcb_temperature.connect(self.cb_temperature)
        self.temperature.register_callback(Temperature.CALLBACK_TEMPERATURE, self.qtcb_temperature.emit)

        # Refresh every second
        self.temperature.set_temperature_callback_period(1000)
        
        # Refresh once on startup
        self.handle_button()

    # Refresh by hand
    def handle_button(self):
        self.cb_temperature(self.temperature.get_temperature())

    def cb_temperature(self, temperature):
        # Show temperature
        self.label.setText(u"Temperature: {0} °C".format(temperature/100.0))
开发者ID:Tinkerforge,项目名称:doc,代码行数:34,代码来源:example_gui_red.py

示例2: collect_data

def collect_data(suffix):
    global SAMPLE_RATE
    global w1
    global row
    print "Now recording " + suffix

    ipcon = IPConnection() # Create IP connection
    imu = IMU(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Set period for quaternion callback to 1s
    imu.set_all_data_period(SAMPLE_RATE)
    imu.set_orientation_period(SAMPLE_RATE)
    imu.set_quaternion_period(SAMPLE_RATE)    
   
    f1 = open('data/letters/all_data_'+suffix+'.csv', 'wb')
    w1 = csv.writer(f1)
    row = []
    # Register quaternion callback
    imu.register_callback(imu.CALLBACK_ALL_DATA, cb_all_data)
    imu.register_callback(imu.CALLBACK_ORIENTATION, cb_orientation_data)
    imu.register_callback(imu.CALLBACK_QUATERNION, cb_quaternion_data)   
  
    
    raw_input('Press key to quit recording ' + suffix + ' \n') # Use input() in Python 3
    ipcon.disconnect()
开发者ID:jbleich89,项目名称:the_pen,代码行数:28,代码来源:recordstuff.py

示例3: temperature

def temperature(connection, table):
    ipcon = IPConnection()
    t = Temperature(TEMPERATURE_UID, ipcon)
    ipcon.connect(HOST, PORT)
    value = t.get_temperature() / 100.0
    insert(connection, table, time.time(), value)
    ipcon.disconnect()
开发者ID:locked-fg,项目名称:Weatherstation-Python,代码行数:7,代码来源:sqlitesaver.py

示例4: humidity

def humidity(connection, table):
    ipcon = IPConnection()
    h = Humidity(HUMIDITY_UID, ipcon)
    ipcon.connect(HOST, PORT)
    value = h.get_humidity() / 10.0
    insert(connection, table, time.time(), value)
    ipcon.disconnect()
开发者ID:locked-fg,项目名称:Weatherstation-Python,代码行数:7,代码来源:sqlitesaver.py

示例5: barometer

def barometer(connection, table):
    ipcon = IPConnection()
    b = Barometer(BAROMETER_UID, ipcon)
    ipcon.connect(HOST, PORT)
    value = b.get_air_pressure() / 1000.0  # Get current air pressure (unit is mbar/1000)
    insert(connection, table, time.time(), value)
    ipcon.disconnect()
开发者ID:locked-fg,项目名称:Weatherstation-Python,代码行数:7,代码来源:sqlitesaver.py

示例6: ambient

def ambient(connection, table):
    ipcon = IPConnection()
    al = AmbientLight(AMBIENT_UID, ipcon)
    ipcon.connect(HOST, PORT)
    value = al.get_illuminance() / 10.0  # Get current illuminance (unit is Lux/10)
    insert(connection, table, time.time(), value)
    ipcon.disconnect()
开发者ID:locked-fg,项目名称:Weatherstation-Python,代码行数:7,代码来源:sqlitesaver.py

示例7: sound_activated

class sound_activated(modes.standard.abstractMode):
    _ipcon = None
    _si = None

    def __init__(self):
        '''
        Constructor
        '''
        modes.standard.abstractMode.__init__(self)
        config = ConfigParser.ConfigParser()
        config.read("config.ini")

        if config.has_section("Tinkerforge") and config.has_option('Tinkerforge', 'HOST') and config.has_option('Tinkerforge', 'PORT') and config.has_option('Tinkerforge', 'UID'):
            HOST = config.get('Tinkerforge', 'HOST')
            PORT = config.getint('Tinkerforge', 'PORT')
            UID = config.get('Tinkerforge', 'UID')
        else:
            print "Can't load Tinkerforge Settings from config.ini"

        self._ipcon = IPConnection()  # Create IP connection
        self._si = SoundIntensity(UID, self._ipcon)  # Create device object

        self._ipcon.connect(HOST, PORT)  # Connect to brickd

    def __del__(self):
        self._ipcon.disconnect()

    def myround(self, x, base=5):
        return int(base * round(float(x) / base))

    def start(self):
        high = 0.0
        count = 0
        while True:
            intensity = self._si.get_intensity()
            # reset high_level after a Song
            if count > 100:
                high = intensity
                count = 0
            if intensity > high:
                high = intensity
            else:
                count += 1
            if high > 0:
                level = self.myround((100 / float(high)) * float(intensity))
            else:
                level = 0

            RED = BLUE = GREEN = 0
            if level <= 33:
                BLUE = 100
            elif level <= 66:
                GREEN = 100
            else:
                RED = 100
            self.setRGB([RED, GREEN, BLUE])
            time.sleep(self._DELAY)

    def getName(self):
        return "Sound Activated"
开发者ID:BennySamir,项目名称:Pi-LEDController,代码行数:60,代码来源:tinkerforgebricks.py

示例8: connect

        class RedBrickResource:
            def connect(self, uid, host, port):
                self.ipcon = IPConnection()
                self.ipcon.connect(host, port)
                self.rb = BrickRED(uid, self.ipcon)

            def disconnect(self):
                self.ipcon.disconnect()
开发者ID:Loremipsum1988,项目名称:tinkervision,代码行数:8,代码来源:rb_setup.py

示例9: connect

def connect():
    ipcon = IPConnection() # Create IP connection
    gps = GPS(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    print('GPS Bricklet connected...')
    return gps, ipcon
开发者ID:balzer82,项目名称:TinkerGPS2Basemaps,代码行数:9,代码来源:tinkerGPS2Basemaps.py

示例10: Sensors

class Sensors(object):

    def __init__(self):
     self.__ipcon = IPConnection('localhost', 4223)
     
    def __del__(self):
        self.__ipcon.destroy()
        
    def add(self, pSensor):
        self.__ipcon.add_device(pSensor)
        
开发者ID:proditor,项目名称:RaspPi-Bot,代码行数:10,代码来源:Sensors.py

示例11: __init__

class Q:
    HOST = "localhost"
    PORT = 4223
    UID = "aeoUQwwyAvY" # Change to your UID

    def __init__(self):
        self.base_x = 0.0
        self.base_y = 0.0
        self.base_z = 0.0
        self.base_w = 0.0

        self.imu = IMU(self.UID) # Create device object
        self.ipcon = IPConnection(self.HOST, self.PORT) # Create IPconnection to brickd
        self.ipcon.add_device(self.imu) # Add device to IP connection
        # Don't use device before it is added to a connection

        # Wait for IMU to settle
        print 'Set IMU to base position and wait for 10 seconds'
        print 'Base position will be 0 for all angles'
        time.sleep(10)
        q = self.imu.get_quaternion()
        self.set_base_coordinates(q.x, q.y, q.z, q.w)

        # Set period for quaternion callback to 10ms
        self.imu.set_quaternion_period(10)

        # Register quaternion callback
        self.imu.register_callback(self.imu.CALLBACK_QUATERNION, self.quaternion_cb)

    def quaternion_cb(self, x, y, z, w):
        # Use conjugate of quaternion to rotate coordinates according to base system
        x, y, z, w = self.make_relative_coordinates(-x, -y, -z, w)

        x_angle = int(math.atan2(2.0*(y*z - w*x), 1.0 - 2.0*(x*x + y*y))*180/math.pi)
        y_angle = int(math.atan2(2.0*(x*z + w*y), 1.0 - 2.0*(x*x + y*y))*180/math.pi)
        z_angle = int(math.atan2(2.0*(x*y + w*z), 1.0 - 2.0*(x*x + z*z))*180/math.pi)

        print 'x: {0}, y: {1}, z: {2}'.format(x_angle, y_angle, z_angle)

    def set_base_coordinates(self, x, y, z, w):
        self.base_x = x
        self.base_y = y
        self.base_z = z
        self.base_w = w

    def make_relative_coordinates(self, x, y, z, w):
        # Multiply base quaternion with current quaternion
        return (
            w * self.base_x + x * self.base_w + y * self.base_z - z * self.base_y,
            w * self.base_y - x * self.base_z + y * self.base_w + z * self.base_x,
            w * self.base_z + x * self.base_y - y * self.base_x + z * self.base_w,
            w * self.base_w - x * self.base_x - y * self.base_y - z * self.base_z
        )
开发者ID:bschauerte,项目名称:imulogger,代码行数:53,代码来源:basic.py

示例12: index

def index():
    ipcon = IPConnection() # Create IP connection
    t = Temperature(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Get current temperature (unit is °C/100)
    temperature = t.get_temperature()/100.0

    ipcon.disconnect()
    return PAGE.format(temperature)
开发者ID:Tinkerforge,项目名称:doc,代码行数:12,代码来源:index.py

示例13: lies_temp

def lies_temp(host, port, uid):
	temp = None
	
	try:
		ipcon = IPConnection()
		b = BrickletTemperature(uid, ipcon)
		ipcon.connect(host, port)
	
		temp = b.get_temperature() / 100.0
		
		ipcon.disconnect()
	except:
		print("Temperaturabfrage fehlgeschlagen")
		
	return temp
开发者ID:GolemMediaGmbH,项目名称:OfficeTemperature,代码行数:15,代码来源:tf_temperature.py

示例14: __init__

    def __init__(self):
        #super(master, self).__init__()
        print 'init...'
        self.PORT   = 4223
        self.MENU_running = False
        self.BOARD_running = False

        ### Connection for Menu
        self.MENU_HOST   = "192.168.0.150" # Manually Set IP of Controller Board   "127.0.0.1"#
        self.MENU_lcdUID = "gFt" # LCD Screen
        self.MENU_jskUID = "hAP" # Joystick
        ### END MENU CONNECTION

        ### Connection for Board
        self.BOARD_HOST   = "192.168.0.111"
        self.BOARD_mstUID = "62eUEf" # master brick
        self.BOARD_io1UID = "ghh"    # io16
        self.BOARD_lcdUID = "9ew"    # lcd screen 20x4
        self.BOARD_iqrUID = "eRN"    # industrial quad relay
        self.BOARD_iluUID = "i8U"    # Ambient Light
        #### END BOARD CONNECTION

        self.ipcon = IPConnection() # Create IP connection
        self.ipcon.connect('127.0.0.1', self.PORT)
        # Register Enumerate Callback
        self.ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, self.cb_enumerate)

        # Trigger Enumerate
        self.ipcon.enumerate()        

        print 'ready?'
        #print self.start()
        return
开发者ID:DeathPoison,项目名称:roomControll,代码行数:33,代码来源:twistedMaster.py

示例15: __init__

    def __init__(self):
        self.ipcon = IPConnection()
        while True:
            try:
                self.ipcon.connect(SmokeDetector.HOST, SmokeDetector.PORT)
                break
            except Error as e:
                log.error('Connection Error: ' + str(e.description))
                time.sleep(1)
            except socket.error as e:
                log.error('Socket error: ' + str(e))
                time.sleep(1)

        self.ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE,
                                     self.cb_enumerate)
        self.ipcon.register_callback(IPConnection.CALLBACK_CONNECTED,
                                     self.cb_connected)

        while True:
            try:
                self.ipcon.enumerate()
                break
            except Error as e:
                log.error('Enumerate Error: ' + str(e.description))
                time.sleep(1)
开发者ID:AxelRb,项目名称:hardware-hacking,代码行数:25,代码来源:smoke_detector.py


注:本文中的tinkerforge.ip_connection.IPConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。