示例#1
0
    def __init__(self, service_uuid, char_uuid, processData, sendHeartbeat,
                 reset):
        super().__init__()
        self.SERVICE_UUID = QtBluetooth.QBluetoothUuid(service_uuid)
        self.CHAR_UUID = QtBluetooth.QBluetoothUuid(char_uuid)
        self.processData = processData
        self.sendHeartbeat = sendHeartbeat
        self.reset = reset

        self.m_deviceDiscoveryAgent = QtBluetooth.QBluetoothDeviceDiscoveryAgent(
        )
        self.m_notificationDesc = QtBluetooth.QLowEnergyDescriptor()
        self.m_control = None
        #self.m_servicesUuid = QtBluetooth.QBluetoothUuid()
        self.m_servicesUuid = []
        self.m_service = QtBluetooth.QLowEnergyService
        self.m_readCharacteristic = QtBluetooth.QLowEnergyCharacteristic()
        self.m_writeCharacteristic = QtBluetooth.QLowEnergyCharacteristic()
        self.m_writemode = QtBluetooth.QLowEnergyService.WriteMode()

        self.m_device = None  # bound to the device if discovered
        self.m_services = []
        self.m_currentService = None
        self.m_connected = False
        self.m_readTimer = None

        self.m_deviceDiscoveryAgent.setLowEnergyDiscoveryTimeout(500)
        self.m_deviceDiscoveryAgent.deviceDiscovered.connect(self.addDevice)
        self.m_deviceDiscoveryAgent.error.connect(self.onDeviceScanError)
        self.m_deviceDiscoveryAgent.finished.connect(self.onScanFinished)
        self.m_deviceDiscoveryAgent.canceled.connect(self.onScanFinished)
        self.dataReceived.connect(self.printDataReceived)
示例#2
0
    def __init__(self, parent=None):
        super().__init__(parent)

        # instance variables. Er is maar 1 instance?
        self.currentDevice = DeviceInfo()  # type: DeviceInfo
        self.devices = []  # type: List[DeviceInfo]
        self.m_services = []  # type: List[QObject]
        self.currentService = None
        self.currentCharacteristic = None
        self.m_characteristics = []  # type: List[QObject]
        self.m_previousAddress = ''
        self.m_message = ''
        self.connected = False
        self.m_deviceScanState = False
        self.randomAddress = False

        self.blcomm = ''
        self.blresult = QByteArray()

        self.discoveryAgent = QtBt.QBluetoothDeviceDiscoveryAgent()
        self.discoveryAgent.setLowEnergyDiscoveryTimeout(5000)

        self.discoveryAgent.deviceDiscovered.connect(self.addDevice)
        self.discoveryAgent.error.connect(self.deviceScanError)
        self.discoveryAgent.finished.connect(self.deviceScanFinished)

        self.controller = None
        self.setUpdate('Search')
	def __init__(self, parent):
		super().__init__()
		self.parent = parent

		self.discoverer = QtBluetooth.QBluetoothDeviceDiscoveryAgent(self)
		self.discoverer.setLowEnergyDiscoveryTimeout(0)
		self.discoverer.deviceDiscovered.connect(self.checkDevice)
		self.discoverer.start(QtBluetooth.QBluetoothDeviceDiscoveryAgent.DiscoveryMethod(2))

		self.central = None
		self.service = None
		self.positionChrc = None
		self.buttonsPressChrc = None

		self.x = 0.5
		self.y = 0.5

		self.descriptCount = 0

		self.setupDone.connect(parent.start)

		self.button1.connect(parent.changeMode)
		self.button2.connect(parent.leftClick)
		self.button3.connect(parent.rightClick)
		self.button4.connect(parent.changeVisibility)
		self.button5.connect(parent.quit)
		self.pos.connect(parent.move)
示例#4
0
    def __init__(self, service_uuid, char_uuid, processData, sendHeartbeat,
                 sendStop, reset):
        super().__init__()

        self.SERVICE_UUID = QtBluetooth.QBluetoothUuid(service_uuid)
        self.CHAR_UUID = QtBluetooth.QBluetoothUuid(char_uuid)
        self.processData = processData
        self.sendHeartbeat = sendHeartbeat
        self.sendStop = sendStop
        self.reset = reset

        self.QBluetoothDeviceDiscoveryAgent_LowEnergyMethod = 2
        self.ENABLE_NOTIFICATION_VALUE = QtCore.QByteArray.fromHex(b"0100")
        self.DISABLE_NOTIFICATION_VALUE = QtCore.QByteArray.fromHex(b"0000")

        self.m_deviceDiscoveryAgent = QtBluetooth.QBluetoothDeviceDiscoveryAgent(
        )
        self.m_deviceDiscoveryAgent.setLowEnergyDiscoveryTimeout(500)
        self.m_deviceDiscoveryAgent.deviceDiscovered.connect(self.addDevice)
        self.m_deviceDiscoveryAgent.finished.connect(self.onScanFinished)
        self.m_deviceDiscoveryAgent.canceled.connect(self.onScanFinished)

        self.m_device = None
        self.m_control = None
        self.m_service = None

        self.m_notificationDesc = QtBluetooth.QLowEnergyDescriptor()
        self.m_readCharacteristic = QtBluetooth.QLowEnergyCharacteristic()
        self.m_writeCharacteristic = QtBluetooth.QLowEnergyCharacteristic()
        self.m_writemode = QtBluetooth.QLowEnergyService.WriteMode()

        self.m_connected = False
        self.m_readTimer = None

        self.dataReceived.connect(self.printDataReceived)
