Browse Source

Added boot event and reboot method.

pyserial_fix
Scott Petersen 11 years ago
parent
commit
e568991735
2 changed files with 14 additions and 0 deletions
  1. +9
    -0
      pyad2usb/ad2usb.py
  2. +5
    -0
      test.py

+ 9
- 0
pyad2usb/ad2usb.py View File

@@ -154,6 +154,7 @@ class AD2USB(object):
on_power_changed = event.Event('Called when panel power switches between AC and DC.')
on_alarm = event.Event('Called when the alarm is triggered.')
on_bypass = event.Event('Called when a zone is bypassed.')
on_boot = event.Event('Called when the device finishes bootings.')

# Mid-level Events
on_message = event.Event('Called when a message has been received from the device.')
@@ -189,6 +190,12 @@ class AD2USB(object):
self._device.close()
self._device = None

def reboot(self):
"""
Reboots the device.
"""
self._device.write('=')

@property
def id(self):
return self._device.id
@@ -224,6 +231,8 @@ class AD2USB(object):
msg = ExpanderMessage(data)
elif header == '!RFX':
msg = RFMessage(data)
elif data.startswith('!Ready'):
self.on_boot()

return msg



+ 5
- 0
test.py View File

@@ -71,6 +71,9 @@ def handle_firmware(stage):
elif stage == pyad2usb.ad2usb.util.Firmware.STAGE_DONE:
print "\r\nDone!"

def handle_boot(sender, args):
print 'boot', args

def upload_usb():
dev = pyad2usb.ad2usb.devices.USBDevice()

@@ -211,8 +214,10 @@ def test_socket():
a2u.on_power_changed += handle_power_changed
a2u.on_alarm += handle_alarm_bell
a2u.on_bypass += handle_bypass
a2u.on_boot += handle_boot

a2u.open()
a2u.reboot()

print dev._id



Loading…
Cancel
Save