示例#1
0
    def __imports__(self):
        """ DotNetDevice loads the DLL; importing in the
            class definition tries to load a lot of DLLs
            on import
            of ssmdevices, which would 1) break platforms
            that do not support the DLL, and 2) waste
            memory, and 3)
        """

        if hasattr(self.__class__, '__dll__') and not hasattr(self, 'dll'):
            self.dll = self.__class__.__dll__
            return

        if self.dll_name is None:
            raise Exception('Need file name of a dll binary')
        if self.library is None:
            raise Exception(
                'Need the python module that shares the library path')
        try:
            import clr
        except ImportError as err:
            if str(err) == 'No module named clr':
                warnings.warn(
                    'could not import pythonnet support via clr module; no support for .NET drivers'
                )
                return None
            else:
                raise err

        import os
        clr.setPreload(False)
        # CPython and .NET libraries: Are they friends?
        clr.AddReference('System.Reflection')
        from System.Reflection import Assembly
        import System

        #        if libname is None:
        libname = os.path.splitext(os.path.basename(self.dll_name))[0]

        if hasattr(self.library, '__loader__'):
            """ If the python module is packaged as a .egg file,
                then use some introspection and the module's
                __loader__ to load the contents of the dll
            """
            #            relpath = module.__name__.replace('.', os.path.sep)
            self.dll_name = os.path.join(self.library.__path__[0],
                                         self.dll_name)
            contents = self.library.__loader__.get_data(self.dll_name)
        else:
            path = os.path.join(self.library.__path__[0], self.dll_name)
            with open(path, 'rb') as f:
                contents = f.read()

        name = System.Array[System.Byte](contents)
        self._dlls[self.dll_name] = Assembly.Load(name)
        self.dll = __import__(libname)
        try:
            self.__class__.__dll__ = self.dll
        except AttributeError:  # Race condition =/
            pass
示例#2
0
    def testPreloadVar(self):
        import clr
        self.assertTrue(clr.getPreload() is False, clr.getPreload())
        clr.setPreload(False)
        self.assertTrue(clr.getPreload() is False, clr.getPreload())
        try:
            clr.setPreload(True)
            self.assertTrue(clr.getPreload() is True, clr.getPreload())
            clr.setPreload(0)
            self.assertTrue(clr.getPreload() is False, clr.getPreload())
            clr.setPreload(1)
            self.assertTrue(clr.getPreload() is True, clr.getPreload())

            import System.Configuration
            content = dir(System.Configuration)
            self.assertTrue(len(content) > 10, content)
        finally:
            clr.setPreload(False)
示例#3
0
def test_preload_var():
    import clr
    assert clr.getPreload() is False, clr.getPreload()
    clr.setPreload(False)
    assert clr.getPreload() is False, clr.getPreload()
    try:
        clr.setPreload(True)
        assert clr.getPreload() is True, clr.getPreload()
        clr.setPreload(0)
        assert clr.getPreload() is False, clr.getPreload()
        clr.setPreload(1)
        assert clr.getPreload() is True, clr.getPreload()

        import System.Configuration
        content = dir(System.Configuration)
        assert len(content) > 10, content
    finally:
        clr.setPreload(False)
示例#4
0
    def testPreloadVar(self):
        import clr
        self.failUnless(clr.getPreload() is False, clr.getPreload())
	clr.setPreload(False)
	self.failUnless(clr.getPreload() is False, clr.getPreload())
        try:
            clr.setPreload(True)
            self.failUnless(clr.getPreload() is True, clr.getPreload())
            clr.setPreload(0)
            self.failUnless(clr.getPreload() is False, clr.getPreload())
            clr.setPreload(1)
            self.failUnless(clr.getPreload() is True, clr.getPreload())
            
            import System.Configuration
            content = dir(System.Configuration)
            self.failUnless(len(content) > 10, content)
        finally:
            clr.setPreload(False)
示例#5
0
    def test_preload_var(self):
        import clr
        self.assertTrue(clr.getPreload() is False, clr.getPreload())
        clr.setPreload(False)
        self.assertTrue(clr.getPreload() is False, clr.getPreload())
        try:
            clr.setPreload(True)
            self.assertTrue(clr.getPreload() is True, clr.getPreload())
            clr.setPreload(0)
            self.assertTrue(clr.getPreload() is False, clr.getPreload())
            clr.setPreload(1)
            self.assertTrue(clr.getPreload() is True, clr.getPreload())

            import System.Configuration
            content = dir(System.Configuration)
            self.assertTrue(len(content) > 10, content)
        finally:
            clr.setPreload(False)
示例#6
0
def test_preload_var():
    import clr
    assert clr.getPreload() is False, clr.getPreload()
    clr.setPreload(False)
    assert clr.getPreload() is False, clr.getPreload()
    try:
        clr.setPreload(True)
        assert clr.getPreload() is True, clr.getPreload()
        clr.setPreload(0)
        assert clr.getPreload() is False, clr.getPreload()
        clr.setPreload(1)
        assert clr.getPreload() is True, clr.getPreload()

        import System.Configuration
        content = dir(System.Configuration)
        assert len(content) > 10, content
    finally:
        clr.setPreload(False)
示例#7
0
文件: patch.py 项目: sho7noka/Unison
def AddReferenceFrom(dll):
    """
    フルパスからlibを直接Reference
    戻値にモジュールを返す
    .NET AddReferenceToFileAndPath 互換

    Args:
        dll: マネージコードのパス

    Returns:
        object: 
        System, ManageCode モジュール

    >>> import clr_ext as clr
    >>> clr.AddReferenceFrom("assembly.dll")
    """

    # unity helper
    if dll.startswith("Asset"):
        _clr.AddReference("UnityEditor")
        import UnityEditor
        path = UnityEditor.AssetDatabase.GetAssetPath(dll)
        dll = System.IO.Path.GetFullPath(path)

    _clr.setPreload(True)
    _clr.AddReference("System")
    import System

    if os.path.exists(dll):
        dir_name = os.path.dirname(dll)
        sys.path.append(dir_name)

    if dll.endswith(".dll"):
        asm = os.path.basename(dll).split(".")[0]
        _clr.AddReference(asm)
        ref = System.Reflection.Assembly.LoadFile(dll)
        name_space = ref.GetTypes()[0].ToString().split(".")[0]

    try:
        Client = __import__(name_space)
    except ModuleNotFoundError:
        Client = None

    return System, Client
示例#8
0
MC.SetParamStr(channel, 'Connector', connector)
MC.SetParamStr(channel, 'CamFile', camFile)
MC.SetParamInt(channel, 'SeqLength_Fr', 1)  #Edit this

MC.SetParamStr(channel, MC.SignalEnable + MC.SIG_SURFACE_PROCESSING, 'ON')
MC.SetParamStr(channel, MC.SignalEnable + MC.SIG_ACQUISITION_FAILURE, 'ON')
MC.SetParamStr(channel, MC.SignalEnable + MC.SIG_END_CHANNEL_ACTIVITY, 'ON')

planeIndex = 0
MC.SetParamStr(channel, 'ChannelState', 'READY')

##########
#Initiate control of ESP301 (Focusing stage)
import clr
# Add reference to assembly and import names from namespace
clr.setPreload(True)
clr.AddReference(
    r'C:/Program Files (x86)/Newport/MotionControl/ESP301/Bin/Newport.ESP301.CommandInterface.dll'
)

from CommandInterfaceESP301 import *
import System
#=====================================================================
# Instrument Initialization
# The key should have double slashes since
# (one of them is escape character)
num_focal_steps = 5  #This is doubled, forward and reverse
step_increment = .1  #how big is your focal hop
dummy_string = "string dummy"
float_dummy = .01
stage_axis = 1