Esempio n. 1
0
def main():
    try:
        dispatcher = Dispatcher()
        host = Host(dispatcher, "/dev/ttyUSB0")
        dispatcher.add_host(host)
        Tasklet.new(dispatcher.loop)()

        print "Calibration: %s" % host.calibrate_baudrate()
        print "Available: %s" % host.available()

        dev = RadioDevice(dispatcher, 2)
        print "Protocol version: %s" % dev.protocol_version

        # Running HTTP server
        application = django.core.handlers.wsgi.WSGIHandler()
        def app_wrapper(*args, **kwargs):
            try:
                return application(*args, **kwargs)
            except Exception as e:
                print e
        server = WSGIServer(application)
        server.serve(('localhost', 8080))

        while True:
            print "ADC data: %s, supply voltage: %.2f" % (dev.adc_data(), dev.supply_voltage())
            Tasklet.sleep(1)

        os._exit(0)
    except Exception as e:
        logging.exception(e)
        os._exit(1)
Esempio n. 2
0
 def testADC(self):
     dev = RadioDevice(self.dispatcher, 2)
     self.assertEqual(dev.adc_data(), [0, 1, 256, 1024, 65535, 184])