Exemplo n.º 1
0
    def __init__(self, **kwargs):
        super(NewFocus6700, self).__init__()
        # Load usb ddl Newport
        try:
            # dllpath = 'C:\\ProgramData\\Anaconda3\\DLLs\\'
            # dllpath = 'C:\\Users\\Greg\\Anaconda3\\DLLs\\'
            dllpath = 'C:\\ProgramData\\Anaconda3\\DLLs\\'
            Assembly.LoadFile(dllpath + 'UsbDllWrap.dll')
            clr.AddReference(r'UsbDllWrap')
            import Newport
            self._dev = Newport.USBComm.USB()

        except Exception as err:
            print(err)
            self._dev = None
        # Laser state
        self._open = False
        self._DeviceKey = kwargs.get('key', None)
        self._idLaser = kwargs.get('id', 4106)
        # Laser properties
        self._lbd = '0'
        self._cc = 0
        self._scan_lim = []
        self._scan_speed = 0
        self._scan = 0
        self._beep = 0
        self._output = 0
        self._is_scaning = False
        # self._is_changing_lbd = False
        self._no_error = '0,"NO ERROR"'
        self._haserr = False
        # Miscs
        self._buff = StringBuilder(64)
        self._err_msg = ''
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#https://github.com/stevehv/pythonnet_release_opened_dll

import clr
from System.Reflection import Assembly
Assembly.LoadFile(
    "C:/Users/gastrodia/source/repos/ClassLibrary1/ClassLibrary1/bin/Debug/ClassLibrary1.dll"
)

from ClassLibrary1 import *


def main():
    print(Class1.Add(1, 1))


if __name__ == '__main__':
    main()
Exemplo n.º 3
0
import logging
import os
import sys
from settings import PACKAGE_ROOT

#------------------------------------------------------------------------------
# prepare environment for loading latino (Python.net interpreter should be used)
# see: http://pythonnet.sourceforge.net/
#------------------------------------------------------------------------------

dllPath = os.path.join(PACKAGE_ROOT, 'bin')
sys.path.append(dllPath)

try:
    import clr
    import System
    import LemmaSharp
    from LemmaSharpInterfaces import *

    from System.Reflection import Assembly
    Assembly.LoadFile(os.path.join(dllPath, 'LemmaSharpPrebuilt.dll'))
except Exception:
    logging.warning(
        "DotNet assemblies could not be loaded! Probable reasons: missing dlls or wrong interpreter (see http://pythonnet.sourceforge.net). "
        "Other functionality of ClowdFlows (besides .Net assemblies) should be OK!"
    )
    pass
Exemplo n.º 4
0
import clr

SYSTEM_REFERENCES = [
    "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
    "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
    "System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
    "System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    "System.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
    "System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
]

CUSTOM_REFERENCES = [
    "Syncfusion.Xlsio.Base",
]

for reference in SYSTEM_REFERENCES:
    clr.AddReferenceByName(reference)

from System.Diagnostics import Process
from System.IO import Path
from System.Reflection import Assembly
module = Process.GetCurrentProcess().MainModule
binDir = Path.GetDirectoryName(module.FileName)

for reference in CUSTOM_REFERENCES:
    assemblyPath = "%s\\%s.dll" % (binDir, reference)
    assembly = Assembly.LoadFile(assemblyPath)
    clr.AddReference(assembly)
Exemplo n.º 5
0
#!/usr/bin/env python3

import clr
import os
import os.path
from System.Reflection import Assembly
from System.Reflection import BindingFlags
import System
from System.Text import Encoding
from System import Type

hota = Assembly.LoadFile(os.getcwd() + "/tools/HotA editor.exe")
hdat = hota.GetType("HotA_editor.Hdat")

hdata = System.Activator.CreateInstance(hdat)
t = hdata.GetType()
mi = t.GetMethod("ReadFile", BindingFlags.Instance | BindingFlags.NonPublic)
r = mi.Invoke(
    hdata, ["homm3_files/HotA/HotA.dat",
            Encoding.GetEncoding("windows-1250")])

for item in r.Items:
    if not os.path.exists("_tmp/HotA_txt/" + item.Name):
        os.makedirs("_tmp/HotA_txt/" + item.Name)
    if item.Data1 != "":
        with open(os.path.join("_tmp/HotA_txt/" + item.Name, "data1.txt"),
                  'w+b') as the_file:
            the_file.write(str.encode(item.Data1, encoding='cp1250'))
    if item.Data2 != "":
        with open(os.path.join("_tmp/HotA_txt/" + item.Name, "data2.txt"),
                  'w+b') as the_file:
Exemplo n.º 6
0
import clr
import os
from os import path
from System.Reflection import Assembly

# Tried loading csharp_library using reflection as recommended as a workaround
# https://github.com/pythonnet/pythonnet/issues/513#issuecomment-316180382
if __name__ == '__main__':
    # Load charp_library.dll using reflection
    # https://stackoverflow.com/a/6365969
    dll_abs_path = path.join(path.dirname(path.abspath(__file__)),
                             "csharp_library.dll")
    dll1 = Assembly.LoadFile(dll_abs_path)

    # Call charp_library.dll
    print(clr.MyNamespace.MyClass().MyFunction()
          )  # AttributeError: module 'clr' has no attribute 'MyNamespace'

    # Release charp_library.dll
    # Don't yet know how to do this, I'd first need to get load working

    # Confirm that dll has been released
    os.remove("charp_library.dll")
