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


Python GATTRequester.write_by_handle方法代码示例

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


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

示例1: __init__

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import write_by_handle [as 别名]
class MagicBlue:
    def __init__(self, mac_address):
        self.mac_address = mac_address
        self._connection = None

    def connect(self):
        """
        Connect to device
        :return: True if connection succeed, False otherwise
        """
        self._connection = GATTRequester(self.mac_address, False)
        try:
            self._connection.connect(True, "random")
        except RuntimeError as e:
            logger.error('Connection failed : {}'.format(e))
            return False
        return True

    def disconnect(self):
        """
        Disconnect from device
        """
        self._connection.disconnect()

    def is_connected(self):
        """
        :return: True if connection succeed, False otherwise
        """
        return self._connection.is_connected()

    def set_color(self, rgb_color):
        """
        Change bulb's color
        :param rgb_color: color as a list of 3 values between 0 and 255
        """
        self._connection.write_by_handle(HANDLE_CHANGE_COLOR, bytes(bytearray([MAGIC_CHANGE_COLOR] + list(rgb_color))))

    def set_random_color(self):
        """
        Change bulb's color with a random color
        """
        self.set_color([random.randint(1, 255) for i in range(3)])

    def turn_off(self):
        """
        Turn off the light by setting color to black (rgb(0,0,0))
        """
        self.set_color([0, 0, 0])

    def turn_on(self, brightness=1.0):
        """
        Set white color on the light
        :param brightness: a float value between 0.0 and 1.0 defining the brightness
        """
        self.set_color([int(255 * brightness) for i in range(3)])
开发者ID:b0tting,项目名称:magicblue,代码行数:57,代码来源:magicbluelib.py

示例2: OnGSRButtonClick

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import write_by_handle [as 别名]
    def OnGSRButtonClick(self):
	
	    req = GATTRequester("98:4F:EE:0F:59:D6")
	    temp = []
	    f = open("gsr.csv", 'a')
	    writer = csv.writer(f)
	    writer.writerow( ('timestamp', 'gsr') )
	    flagTemp = 0;
	    flagBP = 1;
	    flagGSR = 0;
	    req.write_by_handle(0x000e,str(bytearray([01])))
	    tt = req.read_by_handle(0x0010)[0]
开发者ID:ioarun,项目名称:cognitivehealthcare,代码行数:14,代码来源:gateway_publisher.py

示例3: Reader

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import write_by_handle [as 别名]
class Reader(object):
    def __init__(self, address):
        self.requester = GATTRequester(address , False)
        self.connect()
        self.send_data()

    def connect(self):
        print("Connecting...", end=' ')
        sys.stdout.flush()

        self.requester.connect(True)
        print("OK!")

    def send_data(self):
        self.requester.write_by_handle(0xb, str(bytearray([1]))) # You can find the bluetooth handle using
开发者ID:DnPlas,项目名称:EdisonBLE,代码行数:17,代码来源:blu_led.py

示例4: Reader

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import write_by_handle [as 别名]
class Reader(object):
    def __init__(self, address):
        self.requester = GATTRequester(address, False)
        self.connect()
        self.send_data()

    def connect(self):
        print("Connecting...", end=" ")
        sys.stdout.flush()

        self.requester.connect(True)
        print("OK!")

    def send_data(self):
        self.requester.write_by_handle(0x2E, str(bytearray([2])))
开发者ID:kived,项目名称:pygattlib-tmp,代码行数:17,代码来源:write.py

示例5: OnBPButtonClick

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import write_by_handle [as 别名]
    def OnBPButtonClick(self):
	
	   f = open("bp.csv", 'wt')
	   writer = csv.writer(f)
	   writer.writerow( ('sys', 'dia','pulse') )
	   req = GATTRequester("98:4F:EE:0F:59:D6")
	   req.write_by_handle(0x000e,str(bytearray([02])))
	   tt = req.read_by_handle(0x0010)[0]
	   pp = []
	   for c in tt:
		  pp.append(ord(c))
	   print pp
	   if(pp[1] == 2):
		
		while(1):
			try:
				tt = req.read_by_handle(0x0010)[0]
				pp = []
				for c in tt:
					pp.append(ord(c))
				if(pp[0] == 3):
					break
			except Exception,e:
				print e
		
		try:
			name = req.read_by_uuid("2A40")[0]
			#steps = (req.read_by_handle(0x0009)[0])
			print type(name)
		
			value = []
			for c in name:
				value.append((c))
			print value
			print "sys :"+value[1]+value[2]+value[3]+"\n"
			print "dia :"+value[6]+value[7]+value[8]+"\n"
			print "sys :"+value[11]+value[12]+value[13]+"\n"
			writer.writerow((value[1]+value[2]+value[3],value[6]+value[7]+value[8],value[11]+value[12]+value[13]))
		
				
		except Exception,e:
			#name = False
			print e
