Пример #1
0
def type_string(topic):
    """ Returns a platform-dependent string of the type of a particular 'topic'

  topic: string representing a TOS data field('LAST','ASK', etc)
  """
    tystr = _BUF_(MAX_STR_SZ + 1)

    _lib_call("TOSDB_GetTypeString",
              topic.upper().encode("ascii"), tystr, (MAX_STR_SZ + 1))

    return tystr.value.decode()


####################
_on_exit(clean_up)  #
####################


class TOSDB_DataBlock(_TOSDB_DataBlock):
    """ The main object for storing TOS data.    

  size: how much historical data to save
  date_time: should block include date-time stamp with each data-point?
  timeout: how long to wait for responses from TOS-DDE server 

  Please review the attached README.html for details.
  """
    def __init__(self, size=1000, date_time=False, timeout=DEF_TIMEOUT):
        self._name = (_uuid4().hex).encode("ascii")
        self._valid = False
Пример #2
0
       
def clean_up():
    """ Clean up shared resources. ! CALL BEFORE EXITING INTERPRETER ! """
    global _dll, _dll_depend1
    if _dll is not None:       
        err = _lib_call("TOSDB_CloseBlocks", error_check=False)
        print("+ Closing Blocks" if not err else "- Error Closing Blocks")        
        _lib_call("TOSDB_Disconnect", error_check=False)
        print("+ Disconnecting From Service \ Engine")
        print("+ Closing Module(s) ", _dll._name)
        print("                    ", _dll_depend1._name)
        _dll = None
        _dll_depend1 = None
   
 
_on_exit(clean_up)  # try automatically on exit (NO GUARANTEE)


@_contextmanager
def Init(dllpath=None, root="C:\\", bypass_check=False):
    try:
        if not init(dllpath, root, bypass_check):
            raise TODB_InitError("failed to initilize library")
        if not connected():      
            if not connect(): # try again
                raise TODB_InitError("failed to connect to library")
        yield
    finally:
        clean_up()

Пример #3
0
                
def clean_up():
    """ Clean up shared resources. ! CALL BEFORE EXITING INTERPRETER ! """
    global _dll
    if _dll is not None:       
        if _lib_call( "TOSDB_CloseBlocks" ):
            print("- Error Closing Blocks")
        else:
            print("+ Closing Blocks")
        _lib_call( "TOSDB_Disconnect" )
        print("+ Disconnecting From Service \ Engine")        
        print( "+ Closing Module ", _dll._name )
        del _dll
        _dll = None

_on_exit( clean_up )
    
###
### all this stuff can be wrapped with 'virtual' calls
def get_block_limit():
    """ Returns the block limit of C/C++ RawDataBlock factory """
    return _lib_call( "TOSDB_GetBlockLimit", ret_type =_ulong_ )

def set_block_limit( new_limit ):
    """ Changes the block limit of C/C++ RawDataBlock factory """
    _lib_call( "TOSDB_SetBlockLimit", new_limit, ret_type = _ulong_ )

def get_block_count():
    """ Returns the count of current instantiated blocks """
    return _lib_call( "TOSDB_GetBlockCount", ret_type = _ulong_ )
Пример #4
0
    throws TOSDB_CLibError
           **does not raise an exception if lib call returns error code
    """
    global _dll, _dll_depend1
    if _dll is not None:
        err = _lib_call("TOSDB_CloseBlocks", error_check=False)
        print("+ Closing Blocks" if not err else "- Error Closing Blocks")
        _lib_call("TOSDB_Disconnect", error_check=False)
        print("+ Disconnecting From Service \ Engine")
        print("+ Closing Module(s) ", _dll._name)
        print("                    ", _dll_depend1._name)
        _dll = None
        _dll_depend1 = None


_on_exit(clean_up)  # try automatically on exit (NO GUARANTEE)


@_contextmanager
def Init(dllpath=None, root="C:\\"):
    """ Manage a 'session' with the C lib, engine, and TOS platform.

    The context manager handles initialization of the library and tries to
    connect to the engine and TOS platform. On exiting the context block it
    automatically cleans up.

    with Init(...):
        # (automatically initializes, connects etc.)
        # use admin interface, create data blocks etc.
        # (automatically cleans up, closes etc.)
Пример #5
0
def clean_up():
    """ Clean up shared resources. ! CALL BEFORE EXITING INTERPRETER ! """
    global _dll
    if _dll is not None:
        if _lib_call("TOSDB_CloseBlocks"):
            print("- Error Closing Blocks")
        else:
            print("+ Closing Blocks")
        _lib_call("TOSDB_Disconnect")
        print("+ Disconnecting From Service \ Engine")
        print("+ Closing Module ", _dll._name)
        del _dll
        _dll = None


_on_exit(clean_up)


###
### all this stuff can be wrapped with 'virtual' calls
def get_block_limit():
    """ Returns the block limit of C/C++ RawDataBlock factory """
    return _lib_call("TOSDB_GetBlockLimit", ret_type=_ulong_)


def set_block_limit(new_limit):
    """ Changes the block limit of C/C++ RawDataBlock factory """
    _lib_call("TOSDB_SetBlockLimit", new_limit, ret_type=_ulong_)


def get_block_count():