Browse Source

Added config retrieval and F-key constants.

pyserial_fix
Scott Petersen 11 years ago
parent
commit
6ee5232c80
2 changed files with 39 additions and 1 deletions
  1. +32
    -0
      pyad2usb/ad2usb.py
  2. +7
    -1
      test.py

+ 32
- 0
pyad2usb/ad2usb.py View File

@@ -155,6 +155,7 @@ class AD2USB(object):
on_alarm = event.Event('Called when the alarm is triggered.') on_alarm = event.Event('Called when the alarm is triggered.')
on_bypass = event.Event('Called when a zone is bypassed.') on_bypass = event.Event('Called when a zone is bypassed.')
on_boot = event.Event('Called when the device finishes bootings.') on_boot = event.Event('Called when the device finishes bootings.')
on_config_received = event.Event('Called when the device receives its configuration.')


# Mid-level Events # Mid-level Events
on_message = event.Event('Called when a message has been received from the device.') on_message = event.Event('Called when a message has been received from the device.')
@@ -165,6 +166,12 @@ class AD2USB(object):
on_read = event.Event('Called when a line has been read from the device.') on_read = event.Event('Called when a line has been read from the device.')
on_write = event.Event('Called when data has been written to the device.') on_write = event.Event('Called when data has been written to the device.')


# Constants
F1 = str(1) + str(1) + str(1)
F2 = str(2) + str(2) + str(2)
F3 = str(3) + str(3) + str(3)
F4 = str(4) + str(4) + str(4)

def __init__(self, device): def __init__(self, device):
""" """
Constructor Constructor
@@ -174,6 +181,8 @@ class AD2USB(object):
self._alarm_status = None self._alarm_status = None
self._bypass_status = None self._bypass_status = None


self._settings = {}

self._address_mask = 0xFF80 # TEMP self._address_mask = 0xFF80 # TEMP


def open(self, baudrate=None, interface=None, index=None, no_reader_thread=False): def open(self, baudrate=None, interface=None, index=None, no_reader_thread=False):
@@ -190,6 +199,18 @@ class AD2USB(object):
self._device.close() self._device.close()
self._device = None self._device = None


def get_config(self):
"""
Retrieves the configuration from the device.
"""
self._device.write("C\r")

def set_config(self, settings):
"""

"""
pass

def reboot(self): def reboot(self):
""" """
Reboots the device. Reboots the device.
@@ -235,9 +256,20 @@ class AD2USB(object):
msg = LRRMessage(data) msg = LRRMessage(data)
elif data.startswith('!Ready'): elif data.startswith('!Ready'):
self.on_boot() self.on_boot()
elif data.startswith('!CONFIG'):
self._handle_config(data)


return msg return msg


def _handle_config(self, data):
_, config_string = data.split('>')
for setting in config_string.split('&'):
k, v = setting.split('=')

self._settings[k] = v

self.on_config_received(self._settings)

def _update_internal_states(self, message): def _update_internal_states(self, message):
if message.ac_power != self._power_status: if message.ac_power != self._power_status:
self._power_status, old_status = message.ac_power, self._power_status self._power_status, old_status = message.ac_power, self._power_status


+ 7
- 1
test.py View File

@@ -74,6 +74,9 @@ def handle_firmware(stage):
def handle_boot(sender, args): def handle_boot(sender, args):
print 'boot', args print 'boot', args


def handle_config(sender, args):
print 'config', args

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


@@ -215,9 +218,12 @@ def test_socket():
a2u.on_alarm += handle_alarm_bell a2u.on_alarm += handle_alarm_bell
a2u.on_bypass += handle_bypass a2u.on_bypass += handle_bypass
a2u.on_boot += handle_boot a2u.on_boot += handle_boot
a2u.on_config_received += handle_config


a2u.open() a2u.open()
a2u.reboot()
#a2u.reboot()
time.sleep(2)
a2u.get_config()


print dev._id print dev._id




Loading…
Cancel
Save