开发者ID:ioarun,项目名称:cognitivehealthcare,代码行数:45,代码来源:gateway_publisher.py

示例6: __init__

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import write_by_handle [as 别名]
class RoboRoach:

  #######################
  #  API Constants
  #######################

  ROBOROACH_FREQUENCY_HANDLE	=	0x002A
  ROBOROACH_PULSE_WIDTH			  =	0x002cD
  ROBOROACH_NUM_PULSES		  	=	0x0030
  ROBOROACH_RANDOM_MODE       =	0x0033
  ROBOROACH_RIGHT_HANDLE		  =	0x0036
  ROBOROACH_LEFT_HANDLE		   	=	0x0039
  ROBOROACH_GAIN			      	=	0x003C
  ROBOROACH_FREQ_MIN		    	=	0x003F
  ROBOROACH_FREQ_MAX			    =	0x0042
  ROBOROACH_PW_MIN			     	=	0x0045
  ROBOROACH_PW_MAX				    =	0x0048
  ROBOROACH_GAIN_MIN          = 0x004B
  ROBOROACH_GAIN_MAX          = 0x004E

  #######################
  #  CONSTRUCTOR
  #######################

  def __init__(self, mac_address):
  	self.mac_address = mac_address

  	self.req = GATTRequester(mac_address)
  	print type(self.req)

  #######################
  #  COMMON FUNCTIONS
  #######################

  def _turn(self, direction):
  	if direction == 'right':
  	  self.req.write_by_handle(self.ROBOROACH_LEFT_HANDLE, str(bytearray([1])))
  	elif direction == 'left':
	  self.req.write_by_handle(self.ROBOROACH_RIGHT_HANDLE, str(bytearray([1])))
  	else:
  	  print "Unknown direction"
开发者ID:lucasdelevy,项目名称:RoboRoach,代码行数:43,代码来源:roboroach_api.py

示例7: GATTRequester

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import write_by_handle [as 别名]
from gattlib import GATTRequester
import time

# Send: 0x0035 for left
# Send: 0x0039 for right
# Send: 0x0029 for frequency

req = GATTRequester("90:59:AF:14:08:E8")

req.write_by_handle(0x0036, str(bytearray([1])))
time.sleep(1)
req.write_by_handle(0x0039, str(bytearray([1])))
开发者ID:lucasdelevy,项目名称:RoboRoach,代码行数:14,代码来源:send_data.py

示例8: GATTRequester

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import write_by_handle [as 别名]
		print "cilia found"
		req = GATTRequester(tag_address, False, "hci1")
		response = GATTResponse()
		req.connect()
		req.read_by_handle_async(0x3A, response)
		while not response.received():
			time.sleep(0.1)

		steps = response.received()[0]
		#print "steps..."
		#print type(steps)
		#print steps
		#for b in steps:
		#	print hex(ord(b)),' '
		
		req.write_by_handle(0x3C, str(bytearray([0xff, 0xff])))
		req.write_by_handle(0x3E, str(bytearray([0x64])))
		data = req.read_by_handle(0x3C)[0]
		#for d in data:
		#	print hex(ord(d)),' '
		#print("")
		req.write_by_handle(0x3A, str(bytearray([0x0, 0x0])))
		for i in range(1000):
			data = req.read_by_handle(0x39)[0]
			for d in data:
				print hex(ord(d)), 
			print("")
			i = 0
			axl = 0x00
			axh = 0x00
			for d in data:
开发者ID:smihir,项目名称:smartshoes,代码行数:33,代码来源:test.py

