Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop main loop #32

Open
rafifajar22 opened this issue Jul 12, 2018 · 4 comments
Open

stop main loop #32

rafifajar22 opened this issue Jul 12, 2018 · 4 comments

Comments

@rafifajar22
Copy link

rafifajar22 commented Jul 12, 2018

how to stop main loop, because there is blocking, and and I can't call stop function, this my code

import gatt

manager = gatt.DeviceManager(adapter_name='hci0')

class AnyDevice(gatt.Device):
def services_resolved(self):
super().services_resolved()

    device_proprietary_service = next(
        s for s in self.services
        if s.uuid == 'd0cbda9a-9a69-49ab-b4d1-a96d6fbd10c6')

    psp = next(
        c for c in device_proprietary_service.characteristics
        if c.uuid == 'd0cb6c99-9a69-49ab-b4d1-a96d6fbd10c6')

psp.write_value(bytearray(b'\x0a'))
tes="\x1D\x5A\x02"
best=tes.encode()
psp.write_value(best)
kay="\x1B\x5A\x00\x4C\x08\x11\x00\x43\x44\x3A\x42\x30\x3A\x32\x31\x3A\x32\x31\x3A\x34\x30\x3A\x42\x33"
best=kay.encode()
psp.write_value(best)

def characteristic_value_updated(self, characteristic, value):
    print(str(characteristic)+", value: "+value.decode("utf-8"))

def characteristic_write_value_succeeded(self, characteristic):
    print("Write successful.")

def characteristic_write_value_failed(self, characteristic, error):
    print("Write failed. "+str(error))

class Manager(gatt.DeviceManager):
def run(self):
print("Running Manager")
super().run()
def quit(self):
print("Stopping Manager")
super().stop()

manager = Manager(adapter_name = 'hci0')
device = AnyDevice(mac_address='CD:B0:21:21:40:B3', manager=manager)
device.connect()

manager.run()
time.sleep(2)
manager.quit()

@JlnWntr
Copy link

JlnWntr commented Nov 27, 2018

This is a good question.

@Snevzor
Copy link

Snevzor commented Nov 27, 2018

Hello, please see #28

@JlnWntr
Copy link

JlnWntr commented Nov 27, 2018

Thank you, but this refers to KeyboardInterrupts. How can you stop() the manager via python code some seconds after calling manager.run() ?

@JlnWntr
Copy link

JlnWntr commented Dec 3, 2018

#38
I've added a function for a timeout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants