Exemplo n.º 1
0
    def _test_rpc():
        ''' For doctest
            >>> from zero.rpc import ZeroRPC
            >>> ZeroRPC._test_rpc()
            REP u'hello'
            REP 100
        '''
        from zero import Zero, ZeroSetup
        class Z(ZeroRPC):
            def hi(self):
                return "hello"

            def sqr(self, x):
                return x*x

        def listen():
            zero = Zero(ZeroSetup('rep', 8000)).activated(Z())
            for _, msg in izip(range(2), zero):
                zero(msg)
            zero.close()

        from threading import Thread
        t = Thread(name='TestRPC', target=listen)
        t.daemon = True
        t.start()

        zero = Zero(ZeroSetup('req', 8000))
        msg = ['hi']
        rep = zero(msg)
        print 'REP %r' % rep
        msg = ['sqr', {'x': 10}]
        rep = zero(msg)
        print 'REP %r' % rep
        zero.close()
        t.join()
Exemplo n.º 2
0
def main():
    import sys
    if len(sys.argv) > 1 and sys.argv[1] == 'test':
        # Running tests, not zeros
        import doctest
        sys.path.insert(0, '..')
        import zero
        import zero.rpc
        fails, tests = doctest.testmod(zero)
        fails2, tests2 = doctest.testmod(zero.rpc)
        tests += tests2
        if fails + fails2:
            msg = 'Completed %d tests, %d failed. Run zero test -v for more information.'
            sys.exit(msg % (tests, fails + fails2))
        print 'Successfully completed %d tests.' % tests
        return

    import json
    from zero import Zero, ZeroSetup, zauto, UnsupportedZmqMethod
    try:
        # Regular zero run
        setup, loop = ZeroSetup.argv()
        zero = Zero(setup)

        for msg in zauto(zero, loop, setup.args['--wait']):
            sys.stdout.write(json.dumps(msg) + '\n')
            sys.stdout.flush()
    except UnsupportedZmqMethod, e:
        args = e.args[2]
        if args['rpc']:
            # Configured RPC not supported by zauto
            from zero.rpc import zrpc
            with open(args['<config>']) as fin:
                config = json.load(fin)
            if len(args['<type>']) == 1:
                zero = zrpc(config, args['<type>'][0])
                setup = zero.setup
                if args['--dbg']:
                    setup.debugging(True)
                for msg in zero:
                    if setup.transmits:
                        zero(msg)
            else:
                raise ValueError('Multiple RPC workers not yet supported.',
                                 args['<type>'])
        else:
            # Something happened...
            raise e
        if setup.args['--wait']:
            raw_input('Press enter when done.')
        zero.close()
Exemplo n.º 3
0
def main():
    import sys
    if len(sys.argv) > 1 and sys.argv[1] == 'test':
        # Running tests, not zeros
        import doctest
        sys.path.insert(0, '..')
        import zero
        import zero.rpc
        fails, tests = doctest.testmod(zero)
        fails2, tests2 = doctest.testmod(zero.rpc)
        tests += tests2
        if fails + fails2:
            msg = 'Completed %d tests, %d failed. Run zero test -v for more information.'
            sys.exit(msg % (tests, fails + fails2))
        print 'Successfully completed %d tests.' % tests
        return

    import json
    from zero import Zero, ZeroSetup, zauto, UnsupportedZmqMethod
    try:
        # Regular zero run
        setup, loop = ZeroSetup.argv()
        zero = Zero(setup)

        for msg in zauto(zero, loop, setup.args['--wait']):
            sys.stdout.write(json.dumps(msg) + '\n')
            sys.stdout.flush()
    except UnsupportedZmqMethod, e:
        args = e.args[2]
        if args['rpc']:
            # Configured RPC not supported by zauto
            from zero.rpc import zrpc
            with open(args['<config>']) as fin:
                config = json.load(fin)
            if len(args['<type>']) == 1:
                zero = zrpc(config, args['<type>'][0])
                setup = zero.setup
                if args['--dbg']:
                    setup.debugging(True)
                for msg in zero:
                    if setup.transmits:
                        zero(msg)
            else:
                raise ValueError('Multiple RPC workers not yet supported.', args['<type>'])
        else:
            # Something happened...
            raise e
        if setup.args['--wait']:
            raw_input('Press enter when done.')
        zero.close()
Exemplo n.º 4
0
import gpiozero as zero
from time import sleep

DELAY = 0.001  #Pulse duration in seconds.
#The number of steps each stepper motor axis moves per inch
X_Constant = 20
Y_Constant = 20
Z_Constant = 20

X_Dir = zero.LED(19)
X_Pulse = zero.LED(22)
Y_Dir = zero.LED(21)
Y_Pulse = zero(24)
Z_Dir = zero.LED(23)
Z_Pulse = zero.LED(26)
Planter_Dir = zero.LED(10)
Planter_Pulse = zero.LED(12)
Planter_Solenoid = zero.LED(16)
Water_Solenoid = zero.LED(7)
SDA = 3
SCL = 5
X_Stop_Low = zero.Button(31)
X_Stop_High = zero.Button(33)
Y_Stop_Low = zero.Button(35)
Y_Stop_High = zero.Button(37)
Z_Stop_Low = zero.Button(36)
Z_Stop_High = zero.Button(38)

def check_if_dry():
    #Use I2C to get water sensor value.
    #Return value < Water_Constant.
Exemplo n.º 5
0
 def listen():
     zero = Zero(ZeroSetup('rep', 8000)).activated(Z())
     for _, msg in izip(range(2), zero):
         zero(msg)
     zero.close()