def initCom(self): tid = str(threading.get_ident()) #if self.xlApplication == None: if tid in self.comObjects: pass else: pythoncom.CoInitialize() xlApplication = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream( self.thread_xlApplication, pythoncom.IID_IDispatch)) xlWorkbooks = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream( self.thread_xlWorkbooks, pythoncom.IID_IDispatch)) xlWorkbook = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream( self.thread_xlWorkbook, pythoncom.IID_IDispatch)) xlWorksheets = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream( self.thread_xlWorksheets, pythoncom.IID_IDispatch)) xlWorksheet = {} self.setSheet(xlWorksheets, xlWorksheet) self.comObjects[tid] = ExcelComObject(xlApplication, xlWorkbooks, xlWorkbook, xlWorksheets, xlWorksheet)
def initCom(self): if self.ptApplication == None: pythoncom.CoInitialize() self.ptApplication = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream( self.thread_ptApplication, pythoncom.IID_IDispatch)) self.ptPresentations = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream( self.thread_ptPresentations, pythoncom.IID_IDispatch)) self.ptPresentation = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream( self.thread_ptPresentation, pythoncom.IID_IDispatch))
def get_de06_response_from_75C(id, q, gui_queue): pythoncom.CoInitialize() app = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(id, pythoncom.IID_IDispatch)) tmp_list = [] prev_time = time.time() temp_time = prev_time tmp = 0 while True: time.sleep(0.01) c_75c = app.Bus.GetSignal(2, "TesterPhysicalResTCU4", "TesterPhysicalResTCU").RawValue if tmp != c_75c: tmp = c_75c tmp_list.append(c_75c) curr_time = time.time() delta_time, prev_time = curr_time - prev_time, curr_time gui_queue.put( "Get response from 0x75C after setting DE06: " + str(help_utils.decode_raw_signal_value_helper(c_75c))) if help_utils.decode_raw_signal_value_helper( c_75c) == "036ede0600000000L": gui_queue.put("Find positive response after setting DE06") break if time.time( ) - temp_time > 15: # after 15s, force it break since 754 should be sent already. break decode_75c = help_utils.decode_raw_signal_values(tmp_list) print "decodedddddd: ", decode_75c q.put(decode_75c) pythoncom.CoUninitialize()
def open_doc_thread(app_id, fname): pythoncom.CoInitialize() app = win32.Dispatch(pythoncom.CoGetInterfaceAndReleaseStream(app_id, pythoncom.IID_IDispatch)) doc = app.Documents.Open(fname, PasswordDocument='wrong password', ReadOnly=True) doc.Activate() doc_id = pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch, doc) return doc_id
def __init__(self, event_thread, can_logs=None, delta_flag=False, app_id=None): # app = win32com.client.DispatchEx('CANalyzer.Application') pythoncom.CoInitialize() self.app = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(app_id, pythoncom.IID_IDispatch)) self.Measurement = self.app.Measurement self.Running = lambda: self.Measurement.Running self.event = event_thread self.can_logs = can_logs # It's a list self.delta_flag = delta_flag self.marshalled_app_id = pythoncom.CoMarshalInterThreadInterfaceInStream( pythoncom.IID_IDispatch, self.app) # Used to call MeasEvent to call CAPL function, but time.sleep() will cause CANalyzer stuck # Besides, it has to be called before CANalyzer start? self.__MeasurementEvents = win32com.client.DispatchWithEvents( self.Measurement, MeasEvents) print self.__MeasurementEvents # transfer the application object to Event class for CAPL handling print 'which is first' self.__MeasurementEvents.Appl = self.app
def test_can_thread(self, id): pythoncom.CoInitialize() self.app = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(id, pythoncom.IID_IDispatch)) print 'nothing happend' self.app.Measurement.Start()
def run(self): # ptvsd.debug_this_thread() # initialize pythoncom.CoInitialize() # get instance from id aspen_con = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(self._aspen_id, pythoncom.IID_IDispatch)) inp_data = self._app_data.input_table_data out_data = self._app_data.output_table_data input_vars = inp_data.loc[inp_data['Type'] == self._app_data._INPUT_ALIAS_TYPES['mv'], ['Alias', 'Path']].to_dict(orient='records') output_vars = out_data.loc[:, ['Alias', 'Path']].to_dict(orient='records') for row in range(self._input_des_data.shape[0]): [ var.update( {'value': self._input_des_data.loc[row, var['Alias']]}) for var in input_vars ] self.case_sampled.emit( row + 1, run_case(input_vars, output_vars, aspen_con)) if self.isInterruptionRequested(): # to allow task abortion return
def run(self): pythoncom.CoInitialize() tts = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(self.tts_id, pythoncom.IID_IDispatch)) tts.Speak(self.voiceText, 0) self.plugin.TriggerEvent(self.suffix)
def startSpawner(self, *args): pythoncom.CoInitialize() xl = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(self.hWnd, pythoncom.IID_IDispatch)) self.startStatus = True print(self.HWRange) while self.startStatus is True: self.clickWindow() time.sleep(int(self.HWRangeValue * 60))
def run_in_thread(xl_id): # Initialize pythoncom.CoInitialize() # Get instance from the id xl = wincl.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(xl_id, pythoncom.IID_IDispatch)) print('yes') time.sleep(5)
def docfile(self): if self._threading_mode: pythoncom.CoInitialize() docfile = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream( self._docfile_id, pythoncom.IID_IDispatch)) self._docfile_id = pythoncom.CoMarshalInterThreadInterfaceInStream( pythoncom.IID_IDispatch, docfile) return docfile else: return self._dispatch('WinX32.DocFile')
def spt(self): if self._threading_mode: pythoncom.CoInitialize() ws_spec_mgr = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream( self._ws_spec_mgr_id, pythoncom.IID_IDispatch)) self._ws_spec_mgr_id = pythoncom.CoMarshalInterThreadInterfaceInStream( pythoncom.IID_IDispatch, ws_spec_mgr) return ws_spec_mgr.Current else: return self._spt
def exp(self): if self._threading_mode: pythoncom.CoInitialize() ws_exp = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream( self._ws_exp_id, pythoncom.IID_IDispatch)) self._ws_exp_id = pythoncom.CoMarshalInterThreadInterfaceInStream( pythoncom.IID_IDispatch, ws_exp) return ws_exp else: return self._exp
def _doTestInThread(self, interp): pythoncom.CoInitialize() myThread = win32api.GetCurrentThreadId() if freeThreaded: interp = pythoncom.CoGetInterfaceAndReleaseStream(interp, pythoncom.IID_IDispatch) interp = win32com.client.Dispatch(interp) interp.Exec("import win32api") #print "The test thread id is %d, Python.Interpreter's thread ID is %d" % (myThread, interp.Eval("win32api.GetCurrentThreadId()")) pythoncom.CoUninitialize()
def getScope(self): self._m = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(self._id, pythoncom.IID_IDispatch)) self.Acq = self._m.Acquisition self.Proj = self._m.Projection self.Ill = self._m.Illumination self.initialDF = self.Proj.Defocus self.Stage = self._m.Stage if self.debug: print '-----DF:', str(self.initialDF), 'm-----' if self.debug: print '-----end of getscope-----'
def SetCallbackThread(self): if self.__marshall_callback is None: raise COMException(desc='self.__marshall_callback is not initialized') self.__callback = win32com.client.Dispatch ( pythoncom.CoGetInterfaceAndReleaseStream ( self.__marshall_callback, pythoncom.IID_IDispatch ) ) logging.info("SetCallbackThread Done")
def getScope(self): self._m = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(self._id, pythoncom.IID_IDispatch)) self.Acq = self._m.Acquisition self.Proj = self._m.Projection self.initialDF = self.Proj.Defocus print '-----DF:', str(self.initialDF), 'm-----' if self._mstruct.mode == 'TEM': self.setTemAcqVals() if self._mstruct.mode == 'STEM': self.setStemAcqVals() self.Acq.AcquireImages() print '-----end of getscope-----'
def BuildAcces(form, acc_id, dbname, q): pythoncom.CoInitialize() acc = Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(acc_id, pythoncom.IID_IDispatch)) try: #accApp = Dispatch("Access.Application") dbEngine = acc.DBEngine workspace = dbEngine.Workspaces(0) dbLangGeneral = ';LANGID=0x0409;CP=1252;COUNTRY=0' newdb = workspace.CreateDatabase(dbname, dbLangGeneral, 64) sql = """CREATE TABLE PETICION (ID autoincrement, [REFERENCIA CATASTRAL] varchar(20), II_NUM_FIJO VARCHAR(8), EXP_AÑO VARCHAR(13), REF_EXP_DGC VARCHAR(8));""" print sql, type(sql) newdb.Execute(sql.encode('latin-1')) for i in range(form.tabla_2.rowCount()): try: refcat = form.tabla_2.item(i, 2).text() except: refcat = "" try: numfijo = form.tabla_2.item(i, 3).text() except: numfijo = "" try: exp = form.tabla_2.item(i, 4).text() except: exp = "" try: ref_exp = form.tabla_2.item(i, 4).text() ref_exp = ref_exp.split("/")[0] except: ref_exp = "" sql = """INSERT INTO PETICION ([REFERENCIA CATASTRAL], II_NUM_FIJO, EXP_AÑO, REF_EXP_DGC) VALUES ('""" +\ str(refcat) + """','""" + str(numfijo) + """','""" + str(exp) + """','""" + str(ref_exp) + """');""" print sql, type(sql) newdb.Execute(sql.encode('latin-1')) q.put("No") except Exception as e: q.put(e) finally: acc.DoCmd.CloseDatabase acc.Quit newdb = None workspace = None dbEngine = None accApp = None
def on_connection_id_created(self, connection_id): # make the server available to this thread pythoncom.CoInitialize() self.aspen_com = AspenConnection(self.app_data.simulation_file) # populate internal connection variable of AspenConnection class # this is a horrendous fix... it works though! self.aspen_com._aspen = Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(connection_id, pythoncom.IID_IDispatch)) # quit the thread if hasattr(self, 'connection_thread'): self.connection_thread.quit()
def _speaker(self, marshalled_voice, text): pythoncom.CoInitialize() voice = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(marshalled_voice, pythoncom.IID_IDispatch)) self.pre_speak() voice.Speak(text, 3) voice.WaitUntilDone(-1) self.post_speak() pythoncom.CoUninitialize()
def run(self): pid.acquire() print 'Dut[%s] start the test'%self.dut_id pythoncom.CoInitialize() sdk = win32com.client.Dispatch(pythoncom.CoGetInterfaceAndReleaseStream(self.pm_id,pythoncom.IID_IDispatch)) for t in xrange(5): sdk.Init_PM() if not sdk.GetStatus() and t == 4: pythoncom.CoUninitialize(); time.sleep(2) pid.release(); #time.sleep(2) self.running=False self.test_flag=1 self.msg="USB PowerMeter not ready" raise Except('USB PowerMeter not ready') elif sdk.GetStatus(): print sdk.GetStatus(); break else: time.sleep(1)
def verify_no_fault_on_start(self, signal_1="EmgcyCallFalt_B_Dsply", message_1="TCU_Send_Signals_5"): pythoncom.CoInitialize() self.app = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(self.marshalled_app_id, pythoncom.IID_IDispatch)) print('going to verify, sleep 15 s first to wait clear DTC') start_time = time.time() while True: if self.app.Bus.GetSignal(2, message_1, signal_1).Value == 1.0: print('fault, should not start testing') return False elif self.app.Bus.GetSignal(2, message_1, signal_1).Value == 0.0: if time.time() - start_time > 15: print('no fault, ready to start testing') return True
def impl(self): if threading.get_ident() == self._ser_thread: return self._impl elif threading.get_ident() == self._deser_thread: return self._deser assert self._deser is None, f"already deserialized on {self._deser_thread}" self._deser_thread = threading.get_ident() deser = pythoncom.CoGetInterfaceAndReleaseStream( self._ser, pythoncom.IID_IDispatch) dispatch = Dispatch(deser, resultCLSID=self._ser_resultCLSID) self._ser = None # single-use self._deser = xlwings._xlwindows.Range(xl=dispatch) return self._deser
def execute_capl_function2(self, call_marshal_id, par1=None, par2=None, par3=None, par4=None): # if call this func in another thread, self.Running will be considered not CoInitiate. # pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)s pythoncom.CoInitialize() measurement_event = pythoncom.CoGetInterfaceAndReleaseStream( call_marshal_id, pythoncom.IID_IDispatch) m = win32com.client.Dispatch(measurement_event) # m = win32com.client.getevents('{A8507FAB-33D6-43C5-B9F5-3B74451A4C41}') # m = win32com.client.WithEvents(self.Measurement, MeasEvents) print "Now trying to call CAPL func now" #print "run?", self.Running() while True: print 'y' pythoncom.PumpWaitingMessages() if par1 == None: ret = m.Call() print "ret is {}".format(ret) pythoncom.CoUninitialize() return ret elif par2 == None: ret = m.Call(par1) print "ret is {}".format(ret) pythoncom.CoUninitialize() return ret elif par3 == None: ret = m.Call(par1, par2) print "ret is {}".format(ret) pythoncom.CoUninitialize() return ret elif par4 == None: ret = m.Call(par1, par2, par3) print "ret is {}".format(ret) pythoncom.CoUninitialize() return ret else: ret = m.Call(par1, par2, par3, par4) print "ret is {}".format(ret) pythoncom.CoUninitialize() return ret
def execute_capl_function(call_marshal_id): ''' Execute Capl Function based on call_marshal_id :param call_marshal_id: determine which Capl Function is called. :return: ''' pythoncom.CoInitialize() measurement_event = pythoncom.CoGetInterfaceAndReleaseStream( call_marshal_id, pythoncom.IID_IDispatch) m = win32com.client.Dispatch(measurement_event) print "Now trying to call CAPL func now" while True: pythoncom.PumpWaitingMessages() ret = m.Call() print "ret is {}".format(ret) pythoncom.CoUninitialize() return ret
def get_id_from_gui(self, labview_id_gui): pythoncom.CoInitialize() # Get instance from the id self.labview_gui = win32com.client.dynamic.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(labview_id_gui, pythoncom.IID_IDispatch)) # Load all the required VIs for scanner motion self.labview_gui._FlagAsMethod("GetVIReference") self.scanner_speed_set_gui = self.labview_gui.GetVIReference( self._vi_path_folme_speed_set) self.scanner_speed_get_gui = self.labview_gui.GetVIReference( self._vi_path_folme_speed_get) self.scanner_xy_pos_set_gui = self.labview_gui.GetVIReference( self._vi_path_xy_pos_set_fast) self.scanner_xy_pos_get_gui = self.labview_gui.GetVIReference( self._vi_path_xy_pos_get) self.scanner_stop_gui = self.labview_gui.GetVIReference( self._vi_path_folme_stop_movement)
def get_a_signal(self): pythoncom.CoInitialize() self.app = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(self.marshalled_app_id, pythoncom.IID_IDispatch)) temp_status = -10.0 prev_time = time.time() count_1 = 0 while True: time.sleep(1) current_status = self.app.Bus.GetSignal(2, "Signal", "Botschaft").RawValue if current_status > 0: print current_status pythoncom.CoUnInitialize() break
def Init(self, sinkType, customAPIConfiguration): self.thread = Thread(target=self.threadedFunction, args=(sinkType,)) self.thread.start() Trace("Waiting for CQGCEL creation..") self.eventAllPrepared.wait() Trace("CQGCEL is created!") Trace("Marshaled CQGCEL from stream") self.cqgCEL = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(self.cqgCELStream, pythoncom.IID_IDispatch)) Trace("CQGCEL is marshaled from stream!") self.apiConfigurationSet(customAPIConfiguration) self.startupCel() if self.errorHappened: Trace("Error happened during CQGCEL start up!") return self.sink
def sample_case(self, mv_values: dict): """Samples a single case based on values provided in `mv_values`. Parameters ---------- mv_values : dict Dictionary where the keys are the aliases of the input variables and the values are the numeric values of each variable. """ pythoncom.CoInitialize() aspen_obj = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(self.marshall_id, pythoncom.IID_IDispatch)) # set input values for alias, value in mv_values.items(): if alias in self.inp_aliases: # if the value exists in the input variables, set it in the # simulation row = self.app_data.input_table_data[self.inp_aliases[alias]] aspen_obj.Tree.FindNode(row['Path']).Value = value # get the output res_dict = {} UOSTAT2_val = aspen_obj.Tree.FindNode( r"\Data\Results Summary\Run-Status\Output\UOSSTAT2").Value if UOSTAT2_val == 8: res_dict['success'] = True for out_var in self.app_data.output_table_data: res_dict[out_var['Alias']] = aspen_obj.Tree.FindNode( out_var['Path']).Value else: res_dict['success'] = False for out_var in self.app_data.output_table_data: res_dict[out_var['Alias']] = 1.0 pythoncom.CoUninitialize() # unmarshal the thread return res_dict
def get_a_signal_2(self): pythoncom.CoInitialize() self.app = win32com.client.Dispatch( pythoncom.CoGetInterfaceAndReleaseStream(self.marshalled_app_id, pythoncom.IID_IDispatch)) temp_status = -10.0 prev_time = time.time() count_1 = 0 while True: time.sleep(1) current_status = self.app.Bus.GetSignal( 2, "TesterPhysicalResTCU4_Copy_3", "TesterPhysicalResTCU_3").RawValue #current_status = self.app.Bus.GetSignal(2, "TesterPhysicalResTCU4", # "TesterPhysicalResTCU").RawValue # signal_current_log_1.append("oh " + signal_enum_1.name() + " status: " + str(current_status)) if current_status > 0: print current_status break '''