def startMeasurment(self): # Initialize the Pstat self.cominterface.Open() self.cominterface.SetCell(GamryCOM.CellOn) self.cominterface.SetCtrlMode(GamryCOM.PstatMode) # Initialize a Dtaq dtaqchrono = client.CreateObject('GamryCOM.GamryDtaqChrono') dtaqchrono.Init(self.cominterface, GamryCOM.ChronoAmp) dtaqsink = GamryDtaqEvents(dtaqchrono, self) client.ShowEvents(dtaqchrono) client.GetEvents(dtaqchrono, dtaqsink) # Initialize a two-step wavefrom Signal sigstep = client.CreateObject('GamryCOM.GamrySignalStep') sigstep.Init(self.cominterface, 0.5, 15, -0.1, 15, 0.01, GamryCOM.PstatMode) # Set Signal self.cominterface.SetSignal(sigstep) # Acquire Data try: dtaqchrono.Run(True) except Exception as e: print("Big drama show")
def create_filter(self, moniker): null_context = POINTER(IBindCtx)() null_moniker = POINTER(IMoniker)() ##bind moniker to object self.source = moniker.RemoteBindToObject(null_context, null_moniker, IBaseFilter._iid_) self.filter_graph.AddFilter(self.source, "VideoCapture") self.grabber = client.CreateObject(SampleGrabber) self.filter_graph.AddFilter(self.grabber, "Grabber") self.renderer = client.CreateObject(NullRenderer) self.filter_graph.AddFilter(self.renderer, "Renderer") mt = _AMMediaType() mt.majortype = MEDIATYPE_Video mt.subtype = MEDIASUBTYPE_RGB24 mt.formattype = FORMAT_VideoInfo self.grabber.SetMediaType(mt) self.graph_builder.RenderStream(PIN_CATEGORY_CAPTURE, MEDIATYPE_Video, self.source, self.grabber, self.renderer) self.grabber.SetBufferSamples(False) self.grabber.SetOneShot(False)
def __init__(self, connection_type=synctrl.SE_ConnectionAny, device_type=synctrl.SE_DeviceAny): self._synapi = client.CreateObject("SynCtrl.SynAPICtrl") if self._synapi.Initialize() == synerror.SYNE_FAIL: raise RuntimeError( "The Synaptics kernel-mode driver is not present on " "the target machine, or the installed driver version " "is less than that necessary to support the Synaptics COM API." ) self._syndev = client.CreateObject("SynCtrl.SynDeviceCtrl") self._synpac = client.CreateObject("SynCtrl.SynPacketCtrl") # TODO: catch COMError lHandle = self._synapi.FindDevice(connection_type, device_type, -1) if lHandle < 0: raise RuntimeError("No appropriate device found.") elif lHandle == synerror.SYNE_FAIL: raise RuntimeError( "The ISynAPICtrl object has not been initialized properly.") if self._syndev.Select(lHandle) == synerror.SYNE_HANDLE: raise ValueError( "The requested lHandle does not correspond to any known device." ) self._connection = client.GetEvents(self._syndev, self) if self._syndev.Activate() == synerror.SYNE_FAIL: raise RuntimeError( "The Synaptics kernel-mode driver is not present on the target machine." )
def __init__(self, port, *args, **kwargs): self.lib = com.GetModule("Prior.dll") self.port = port self.controller = com.CreateObject(self.lib.Scan()) self.controller.Connect(self.port) self.zobject = com.CreateObject(self.lib.Z())
def __init__(self, mode="Potentiostat", which_one=0): pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED) self.devices=client.CreateObject('GamryCOM.GamryDeviceList',clsctx=comtypes.CLSCTX_LOCAL_SERVER) # print self.devices.EnumSections() # Unfortunately it is necessary to sleep for 10 seconds after initializing the # device list. Results with-out this sleep are somewhat unpredictable. time.sleep(10) # Another demonstration how immature this ugly interface is programmed self.pstat=client.CreateObject('GamryCOM.GamryPstat',clsctx=comtypes.CLSCTX_LOCAL_SERVER) self.pstat.Init(self.devices.EnumSections()[which_one]) # grab pstat selected time.sleep(10) self.pstat.Open() time.sleep(1) #self.pstat.SetCell(0) # 0=off 1=on #self.pstat.SetCell(GamryCOM.CellOff) #self.pstat.SetCtrlMode(1) # 0=Galvanostat (amp=const), 1=Potentiostat (volts=const), 2=Zero Resistance Ammeter 3=Frequency response analyser self.mode = mode if self.mode == "Potentiostat": self.pstat.SetCtrlMode(GamryCOM.PstatMode) print "Potentiostatic mode selected" elif self.mode == "Galvanostat": self.pstat.SetCtrlMode(GamryCOM.GstatMode) print "Galvanostatic mode selected" #self.pstat.SetStability(GamryCOM.StabilityFast) # 0=Fast 1=medfast 2=norm 3=slow #self.pstat.SetStability(2) # 0=Fast 1=medfast 2=norm 3=slow #self.pstat.SetCASpeed(GamryCOM.CASpeedMedFast) # use medfast ??? self.pstat.SetSenseSpeedMode(1) # TRUE #self.pstat.SetConvention(1) # 0=cathodic 1=anodic self.pstat.SetGround(0) # 0=Float 1=Earth #self.pstat.SetIchRange(3.0) #self.pstat.SetIchRangeMode(0) # False #self.pstat.SetIchFilter(5.0) #self.pstat.SetVchRange(3.0) #self.pstat.SetVchRangeMode(0) # False #self.pstat.SetIchOffsetEnable(1) # True #self.pstat.SetVchOffsetEnable(1) # True #self.pstat.SetVchFilter(5.0) #self.pstat.SetAchRange(3.0) #self.pstat.SetIERangeLowerLimit() # NIL #self.pstat.SetIERange(0.03) #self.pstat.SetIERangeMode(0) # False #self.pstat.SetAnalogOut(0.0) #self.pstat.SetVoltage(0.0) # DCvoltage #self.pstat.SetPosFeedEnable(0) # False time.sleep(1) self.pstat.SetCell(GamryCOM.CellOn) time.sleep(1) self.readz=client.CreateObject('GamryCOM.GamryReadZ',clsctx=comtypes.CLSCTX_LOCAL_SERVER) self.readz.Init(self.pstat) self.readzsink = GamryReadZEvents(self.readz) self.connection = client.GetEvents(self.readz, self.readzsink) self.frequency_values = [] self.wait_time_after_each_measurement = 5 self.cycle_max = 10 self.interrupt = False # Variable which makes it possible to stop a running measurement #self.setup_impedance_measurement() pythoncom.CoUninitialize() # Windows shit return
def regLW(): ''' 注册乐玩插件,需要把文件lw.dll放在根目录 :return: 返回乐玩对象 ''' try: lw = client.CreateObject("lw.lwsoft3") except: os.system('regsvr32 lw.dll') lw = client.CreateObject("lw.lwsoft3") return lw
def __init__(self, name): import comtypes.gen.SKCOMLib as _api if name == 'center': self._component = cc.CreateObject(_api.SKCenterLib, interface=_api.ISKCenterLib) elif name == 'quote': self._component = cc.CreateObject(_api.SKQuoteLib, interface=_api.ISKQuoteLib) elif name == 'order': self._component = cc.CreateObject(_api.SKOrderLib, interface=_api.ISKOrderLib) elif name == 'reply': self._component = cc.CreateObject(_api.SKReplyLib, interface=_api.ISKReplyLib) else: raise ValueError('Invalid parament! [name: %s]' % name)
def __init__(self): ##the queue will contain pointers to the buffer where each frame is stored self.queue = queue.Queue() ##create the filter graph self.filter_graph = client.CreateObject(FilterGraph) ## self.control = self.filter_graph.QueryInterface(IMediaControl) self.graph_builder = client.CreateObject(CaptureGraphBuilder2) self.graph_builder.SetFiltergraph(self.filter_graph) self.show_video_window = True
def __init__(self): threading.Thread.__init__(self) cc.GetModule( os.path.split(os.path.realpath(__file__))[0] + r'\SKCOM.dll') from comtypes.gen import SKCOMLib as sk self.skC = cc.CreateObject(sk.SKCenterLib, interface=sk.ISKCenterLib) self.skQ = cc.CreateObject(sk.SKQuoteLib, interface=sk.ISKQuoteLib) self.EventQ = self.skQ_events(self) self.ConnectionQ = cc.GetEvents(self.skQ, self.EventQ) self.feature_list = [] self.option_list = [] self.feature_code = "" self.option_code = "" self.watchdog = 0
def __init__(self): self.GamryCOM = client.GetModule(setupd["path_to_gamrycom"]) self.devices = client.CreateObject("GamryCOM.GamryDeviceList") # print(devices.EnumSections()) self.pstat = client.CreateObject("GamryCOM.GamryPC6Pstat") # print(devices.EnumSections()) try: self.pstat.Init(self.devices.EnumSections()[0]) # grab first pstat except IndexError: print("No potentiostat is connected! Have you turned it on?") self.temp = []
def BuildGraph(graph, srcFile1): # Add LAV Splitter Source pLAVSplitterSource = client.CreateObject(CLSID_LAVSplitterSource, interface=IBaseFilter) graph.AddFilter(pLAVSplitterSource, 'LAV Splitter Source') # Set source filename pLAVSplitterSource_src = pLAVSplitterSource.QueryInterface( IFileSourceFilter) pLAVSplitterSource_src.Load(srcFile1, None) # Add LAV Video Decoder pLAVVideoDecoder = client.CreateObject(CLSID_LAVVideoDecoder, interface=IBaseFilter) graph.AddFilter(pLAVVideoDecoder, 'LAV Video Decoder') # Add LAV Audio Decoder pLAVAudioDecoder = client.CreateObject(CLSID_LAVAudioDecoder, interface=IBaseFilter) graph.AddFilter(pLAVAudioDecoder, 'LAV Audio Decoder') # Add Video Mixing Renderer pVideoMixingRenderer = client.CreateObject(CLSID_VideoMixingRenderer, interface=IBaseFilter) graph.AddFilter(pVideoMixingRenderer, 'Video Mixing Renderer') # Add DirectSound Audio Renderer pDirectSoundAudioRenderer = client.CreateObject( CLSID_DirectSoundAudioRenderer, interface=IBaseFilter) graph.AddFilter(pDirectSoundAudioRenderer, 'DirectSound Audio Renderer') # Connect LAV Splitter Source and ffdshow Video Decoder graph.ConnectDirect(GetPin(pLAVSplitterSource, 'Video'), GetPin(pLAVVideoDecoder, 'In'), None) # Connect LAV Splitter Source and LAV Audio Decoder graph.ConnectDirect(GetPin(pLAVSplitterSource, 'Audio'), GetPin(pLAVAudioDecoder, 'Input'), None) # Connect ffdshow Video Decoder and Video Mixing Renderer graph.ConnectDirect(GetPin(pLAVVideoDecoder, 'Out'), GetPin(pVideoMixingRenderer, 'VMR Input0'), None) # Connect LAV Audio Decoder and DirectSound Audio Renderer graph.ConnectDirect( GetPin(pLAVAudioDecoder, 'Output'), GetPin(pDirectSoundAudioRenderer, 'Audio Input pin (rendered)'), None)
def connect(self): self.smi = cc.CreateObject('SMIEngine.SMIHost') cc.GetModule('IntegMotorInterface.dll') self.CommInterface = self.smi.QueryInterface( comtypes.gen.INTEGMOTORINTERFACELib.ISMIComm) self.motor_door = None self.establish_link()
def word_to_pdf(path, tmp_path=None): """ Converts all Word docs in `path` to PDF, collected in a temporary folder. If `tmp_path` is provided and it is an existing folder, it must be empty. Otherwise the folder is created. """ if tmp_path is None: tmp_path = os.path.join(path, '.tmp') check_tmp_path(tmp_path) # Use Word itself to 'save as' each file as a PDF via the comtypes library word = client.CreateObject('Word.Application') word.Visible = False filenames = get_files_of_type(path, ('.doc', '.docx')) bar = progressbar.ProgressBar(max_value=len(filenames)) for i, fn in enumerate(filenames): doc = word.Documents.Open(os.path.join(path, fn)) out_fn = '{}.pdf'.format(fn.split('.')[0]) doc.SaveAs(os.path.join(tmp_path, out_fn), FileFormat=COMTYPES_PDF_FORMAT) doc.close() bar.update(i + 1) word.Quit()
def download(self, link, path_to_save=None, output=None, referrer=None, cookie=None, postData=None, user=None, password=None, confirm=False, lflag=None): #print "link =", link #print "referrer =", referrer #print "postData =", postData #print "user ="******"password ="******"path_to_save =", path_to_save #print "output =", output #print "lflag =", lflag if confirm: lflag = 0 else: lflag = 5 try: cc.GetModule(['{ECF21EAB-3AA8-4355-82BE-F777990001DD}', 1, 0]) except: cc.GetModule(self.tlb) import comtypes.gen.IDManLib as idman idman1 = cc.CreateObject(idman.CIDMLinkTransmitter, None, None, idman.ICIDMLinkTransmitter2) if path_to_save: os.path.realpath(path_to_save) idman1.SendLinkToIDM(link, referrer, cookie, postData, user, password, path_to_save, output, lflag)
def SetUpCOMInterface(): DSSobj = cc.CreateObject("OpenDSSEngine.DSS") DSSstart = DSSobj.Start(0) DSStext = DSSobj.Text DSScircuit = DSSobj.ActiveCircuit return DSSobj, DSSstart, DSStext, DSScircuit
def GetOCRByOmniPage(strInput): obj = client.CreateObject(api.Engine) obj.Init() doc = obj.Documents.Add() doc.Deskew = 4 doc.AutoZoning_Form = True doc.AutoZoning_Column = 2 z = doc.LoadImage(strInput) strOutput = os.path.join(os.getcwd(),"output.txt") z.ConvertToDirectTXT(strOutput,0) strOutputXML = os.path.join(os.getcwd(),"Omnipage_XML_Output.xml") z.ConvertToDirectTXT(strOutputXML,4) strText = "" if os.path.exists(strOutput): with open(strOutput,'r') as f: strText = f.readlines() strText = ''.join(strText) # print(strText) os.remove(strOutput) return strText else: print("Output file did not generated by Omnipage.") return ""
def obtain_webcams(self): ##call to refresh available webcams self.webcam_list.clear() self.duplicate_webcam_count.clear() ##create dev_enum device_enumerator = client.CreateObject(CLSID_SystemDeviceEnum, interface=ICreateDevEnum) ##create class enum class_enumerator = device_enumerator.CreateClassEnumerator( CLSID_VideoInputDeviceCategory, 0) ##get moniker from class enum (moniker, fetch) = class_enumerator.RemoteNext(1) while (fetch): ##obtain info about current moniker null_context = POINTER(IBindCtx)() null_moniker = POINTER(IMoniker)() property_bag = moniker.RemoteBindToStorage( null_context, null_moniker, IPropertyBag._iid_).QueryInterface(IPropertyBag) webcam_name = property_bag.Read("FriendlyName", pErrorLog=None) if (webcam_name in self.webcam_list): self.duplicate_webcam_count[webcam_name] += 1 self.webcam_list[webcam_name + " - " + str( self.duplicate_webcam_count[webcam_name])] = moniker else: self.duplicate_webcam_count[webcam_name] = 1 self.webcam_list[webcam_name + " - " + str( self.duplicate_webcam_count[webcam_name])] = moniker (moniker, fetch) = class_enumerator.RemoteNext(1)
def __init__(self): self.buttons = [] self.rotation = None self.translation = None from comtypes import client device = client.CreateObject("TDxInput.Device") devnames = { 6: "Space Navigator", 4: "Space Explorer", 25: "Space Traveler", 29: "Space Pilot" } name = devnames.get(device.Type, 'unknown') status = device.Connect() if status: raise IOError, 'COM Connection to %s device failed.' % name # Setup button listener self.keyboard = device.Keyboard self.kev = client.GetEvents(self.keyboard, self) # Setup sensor listener self.sensor = device.Sensor self.sev = client.GetEvents(self.sensor, self)
def __init__(self, filepath, open_sheet_name=None): self.__mcadapp = CC.CreateObject("MathcadPrime.Application") self.__ws_at_init = {} for i in range(self.__mcadapp.Worksheets.Count): self.__ws_at_init[self.__mcadapp.Worksheets.Item(i).Name] = \ (self.__mcadapp.Worksheets.Item(i).FullName, self.__mcadapp.Worksheets.Item(i)) if open_sheet_name is not None: for n, (path, __mcobj) in self.__ws_at_init.items(): if open_sheet_name == n: self.__mcadapp.Open(path) # Doesn't really open as it is already open # @TODO - change to activate worksheet by same name self.__obj = __mcobj #self.__obj = self.__mcadapp.ActiveWorksheet.Name # Fetches COM worksheet object self.Name = self.__obj.Name break else: print(f"open_sheet_name={open_sheet_name} does not match the name of any open worksheets") if filepath is not None: if os.path.isfile(filepath) and os.path.exists(filepath): try: self.__mcadapp.Open(filepath) # The below method has to be used because ActiveWorksheet # only returns an IMathcadPrimeWorksheet object. This does # Not have all of the required methods for i in range(self.__mcadapp.Worksheets.Count): if self.__mcadapp.Worksheets.Item(i).Name == self.__mcadapp.ActiveWorksheet.Name: self.__obj = self.__mcadapp.Worksheets.Item(i) # Returns IMathcadPrimeWorksheet2 object break except: print(f"Error opening {filepath}")
def sk_init(self): import redis #使用python来操作redis用法详解 https://www.jianshu.com/p/2639549bedc8 导入redis模块,通过python操作redis 也可以直接在redis主机的服务端操作缓存数据库 #cache = redis.Redis(host='localhost', port=6379, decode_responses=True) # host是redis主机,需要redis服务端和客户端都启动 redis默认端口是6379 pool = redis.ConnectionPool(host=self.redis_host, port=6379, decode_responses=True, max_connections=50) self.cache = redis.Redis(connection_pool=pool) self.skC = cc.CreateObject(sk.SKCenterLib, interface=sk.ISKCenterLib) self.skQ = cc.CreateObject(sk.SKQuoteLib, interface=sk.ISKQuoteLib) self.skR = cc.CreateObject(sk.SKReplyLib, interface=sk.ISKReplyLib) #Configuration self.EventQ = self.skQ_events(self) self.EventR = self.skR_events(self) self.ConnectionQ = cc.GetEvents(self.skQ, self.EventQ) self.ConnectionR = cc.GetEvents(self.skR, self.EventR)
def windows_say(msg): try: import comtypes.client as cc # dynamic=True不生成静态的Python代码 voice = cc.CreateObject("SAPI.SpVoice", dynamic=True) voice.Speak(msg) except: pass
def __init__(self, python_name=""): self.__mcadapp = CC.CreateObject("MathcadPrime.Application") for i in range(self.__mcadapp.Worksheets.Count): if self.__mcadapp.Worksheets.Item(i).Name == self.__mcadapp.ActiveWorksheet.Name: self.__ws = self.__mcadapp.Worksheets.Item(i) # Returns IMathcadPrimeWorksheet2 object break self.python_name = python_name # Just for organisation in scripts self.object = None
def __init__(self): # pythoncom.CoInitialize() self.lw = client.CreateObject('lw.lwsoft3') self.hwnd = -1 self.state = 0 self.word_path_num = 0 self.x = -1 self.y = -1
def on_load(self): self.taskbar = client.CreateObject( '{56FDF344-FD6D-11d0-958A-006097C9A090}', interface=ITaskbarList3) ret = self.taskbar.HrInit() if ret != S_OK: logger.warning("taskbar.HrInit failed: %r", ret) del self.taskbar
def doc2pdf(input, output): print(input,output) wdFormatPDF=17 word = client.CreateObject('Word.Application') doc = word.Documents.Open(input) doc.SaveAs(output, FileFormat=wdFormatPDF) doc.Close() word.Quit()
def __init__(self, parent=None): super().__init__(parent) self._reset() self._hwnd = self.winId().__int__() self._system_device_enum = client.CreateObject(CLSID_SystemDeviceEnum, interface=ICreateDevEnum) self._size_factor = self.devicePixelRatio() self._fullscreen = False self._prop_obj_filter = None self._prop_obj_pin = None
def __init__(self, filename): if not os.path.isfile(filename): raise FileNotFoundError self.filename = filename self.app = client.CreateObject('Powerpoint.Application') self.presentation = self.app.Presentations.Open(os.path.abspath( self.filename), ReadOnly=True, WithWindow=False)
def create_instance(self, class_guid, interface_name): """ Create instance of a class with GUID and query interface from it @class_guid - GUID of COM class the instance of which should be created @interface_name - name of the interface to query on object """ com_interface = getattr(self.__generated_module, interface_name) obj = cc.CreateObject(class_guid, interface=com_interface) return obj.QueryInterface(com_interface)
def __init__(self): #Create new ISynAPICtrl control object instance for managing SynComAPI for all devices self._synapi = client.CreateObject("SynCtrl.SynAPICtrl") #Create new ISynDeviceCtrl control object for managing a particular device self._syndev = client.CreateObject("SynCtrl.SynDeviceCtrl") #Create new ISynPacketCtrl control object managing a device's packet data self._synpac = client.CreateObject("SynCtrl.SynPacketCtrl") #Initialize device query handle variable self._dev = None #Initialize device selection flag self._selected = False #Initialize comtypes connection variable self._connection = None
def list_voices(): if sys.platform != 'win32': return [] try: voice = cc.CreateObject('SAPI.SpVoice') return [v.GetDescription() for v in voice.GetVoices()] except Exception: logging.exception('Failed to retrieve voices!') return []