示例#5
0
    def bluetoothTest(self):
        self.agent = QtBt.QBluetoothDeviceDiscoveryAgent(self)
        self.agent.deviceDiscovered.connect(self.foo)
        self.agent.finished.connect(self.foo)
        self.agent.error.connect(self.foo)
        self.agent.setLowEnergyDiscoveryTimeout(1000)

        timer = QTimer(self.agent)
        timer.start(500)
        timer.timeout.connect(self.display_status)
示例#6
0
    def scan_for_devices(self):
        self.agent = QtBt.QBluetoothDeviceDiscoveryAgent(self)
        self.agent.deviceDiscovered.connect(self.device_discovered)
        self.agent.finished.connect(self.finished)
        self.agent.error.connect(self.error)
        self.agent.setLowEnergyDiscoveryTimeout(1000)

        timer = QtCore.QTimer(self.agent)
        timer.start(2000)
        timer.timeout.connect(self.display_status)

        self.agent.start()
示例#7
0
    def __init__(self):
        self.local_device = QtBt.QBluetoothLocalDevice()
        self.local_device.deviceConnected.connect(self.notify_connect)
        self.local_device.deviceDisconnected.connect(self.notify_disconnect)

        self.agent = QtBt.QBluetoothDeviceDiscoveryAgent()
        self.agent.deviceDiscovered.connect(self.notify_discovered)
        self.agent.finished.connect(self.notify_finished)
        self.agent.error.connect(self.notify_error)
        self.agent.setLowEnergyDiscoveryTimeout(60000)

        self.scan_loop_timer = QTimer()
        self.scan_loop_timer.timeout.connect(self.scan_loop)

        self.bluetooth_speaker_cb = object()
示例#8
0
    def __init__(self, device, postman, parent=None):
        super(BluetoothSearch, self).__init__(parent)
        uic.loadUi('GUI/bluetoothSearch.ui', self)

        self.device = device
        self.postman = postman
        self.agent = QtBluetooth.QBluetoothDeviceDiscoveryAgent(self)
        self.agent.error.connect(self.error)
        self.agent.deviceDiscovered.connect(self.discovered)
        self.agent.finished.connect(self.stop)

        self.bScan.clicked.connect(self.scan)
        self.buttonBox.accepted.connect(self.save)
        self.localDevice = QtBluetooth.QBluetoothLocalDevice()
        if self.localDevice.isValid():
            self.localDevice.powerOn()
        self.postman.Post.emit("Bluetooth_" + self.device.getName(),
                               self.device.getName(),
                               'Connect to: ' + self.localDevice.name())
示例#9
0
    def __init__(self):
        super().__init__()
        self.m_deviceDiscoveryAgent = QtBluetooth.QBluetoothDeviceDiscoveryAgent(
        )
        self.m_notificationDesc = QtBluetooth.QLowEnergyDescriptor()
        self.m_control = None
        #self.m_servicesUuid = QtBluetooth.QBluetoothUuid()
        self.m_servicesUuid = []  #用于存放设备的服务的UUID
        self.m_service = QtBluetooth.QLowEnergyService  #用于存放设备具体使用的服务
        self.m_readCharacteristic = QtBluetooth.QLowEnergyCharacteristic(
        )  #用于存放读取的服务的特性内容
        self.m_writeCharacteristic = QtBluetooth.QLowEnergyCharacteristic(
        )  #用于存放写入的服务的特性内容
        self.m_devices = []  #用于存放获取的设备列表
        self.m_writemode = QtBluetooth.QLowEnergyService.WriteMode()
        self.m_readTimer = QtCore.QTimer()

        self.m_connected = bool
        self.m_devicesNames = []
        self.m_services = []
        self.m_currentDevice = None
        self.m_currentService = None

        #初始化相关变量
        self.m_connected(False)
        #self.m_control(None)
        self.m_readTimer = None
        #self.m_currentService(None)
        #self.m_currentDevice(None)

        #绑定设备发现相关信号函数
        self.m_deviceDiscoveryAgent.setLowEnergyDiscoveryTimeout(500)
        self.m_deviceDiscoveryAgent.deviceDiscovered.connect(self.addDevice)
        self.m_deviceDiscoveryAgent.error.connect(self.onDeviceScanError)
        self.m_deviceDiscoveryAgent.finished.connect(self.onScanFinished)
        self.m_deviceDiscoveryAgent.canceled.connect(self.onScanFinished)
        self.dataReceived.connect(self.printDataReceived)
示例#10
0
 def __init__(self, app):
     self.local_device = QtBt.QBluetoothLocalDevice()
     self.agent = QtBt.QBluetoothDeviceDiscoveryAgent()
     self.timer = QTimer()
     self.ben = object
     self.app = app