本文整理汇总了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))
示例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"
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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
示例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()
示例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)
示例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()
示例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
示例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
示例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