示例9: __init__

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import write_by_handle [as 别名]
class RoboRoach:

  #######################
  #  API Constants
  #######################

  ROBOROACH_FREQUENCY_HANDLE         = 0x002A
  ROBOROACH_PULSE_WIDTH_HANDLE       = 0x002D
  ROBOROACH_NUM_PULSES_HANDLE        = 0x0030
  ROBOROACH_RANDOM_MODE              = 0x0033
  ROBOROACH_RIGHT_HANDLE             = 0x0036
  ROBOROACH_LEFT_HANDLE              = 0x0039
  ROBOROACH_GAIN_HANDLE              = 0x003C
  ROBOROACH_MIN_FREQ_HANDLE          = 0x003F
  ROBOROACH_MAX_FREQ_HANDLE          = 0x0042
  ROBOROACH_MIN_PW_HANDLE            = 0x0045
  ROBOROACH_MAX_PW_HANDLE            = 0x0048
  ROBOROACH_MIN_GAIN_HANDLE          = 0x004B
  ROBOROACH_MAX_GAIN_HANDLE          = 0x004E

  #######################
  #  CONSTRUCTOR
  #######################

  def __init__(self, mac_address):
    self.mac_address = mac_address
    self.req = GATTRequester(mac_address)

    self._set_min_freq(0x0A)
    self._set_max_freq(0X46)

    self._set_min_pw(0x01)
    self._set_max_pw(0x14)

    self._set_min_gain(0x0A)
    self._set_max_gain(0x46)

  #######################
  #  AUXILIAR FUNCTIONS
  #######################
  def read_async(self, handle):
    response = GATTResponse()

    self.req.read_by_handle_async(handle, response)
    while not response.received():
      time.sleep(0.1)

    return response.received()[0]

  #######################
  #  COMMON FUNCTIONS
  #######################

  def _turn(self, direction):
    if direction == 'right':
      self.req.write_by_handle(self.ROBOROACH_LEFT_HANDLE, str(bytearray([1])))
    elif direction == 'left':
      self.req.write_by_handle(self.ROBOROACH_RIGHT_HANDLE, str(bytearray([1])))
    else:
      print "Unknown direction"

  def _rand(self, random):
    if random == True:
      self.req.write_by_handle(self.ROBOROACH_RANDOM_MODE, str(bytearray([1])))
    else:
      self.req.write_by_handle(self.ROBOROACH_RANDOM_MODE, str(bytearray([0])))

  def _set_freq(self, frequency):
    self.req.write_by_handle(self.ROBOROACH_FREQUENCY_HANDLE, str(bytearray([frequency])))

  def _get_freq(self):
    freq = self.read_async(self.ROBOROACH_FREQUENCY_HANDLE)
    return freq.encode('hex')

  def _set_pw(self, pulse_width):
    self.req.write_by_handle(self.ROBOROACH_PULSE_WIDTH_HANDLE, str(bytearray([pulse_width])))

  def _get_pw(self):
    pulse_width = self.read_async(self.ROBOROACH_PULSE_WIDTH_HANDLE)
    return pulse_width.encode('hex')

  def _set_gain(self, gain):
    self.req.write_by_handle(self.ROBOROACH_GAIN_HANDLE, str(bytearray([gain])))

  def _get_gain(self):
    gain = self.read_async(self.ROBOROACH_GAIN_HANDLE)
    return gain.encode('hex')

  def _set_min_freq(self, freq):
    self.req.write_by_handle(self.ROBOROACH_MIN_FREQ_HANDLE, str(bytearray([freq])))

  def _set_max_freq(self, freq):
    self.req.write_by_handle(self.ROBOROACH_MAX_FREQ_HANDLE, str(bytearray([freq])))

  def _get_min_freq(self):
    min_freq = self.read_async(self.ROBOROACH_MIN_FREQ_HANDLE)
    return min_freq.encode('hex')

  def _get_max_freq(self):
    max_freq = self.read_async(self.ROBOROACH_MAX_FREQ_HANDLE)
#.........这里部分代码省略.........
开发者ID:lucasdelevy,项目名称:RoboRoach,代码行数:103,代码来源:control_api.py


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