Beispiel #1
0
# initialized, so in the Python they must be running as root when the
# parapin.Port object is created (otherwise, parapin.ParapinError
# exception will be raised). If you provide the uid argument, root
# privileges will be dropped to that user id after initialization.

# inmode and outmode arguments may be provided for convenience, so you
# don't have to call port.set_output_mode or port.set_input_mode later.

# Pin type signature is Pin(i), the i argument is the pin value to be
# used. The objects have access to all parapin functions (Pin.set,
# Pin.clear, Pin.change, Pin.is_set), the pulse function, lshift and
# rshift functions (described later) and support binary bitwise
# operators like & (and), | (or) and ^ (xor).

# So... first, create a Port object.
port = parapin.Port(LPT1, outmode=LP_DATA_PINS)

# You may also set input and output mode using port.set_output_mode()
# and port.set_input_mode() methods

# You have four options to Pin objects creation.

# 1. Calling the Pin class (not recommended):
pin_2 = parapin.Pin(LP_PIN02)
print "Seting pin 2"
pin_2.set()
raw_input("Hit return...\n")
print "Clearing pin 2"
pin_2.clear()
raw_input("Hit return...\n")
Beispiel #2
0
 def setUp(self):
     self.port = parapin.Port(0x378)
     self.port.set_output_mode(LP_DATA_PINS)
Beispiel #3
0
 def test_init_with_arguments(self):
     port = parapin.Port(0x378)
     self.assertEqual(port.base, 0x378)
     self.assertEqual(os.getuid(), 0)
Beispiel #4
0
 def setUp(self):
     self.port = parapin.Port(0x378, outmode=LP_DATA_PINS)
Beispiel #5
0
        pins234 = self.port.get_pin(2, 3, 4)
        self.assertEqual(pins234.pin, LP_PIN02 | LP_PIN03 | LP_PIN04)

    def test_port_get_item(self):
        for i in xrange(1, 26):
            pin = self.port[i]
            self.assertEqual(pin.pin, LP_PIN[i])
            if i < 18:
                self.assertEqual(pin.pin, eval("LP_PIN%02i" % i))

    def test_port_get_tuple(self):
        pin5, pin6, pin7 = self.port[5:8]
        self.assertEqual(pin5.pin, LP_PIN05)
        self.assertEqual(pin6.pin, LP_PIN06)
        self.assertEqual(pin7.pin, LP_PIN07)


class TestPortWithOutputMode(TestPort):
    def setUp(self):
        self.port = parapin.Port(0x378, outmode=LP_DATA_PINS)


if __name__ == '__main__':
    try:
        unittest.main()
    finally:
        port = parapin.Port(0x378, 1000)
        assert os.getuid() == 1000

        print gc.garbage