Exemplo n.º 7
0
def build_documentation(dll_path, hierarchy):
    log.info("Building documentation")
    dll_file = FileInfo(dll_path)
    assembly = Assembly.LoadFile(dll_file.FullName)
    # Iterate through all namespaces
    # Each namespace is a folder, each class is a file
    # Also builds a YAML index
    index = []
    for namespace, members in hierarchy.items():
        index_files = []
        for member, content in members.items():
            filename = "{}.md".format(
                (namespace + '/' + member).replace('.', '/'))
            file_path = os.path.join(output_dir, filename)
            # Ensure intermediary directories exist
            os.makedirs(os.path.dirname(file_path), exist_ok=True)
            with open(file_path, "w") as file:
                log.debug("Building %s", file.name)
                index_files.append({member: filename})
                member_type = assembly.GetType("{}.{}".format(
                    namespace, member))
                object_type = "Class"
                if member_type is None:
                    member_type = assembly.GetType("{}+{}".format(
                        namespace, member))
                    object_type = "Delegate"
                if member_type.IsEnum:
                    object_type = "Enum"
                # Check if member inherits other members:
                base_type = member_type.BaseType
                if base_type is not None:
                    file.write("**Inherits**  \n{}\n".format(
                        get_link(assembly,
                                 cs_type=base_type,
                                 current_file=file_path)))
                file.write("# {} {}\n".format(object_type, member))
                file.write("{}\n".format(
                    parse_content(
                        assembly,
                        content.get('documentation',
                                    collections.OrderedDict()).get('summary'),
                        current_file=file_path)))
                _temp = collections.OrderedDict()
                # Enums are represented differently
                if object_type == "Enum":
                    rows = []
                    for field, subcontent in content["children"].items():
                        documentation = subcontent["documentation"]
                        rows.append([field, documentation.get("summary", "")])
                    enum_table = build_table(["Field", "Description"], rows)
                    file.write(enum_table)
                    continue
                if object_type == "Delegate":
                    file.write(
                        parse_delegate(
                            member_type,
                            content.get('documentation',
                                        collections.OrderedDict()), file_path))
                    continue
                for name, subcontent in content['children'].items():
                    if "documentation" not in subcontent:
                        continue
                    documentation = subcontent["documentation"]
                    if subcontent["type"] == "C":
                        if "constructors" not in _temp:
                            _temp['constructors'] = []
                        _temp["constructors"].append(
                            parse_constructor(member_type, name, documentation,
                                              file_path))

                    if subcontent["type"] == "F":
                        if "fields" not in _temp:
                            _temp["fields"] = []
                        _temp["fields"].append(
                            parse_field(member_type, name, documentation,
                                        file_path))

                    if subcontent["type"] == "P":
                        if "properties" not in _temp:
                            _temp["properties"] = []
                        _temp["properties"].append(
                            parse_property(member_type, name, documentation,
                                           file_path))

                    if subcontent["type"] == "M":
                        if "methods" not in _temp:
                            _temp["methods"] = []
                        _temp["methods"].append(
                            parse_method(member_type, name, documentation,
                                         file_path))

                    if subcontent["type"] == "E":
                        if "events" not in _temp:
                            _temp["events"] = []
                        _temp["events"].append(
                            parse_event(member_type, name, documentation,
                                        file_path))

                if "constructors" in _temp:
                    file.write("## Constructors\n----\n")
                    file.write("\n".join(_temp["constructors"]))

                if "fields" in _temp:
                    file.write("## Fields\n----\n")
                    file.write("\n".join(_temp["fields"]))

                if "properties" in _temp:
                    file.write("## Properties\n----\n")
                    file.write("\n".join(_temp["properties"]))

                if "methods" in _temp:
                    file.write("## Methods\n----\n")
                    file.write("\n".join(_temp["methods"]))

                if "events" in _temp:
                    file.write("## Events\n----\n")
                    file.write("\n".join(_temp["events"]))
        index.append({namespace: index_files})

    with open(os.path.join(output_dir, "index.yml"), 'w') as yamlfile:
        yaml.dump(index, yamlfile, default_flow_style=False)
        log.info("Generated index file: %s", yamlfile.name)
Exemplo n.º 8
0
import clr



from System.Windows.Forms import Form,Application
import os
from System.IO import File #For saving to files

import time

import numpy as np
from System.Reflection import Assembly

cp = os.getcwd()
Assembly.LoadFile(cp + '\\UsbCoreFsm100.dll') 
Assembly.LoadFile(cp + '\\UsbFsm100Server.dll') 

#need to reimport clr to update the assemblies...
import clr


class ZLZRDanger(Exception):
     def __init__(self, value):
         self.value = value
     def __str__(self):
         return repr(self.value)

ACK = 0o6
class Splicer():
    def __init__(self):
Exemplo n.º 9
0
    raise ImportError(
        "If you're running CPython, you don't need ironclad. If you're running Jython, ironclad won't work."
    )

import os
_dirname = os.path.dirname(__file__)

import clr
from System import GC, Int32, IntPtr
from System.Reflection import Assembly
from System.Runtime.InteropServices import Marshal

if Marshal.SizeOf(Int32) != Marshal.SizeOf(IntPtr):
    raise ImportError("Ironclad is currently 32-bit only")

clr.AddReference(Assembly.LoadFile(os.path.join(_dirname, "ironclad.dll")))
from Ironclad import CPyMarshal, PythonMapper
from Ironclad.Structs import PyObject, PyVarObject, PyTypeObject
_mapper = PythonMapper(os.path.join(_dirname, "python26.dll"))


def gcwait():
    """
    Attempt to force a garbage collection, and wait for pending finalizers.
    
    If you think you need to call this function, you're probably wrong.
    """
    for _ in range(4):
        _mapper.DemandCleanup()
        GC.Collect()
        GC.WaitForPendingFinalizers()