Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

win32com, threading Fehler

Allgemeines zum Thema EventGhost
Post Reply
User avatar
topix
Experienced User
Posts: 441
Joined: Sat May 05, 2007 3:43 pm
Location: Germany
Contact:

win32com, threading Fehler

Post by topix »

Ich m├Âchte das serial-plugin f├╝r meine Bed├╝rfnisse umschreiben. Ziel ist, das ├╝ber den serial-port empfangene Zeilen in eine Excel-Datei geschrieben werden. Testweise habe ich die Zeilen dort angef├╝gt, wo das Event getriggert wird. Soweit klappt es.
Allerdings wird bei jeder empfangenen Zeile die xls-Datei ge├Âffnet/geschlossen. Ich wollte nun das ├Âffnen der Datei in die Start-Routine des Plugins verlegen. Da ist dann das Problem. Ich finde den richtigen Weg nicht. Beim schreiben kommt dann immer die Meldung, das die Funtkion cells nicht existiert.

Hat da jemand ne L├Âsung f├╝r mich?

So gehts:

Code: Select all

    def HandleChar(self, ch):
        self.buffer += ch
        pos = self.buffer.find(self.terminator)
        if pos != -1:
            eventstring = self.buffer[:pos]
            if eventstring:
                self.TriggerEvent(self.decoder(eventstring)[0])

                #----- topix -----
                self.xlApp = win32com.client.Dispatch("Excel.Application") 
                self.xlApp.Workbooks.Open(r"F:\XL-Test.xls") 
                self.xlApp.Visible = 1 
                self.ws = self.xlApp.ActiveSheet
                self.ws.cells(5,2).Value = "Excel-Test"
                self.xlApp.ActiveWorkbook.Close(SaveChanges=1)
                #----- topix -----

            self.buffer = self.buffer[pos+len(self.terminator):]
So nicht:

Code: Select all

    def __start__( ...
        #----- topix -----
        self.xlApp = win32com.client.Dispatch("Excel.Application") 
        self.xlApp.Workbooks.Open(r"F:\XL-Test.xls") 
        self.xlApp.Visible = 1 
        self.ws = self.xlApp.ActiveSheet
        #----- topix -----
        ...

    def __stop__(self):
        ....
        self.xlApp.ActiveWorkbook.Close(SaveChanges=1)
        ...

    def HandleChar(self, ch):
        self.buffer += ch
        pos = self.buffer.find(self.terminator)
        if pos != -1:
            eventstring = self.buffer[:pos]
            if eventstring:
                self.TriggerEvent(self.decoder(eventstring)[0])

                #----- topix -----
                self.ws.cells(5,2).Value = "Excel-Test"
                #----- topix -----

            self.buffer = self.buffer[pos+len(self.terminator):]
Post Reply