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


Python IPConnection.connect方法代码示例

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


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

示例1: Window

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
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,代码行数:36,代码来源:example_gui_red.py

示例2: sound_activated

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
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,代码行数:62,代码来源:tinkerforgebricks.py

示例3: collect_data

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
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,代码行数:30,代码来源:recordstuff.py

示例4: temperature

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
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,代码行数:9,代码来源:sqlitesaver.py

示例5: humidity

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
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,代码行数:9,代码来源:sqlitesaver.py

示例6: barometer

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
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,代码行数:9,代码来源:sqlitesaver.py

示例7: ambient

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
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,代码行数:9,代码来源:sqlitesaver.py

示例8: connect

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
        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,代码行数:10,代码来源:rb_setup.py

示例9: connect

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
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,代码行数:11,代码来源:tinkerGPS2Basemaps.py

示例10: TinkerforgeConnection

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
class TinkerforgeConnection(object):
    # Connection to the Brick Daemon on localhost and port 4223
    ipcon = None
    current_entries = dict()

    # noinspection PyUnusedLocal
    def cb_enumerate(self, uid, connected_uid, position, hardware_version, firmware_version, device_identifier,
                     enumeration_type):

        if enumeration_type == IPConnection.ENUMERATION_TYPE_DISCONNECTED:
            del self.current_entries[uid]

        else:
            if device_identifier == 13:
                self.current_entries.update({uid: "Master Brick"})
            elif device_identifier == 21:
                self.current_entries.update({uid: "Ambient Light Bricklet"})
            elif device_identifier == 229:
                self.current_entries.update({uid: "Distance US Bricklet"})
            elif device_identifier == 235:
                self.current_entries.update({uid: "RemoteSwitchBricklet"})
            else:
                self.current_entries.update(
                    {uid: "device_identifier = {0}".format(device_identifier)})

    def switch_socket(self, uid, address, unit, state):
        rs = BrickletRemoteSwitch(uid, self.ipcon)
        rs.switch_socket_b(address, unit, state)

    def dim_socket(self, uid, address, unit, value):
        rs = BrickletRemoteSwitch(uid, self.ipcon)
        rs.dim_socket_b(address, unit, value)

    def get_illuminance(self, uid):
        try:
            al = BrickletAmbientLight(uid, self.ipcon)
            return al.get_illuminance() / 10
        except Exception:
            log.warn(uid + " not connected")
            return -1

    def get_distance(self, uid):
        try:
            dus = BrickletDistanceUS(uid, self.ipcon)
            return dus.get_distance_value()
        except Exception:
            log.warn(uid + " not connected")
            return -1

    def __init__(self, ip_address):
        self.ipcon = IPConnection()
        self.ipcon.connect(ip_address, 4223)
        self.ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, self.cb_enumerate)
        self.ipcon.enumerate()
开发者ID:JonathanH5,项目名称:meinHeim,代码行数:56,代码来源:modules.py

示例11: index

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
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,代码行数:14,代码来源:index.py

示例12: __init__

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
class volt_cur:
    def __init__(self):
        self.vc = None

        # Create IP Connection
        self.ipcon = IPConnection() 

        # Register IP Connection callbacks
        self.ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, 
                                     self.cb_enumerate)
        self.ipcon.register_callback(IPConnection.CALLBACK_CONNECTED, 
                                     self.cb_connected)

        # Connect to brickd, will trigger cb_connected
        self.ipcon.connect(constants.ownIP, PORT) 
        #self.ipcon.enumerate()                 
       
    
    def cb_reached_vc(self):        
        voltage = self.vc.get_voltage()
        dicti = {}
        dicti['value'] = str(voltage)
        dicti['name'] = 'Voltage'
        mySocket.sendto(str(dicti),(constants.server1,constants.broadPort)) 
        mySocket.sendto(str(dicti),(constants.server1,constants.broadPort)) 
        current = self.vc.get_current()
        dicti = {}
        dicti['value'] = str(current)
        dicti['name'] = 'Current'
        mySocket.sendto(str(dicti),(constants.server1,constants.broadPort)) 
        mySocket.sendto(str(dicti),(constants.server1,constants.broadPort))         
        thread_cb_reached = Timer(60, self.cb_reached_vc, [])
        thread_cb_reached.start()        
       
    
    # Callback handles device connections and configures possibly lost 
    # configuration of lcd and temperature callbacks, backlight etc.
    def cb_enumerate(self, uid, connected_uid, position, hardware_version, 
                     firmware_version, device_identifier, enumeration_type):

        if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED or \
           enumeration_type == IPConnection.ENUMERATION_TYPE_AVAILABLE:
            
            # Enumeration for V/C
            if device_identifier == BrickletVoltageCurrent.DEVICE_IDENTIFIER:
                self.vc = BrickletVoltageCurrent(uid, self.ipcon)
                self.cb_reached_vc()
        
    def cb_connected(self, connected_reason):
        # Enumerate devices again. If we reconnected, the Bricks/Bricklets
        # may have been offline and the configuration may be lost.
        # In this case we don't care for the reason of the connection
        self.ipcon.enumerate()    
开发者ID:chrihuc,项目名称:satellite,代码行数:55,代码来源:tf_class.py

示例13: lies_temp

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
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,代码行数:17,代码来源:tf_temperature.py

示例14: __init__

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
	def __init__(self):
		#uinput Bereich
		self.events = (
			uinput.BTN_A, #Es wird mindestens ein Button benötigt (seltsam)
			uinput.ABS_Z + (-150, 150, 0, 0), #Erstellt Joystick Achse Z, kleinster Wert des Potis ist -150, größter Wert ist +150
			)

		self.device = uinput.Device(self.events, "TF Virutal HID Joystick")
		
		#TinkerForge Bereich
		ipcon = IPConnection()
		self.poti = RotaryPoti("aBQ", ipcon) #UID ändern!

		ipcon.connect("127.0.0.1", 4223) #IP / Port anpassen
		self.poti.set_position_callback_period(50)
		self.poti.register_callback(self.poti.CALLBACK_POSITION, self.poti_cb) #Sobald der Callback auslöst wird die Funktion poti_cb aufgerufen
开发者ID:HcDevel,项目名称:TinkerForge-HID-Interface,代码行数:18,代码来源:rotary-poti-example.py

示例15: getTFconn

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import connect [as 别名]
def getTFconn( HOST=TF_HOST, PORT=TF_PORT ):
    try:
        ipcon = IPConnection()
    except  Exception as e:
        errmsg = str(traceback.format_exception( *sys.exc_info() ));
        Logger.info( 'Tinkerforge IPConnection failed ... ' + errmsg );
        sendEmail(admin,'getPower.py', 'Tinkerforge IPConnection failed ... ' + errmsg )
        sys.exit(-1) # should cause rPi to reboot
    try:
        ipcon.connect(HOST, PORT)
    except  Exception as e:
        errmsg = str(traceback.format_exception( *sys.exc_info() ));
        Logger.info( 'Tinkerforge unable to connect! ' + errmsg );
        sendEmail(admin,'getPower.py', 'Tinkerforge unable to connect! ' + errmsg )
        sys.exit(-1) # should cause rPi to reboot
    return ipcon
开发者ID:matthiku,项目名称:buildingAutomationBackend,代码行数:18,代码来源:libFunctions.py


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