本文整理汇总了Python中Device.Device类的典型用法代码示例。如果您正苦于以下问题:Python Device类的具体用法?Python Device怎么用?Python Device使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Device类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, config, device_no=1, hot_start=False, print_logs=False):
Device.__init__(self, config, device_no, hot_start, print_logs)
# Basics
self.CommandEndCharacter = '\r\n'
self.ReadSleepTime = .1
self.WriteSleepTime = .1
self.AnswerTime = .1
self.Config = config
self.MaxVoltage = None
self.Identifier = None
self.Model = None
# Serial
self.bOpen = False
self.SerialPortName = self.Config.get(self.SectionName, 'address')
self.Serial = None
self.open_serial_port()
# Info
self.Busy = False
self.last_write = ''
self.LastMeasurement = -1
self.LastCurrents = []
self.LastVoltages = []
self.LastStatusUpdate = -1
self.LastStatus = []
self.lastVoltage = 0
self.CanRamp = True
self.init_device(hot_start)
self.hot_start()
示例2: __init__
def __init__(self):
Device.__init__(self)
self.__pagein = 0
self.__pageout = 0
self.__time = time.time()
self.__lock = threading.Lock()
示例3: unicalDev
def unicalDev(self, dev):
unicality = True
d = Device(dev)
for device in self.data_list :
if d.device_name() == device.device_name() and \
d.device_type() == device.device_type() :
unicality = False
break
return unicality
示例4: __init__
def __init__(self, dev):
Device.__init__(self)
self.__dev = dev
buf = gtop.netload(dev)
self.__in, self.__out = buf.bytes_in, buf.bytes_out
self.__time = time.time()
self.__lock = threading.Lock()
示例5: addComputer
def addComputer(self, name):
device = Device('computer.jpg', name, 'computer', self)
device.move(100, 65)
device.show()
self.deviceList.append(device)
try:
self.detailsWindow.updateDetails()
except Exception as e:
pass
示例6: enrollDevice
def enrollDevice(deviceOwner = "", deviceType = "", deviceName = ""):
deviceId = generateId()
device = Device()
device.deviceID = deviceId
device.deviceType = deviceType
device.deviceName = deviceName
device.deviceOwner = deviceOwner
deviceDao = DeviceDAO()
return deviceDao.createDevice(device)
示例7: __init__
def __init__(self):
Device.__init__(self)
self.__total = 0.0
self.__user = 0.0
self.__sys = 0.0
self.__nice = 0.0
self.__idle = 0.0
self.__lock = threading.Lock()
示例8: build_device
def build_device(self, the_json):
d = Device()
if "name" in the_json:
d.name = the_json["name"]
if "sensors" in the_json:
for sensor in the_json["sensors"]:
if '__type__' in sensor and sensor['__type__'] == 'Sensor':
self.build_sensor(d, sensor)
if "actuator" in the_json:
self.build_actuator(d, the_json["actuator"])
return d
示例9: __init__
def __init__(self, key, port, host=''):
import socket
from NetRenderer import NetRenderer
Device.__init__(self, NetRenderer())
self.host = host
self.port = port
import journal
self._marshaller = journal.pickler()
self._marshaller.key = key
return
示例10: __init__
def __init__(self, key, port, host=''):
import socket
from NetRenderer import NetRenderer
Device.__init__(self, NetRenderer())
import pyre.ipc
self._connection = pyre.ipc.connection('udp')
self._connection.connect((host, port))
import journal
self._marshaller = journal.pickler()
self._marshaller.key = key
return
示例11: scan_response_handler
def scan_response_handler(self, sender, args):
'''
Handles all of the scan response data and stores it in a list of device objects
:param sender:
:param args:
:return:
'''
addr = args['sender']
if not self.find_device(addr):
d = Device(self.bglib, self.cmd_q, addr)
self.devices.append(d)
ad_data = parse_scan_response_data(args['data'])
if 'name' in ad_data:
d.name = ad_data['name']
示例12: __init__
def __init__(self, config, device_no=1, hot_start=False):
Device.__init__(self, config, device_no, hot_start)
# Serial
self.bOpen = False
self.bOpenInformed = False
self.serialPortName = config.get(self.SectionName, 'address')
self.baudrate = config.getint(self.SectionName, 'baudrate')
self.serial = None
self.commandEndCharacter = chr(13) + chr(10)
self.writeSleepTime = 0.1
self.readSleepTime = 0.2
self.measurements = deque()
self.last_voltage = 0
self.identifier = None
self.Model = None
self.MaxVoltage = None
self.manual = False
self.open_serial_port()
示例13: parseDevice
def parseDevice(jsonData):
decoded = json.loads(jsonData)
# for a in decoded.keys():
# print decoded[a]
# for b in decoded[a].keys():
# print decoded[a][b]
device = Device()
device.DeviceType = decoded['device']['DeviceType']
device.Name = decoded['device']['Name']
device.Battery = decoded['device']['Battery']
device.UnReadMessages = decoded['device']['UnReadMessages']
device.PhoneCall = decoded['device']['PhoneCall']
device.Mac = decoded['device']['Mac']
return device
示例14: evaluate
def evaluate(self, batchess, results, result_format, num_frames):
"""
:param list[list[EngineBatch.Batch]] batchess: batches per device
:param list[list[numpy.ndarray]] results: results per device
:param list[str]|None result_format: describes what we have in a result list
:type num_frames: NumbersDict
:returns some score or None
:rtype: dict[str] | None
"""
assert results
assert result_format # train should always have the format
assert num_frames["data"] > 0
# We can get info such as "cost:..." and more info such as gradient_norm.
# See Device.initialize().
# We might also get gparams or ctc_priors or so. We will filter them out below when not needed.
results = [Device.make_result_dict(res, result_format) for res in results]
batch_norm_fact = 1 if not self.share_batches else 1.0 / len(self.devices)
summed_results = {}
for key in results[0].keys():
summed_results[key] = sum([res[key] for res in results]) * batch_norm_fact
# Accumulate for epoch stats.
for key, value in summed_results.items():
if key.startswith("gparam:"): continue
if key not in self.results:
self.results[key] = value # / float(num_frames[target])
else:
self.results[key] += value # / float(num_frames[target])
# Prepare eval info stats for this (multiple-)batch run.
eval_info = {}
for key, value in summed_results.items():
if key.startswith("gparam:"): continue
if key == "ctc_priors": continue
target = self._get_target_for_key(key)
eval_info[key] = value / float(num_frames[target])
#if numpy.isinf(score) or numpy.isnan(score):
# for i, res in enumerate(results):
# if numpy.isinf(res["cost"]) or numpy.isnan(res["cost"]):
# raise ModelBrokenError("Model is broken, got %s score." % score, batchess[i])
# assert False # Should not get here.
return eval_info
示例15: finish
def finish(self):
"""
:returns whether everything is fine.
"""
device_results, outputs_format = self.device_collect_results()
if device_results is None:
if not getattr(sys, "exited", False):
print("device crashed on batch", self.run_start_batch_idx, file=log.v3)
self.parent.device_crash_batch = self.run_start_batch_idx
self.crashed = True
return False
assert len(device_results) == len(self.alloc_devices) == len(self.running_devices_batches)
if outputs_format and any([k.startswith("gparam:") for k in outputs_format]):
# WARNING: this code is untested and likely broken!
for i in range(len(self.alloc_devices)):
res = Device.make_result_dict(device_results[i], outputs_format)
self.alloc_devices[i].sync_net_train_params()
devnet = self.alloc_devices[i].get_net_train_params(self.parent.network)
vars = self.parent.network.get_all_params_vars()
for p, q in zip(vars, devnet):
p.set_value(q)
gparams = {}
for p in vars:
gparams[p] = numpy.zeros(p.get_value(borrow=True, return_internal_type=True).shape, dtype=theano.config.floatX)
for p in vars:
q = res["gparam:%s" % p.name]
if q.shape == p.get_value().shape:
gparams[p] = q
elif q.shape:
print("warning: shape for gradient does not match:", p.get_value().shape, q.shape, file=log.v2)
self.parent.updater.setNetParamDeltas(gparams)
self.parent.updater.update()
self.alloc_devices[i].set_net_params(self.parent.network)
self.result = { 'batchess': self.running_devices_batches,
'results': device_results,
'result_format': outputs_format,
'num_frames': self.num_frames }
self.eval_info = self.parent.evaluate(**self.result)
self.parent.lock.acquire()
self.print_process()
self.parent.lock.release()
return True