Exemple #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)
Exemple #2
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)
Exemple #3
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)