def do_read(self, args):
        """read <addr> <objid> <prop> [ <indx> ]"""
        args = args.split()
        if _debug: ReadPropertyConsoleCmd._debug("do_read %r", args)

        try:
            addr, obj_id, prop_id = args[:3]
            obj_id = ObjectIdentifier(obj_id).value

            datatype = get_datatype(obj_id[0], prop_id)
            if not datatype:
                raise ValueError("invalid property for object type")

            # build a request
            request = ReadPropertyRequest(
                objectIdentifier=obj_id,
                propertyIdentifier=prop_id,
                )
            request.pduDestination = Address(addr)

            if len(args) == 4:
                request.propertyArrayIndex = int(args[3])
            if _debug: ReadPropertyConsoleCmd._debug("    - request: %r", request)

            # make an IOCB
            iocb = IOCB(request)
            if _debug: ReadPropertyConsoleCmd._debug("    - iocb: %r", iocb)

            # give it to the application
            deferred(this_application.request_io, iocb)

            # wait for it to complete
            iocb.wait()

            # do something for success
            if iocb.ioResponse:
                apdu = iocb.ioResponse

                # should be an ack
                if not isinstance(apdu, ReadPropertyACK):
                    if _debug: ReadPropertyConsoleCmd._debug("    - not an ack")
                    return

                # find the datatype
                datatype = get_datatype(apdu.objectIdentifier[0], apdu.propertyIdentifier)
                if _debug: ReadPropertyConsoleCmd._debug("    - datatype: %r", datatype)
                if not datatype:
                    raise TypeError("unknown datatype")

                # special case for array parts, others are managed by cast_out
                if issubclass(datatype, Array) and (apdu.propertyArrayIndex is not None):
                    if apdu.propertyArrayIndex == 0:
                        value = apdu.propertyValue.cast_out(Unsigned)
                    else:
                        value = apdu.propertyValue.cast_out(datatype.subtype)
                else:
                    value = apdu.propertyValue.cast_out(datatype)
                if _debug: ReadPropertyConsoleCmd._debug("    - value: %r", value)

                sys.stdout.write(str(value) + '\n')
                if hasattr(value, 'debug_contents'):
                    value.debug_contents(file=sys.stdout)
                sys.stdout.flush()

            # do something for error/reject/abort
            if iocb.ioError:
                sys.stdout.write(str(iocb.ioError) + '\n')

        except Exception, error:
            ReadPropertyConsoleCmd._exception("exception: %r", error)
def do_read ( self , args ) : args = args . split ( ) if _debug : ReadPropertyConsoleCmd . _debug ( "do_read %r" , args ) try : addr , obj_id , prop_id = args [ : 3 ] obj_id = ObjectIdentifier ( obj_id ) . value datatype = get_datatype ( obj_id [ 0 ] , prop_id ) if not datatype : raise ValueError ( "invalid property for object type" ) request = ReadPropertyRequest ( objectIdentifier = obj_id , propertyIdentifier = prop_id , ) request . pduDestination = Address ( addr ) if len ( args ) == 4 : request . propertyArrayIndex = int ( args [ 3 ] ) if _debug : ReadPropertyConsoleCmd . _debug ( "    - request: %r" , request ) iocb = IOCB ( request ) if _debug : ReadPropertyConsoleCmd . _debug ( "    - iocb: %r" , iocb ) deferred ( this_application . request_io , iocb ) iocb . wait ( ) if iocb . ioResponse : apdu = iocb . ioResponse if not isinstance ( apdu , ReadPropertyACK ) : if _debug : ReadPropertyConsoleCmd . _debug ( "    - not an ack" ) return datatype = get_datatype ( apdu . objectIdentifier [ 0 ] , apdu . propertyIdentifier ) if _debug : ReadPropertyConsoleCmd . _debug ( "    - datatype: %r" , datatype ) if not datatype : raise TypeError ( "unknown datatype" ) if issubclass ( datatype , Array ) and ( apdu . propertyArrayIndex is not None ) : if apdu . propertyArrayIndex == 0 : value = apdu . propertyValue . cast_out ( Unsigned ) else : value = apdu . propertyValue . cast_out ( datatype . subtype ) else : value = apdu . propertyValue . cast_out ( datatype ) if _debug : ReadPropertyConsoleCmd . _debug ( "    - value: %r" , value ) sys . stdout . write ( str ( value ) + '\n' ) if hasattr ( value , 'debug_contents' ) : value . debug_contents ( file = sys . stdout ) sys . stdout . flush ( ) if iocb . ioError : sys . stdout . write ( str ( iocb . ioError ) + '\n' ) except Exception , error : ReadPropertyConsoleCmd . _exception ( "exception: %r" , error )
read <addr> <objid> <prop> [ <indx> ]