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