#!/usr/bin/python
#
# arch-tag: test the state of a digital I/O line
# Time-stamp: <2004-09-14 19:24:15 mike>
#
"""Test the state of a digital I/O line

Usage:  ioptest.py board:channel:bit

    board - board number (0-3)
    port  - port name (A, B, or C)
    bit   - bit number (0-7)
      
Outputs 1 for a high state and 0 for a low state.

"""
import sys
from pmacs import NPCData, npc

try:
    board,port,bit = sys.argv[1].split(':')
except:
    print __doc__
    sys.exit(1)

# Convert port name to index (0-2)
port = ord(port.upper()) - ord('A')

byte,elem = NPCData.dio_offset([int(board), port])
npc = npc.NPC(host='bitsy.apl.washington.edu')
rec = npc.getSample()
state = (rec[elem] >> int(bit)) & 1
print state

sys.exit(state^1)
