WebSites    Projekte    CCD_ControllerCommandDispatcher

PC-CommandDispatcher

Übersicht


  •  PCCommandDispatcher unter der Spyder-Entwicklungsoberfläche
  •  vollständig in Python (und Tkinter) entwickelt
  •  aktuell nur unter Windows10 mit Standard-PC getestet
  •  spezielle UART-Funktionen verlangen Weiterentwicklung für Linux
  •  Senden von UART-ASCII-Commands vom PC zum MicroController
  •  Empfangen von UART-ASCII-Responses vom MicroController
  •  Empfangen von asynchronen UART-ASCII-Events des MicroControllers
  •  Minimale Version: nur Berücksichtigung von System- und Led-Commands

Download

  •  2212062024 PcCommandDispatcher 01V06

Bestandteile



  •  Main-Modul : PcCommandDispatcher.py :
#
import System as SYS
#
#---------------------------------------------------------
# Main
#---------------------------------------------------------
if ('__main__' == __name__):
    SYS.OnProtocol('*** PcCommandDispatcher: begin')
    #
    SYS.FrameApplication.Initialise()
    #
    SYS.FrameApplication.Execute()
    #
    SYS.OnProtocol('*** PcCommandDispatcher: end')
#
#

  •  Modul : System.py :
#
import tkinter as TKI
#
import Define as DEF
import Uart as URT
import FrameApplication as FRA
import FrameSystemLedState as FSLS
#
global FrameApplication
#---------------------------------------------------------
# Main - Function
#---------------------------------------------------------
def OnError(text):
    FrameApplication.Error(text)
def OnProtocol(line):
    FrameApplication.Protocol(line)
#
def SystemOnAbort():
    UartController.Abort()
#------------------------------------------------------------
# Callback - Uart
#------------------------------------------------------------
def UartOnOpen():
    FrameApplication.tbsUart.FrameUartProtocol.ControlsEnable()
    FrameApplication.tbsSystem.ControlsEnable()
    return
def UartOnClose():
    FrameApplication.tbsUart.FrameUartProtocol.ControlsDisable()
    FrameApplication.tbsSystem.ControlsDisable()
    return
def UartOnLineReceived(rxline):
    # ':xxx' in Uart RxLine respected
    FrameApplication.tbsUart.FrameUartProtocol.AddRxLine(rxline)
    if ('!Error:' in rxline):
        OnProtocol(rxline)
        SystemOnAbort() # reenable Handshake
        Text = rxline[8:-1]
        OnError(Text)
        return
    if ('!SYS' in rxline):
        Text = rxline[5:]
        Tokens = Text.split(' ')
        #debug print('>>>', Tokens)
        FRM = FrameApplication.tbsSystem.frmSystemCommon
        FRM.SetControllerTicks(float(Tokens[0]) / 1000.0)
        return
    if ('!LSO' == rxline):
        FRM = FrameApplication.tbsSystem.frmSystemLedState
        FRM.SetState(FSLS.EStateLed.sldOn)
        return
    if ('!LSF' == rxline):
        FRM = FrameApplication.tbsSystem.frmSystemLedState
        FRM.SetState(FSLS.EStateLed.sldOff)
        return
    return
def UartOnLineTransmit(txline):
    FrameApplication.tbsUart.FrameUartProtocol.AddTxLine(txline)
    return
#------------------------------------------------------------
# Callback - FrameSetupGlobal
#------------------------------------------------------------
def FrameUartProtocolOnTransmitLine(txline):
    UartController.TransmitLine(txline)
#------------------------------------------------------------
# Callback - FrameSystemCommon
#------------------------------------------------------------
def FrameSystemCommonOnReset():
    UartController.TransmitLine('R')
def FrameSystemCommonOnAbort():
    UartController.TransmitLine('A')
def FrameSystemCommonOnRefreshInterval(interval):
    UartController.TransmitLine('SRI {0}'.format(interval))
#------------------------------------------------------------
# Callback - FrameSystemLed
#------------------------------------------------------------
def FrameSystemLedOnSetOn():
    UartController.TransmitLine('LSO')
def FrameSystemLedOnSetOff():
    UartController.TransmitLine('LSF')
def FrameSystemLedOnInvert():
    UartController.TransmitLine('LSI')
def FrameSystemLedOnBlink(blinkcount, timeon, timeoff):
    UartController.TransmitLine('LSB {0} {1} {2}'.format(blinkcount, timeon, timeoff))
#------------------------------------------------------------
# Callback - Protocol
#------------------------------------------------------------
def FrameProtocolOnWriteToFile():
    FrameApplication.tbsProtocol.WriteToFile()
    return
def FrameProtocolOnClearAll():
    FrameApplication.tbsProtocol.ClearAll()
    return
# Uart
def FrameProtocolUartOnWriteToFile():
    FrameApplication.tbsProtocolUart.WriteToFile()
    return
def FrameProtocolUartOnClearAll():
    FrameApplication.tbsProtocolUart.ClearAll()
    return
#---------------------------------------------------------
# Main - Callback
#---------------------------------------------------------
def OnFrameApplicationDelete():
    try:
        UartController.Close()
        FrameApplication.WriteInitdata(DEF.NAME_INITFILE)
    except:
        pass
#--------------------------------------------------------------------
#   Field - Global
#--------------------------------------------------------------------
UartController = URT.CUart()
UartController.SetOnProtocol(OnProtocol)
UartController.SetOnOpen(UartOnOpen)
UartController.SetOnClose(UartOnClose)
UartController.SetOnLineReceived(UartOnLineReceived)
UartController.SetOnLineTransmit(UartOnLineTransmit)
#
FrameApplication = FRA.CFrameApplication(TKI.Tk(),
                                         OnFrameApplicationDelete)
FrameApplication.SetOnProtocolWriteToFile(FrameProtocolOnWriteToFile)
FrameApplication.SetOnProtocolClearAll(FrameProtocolOnClearAll)
FrameApplication.SetOnProtocolUartWriteToFile(FrameProtocolUartOnWriteToFile)
FrameApplication.SetOnProtocolUartClearAll(FrameProtocolUartOnClearAll)
#
FRM = FrameApplication.tbsSystem.frmSystemCommon
FRM.SetSystemOnReset(FrameSystemCommonOnReset)
FRM.SetSystemOnAbort(FrameSystemCommonOnAbort)
FRM.SetSystemOnRefreshInterval(FrameSystemCommonOnRefreshInterval)
#
FrameApplication.tbsSystem.frmSystemLed.SetLedSystemOnSetOn(FrameSystemLedOnSetOn)
FrameApplication.tbsSystem.frmSystemLed.SetLedSystemOnSetOff(FrameSystemLedOnSetOff)
FrameApplication.tbsSystem.frmSystemLed.SetLedSystemOnInvert(FrameSystemLedOnInvert)
FrameApplication.tbsSystem.frmSystemLed.SetLedSystemOnBlink(FrameSystemLedOnBlink)
#
FrameApplication.tbsUart.FrameUartSetup.SetLinkUart(UartController)
FrameApplication.tbsUart.FrameUartProtocol.SetOnTransmitLine(FrameUartProtocolOnTransmitLine)

  •  Modul : FrameApplication.py :
import tkinter as TKI
from tkinter import ttk as TTK
from tkinter import messagebox as TKMB
from tkinter import filedialog as TKFD
#
import Define as DEF
import Initdata as ID
import FrameProtocol as FPT
import FrameSystem as FST
import FrameUart as FUT
#
class CFrameApplication(TKI.Frame):
    def __init__(self, frameparent, onframeapplicationdelete):
        TKI.Frame.__init__(self, frameparent)
        self.FrameParent = frameparent
        self.FrameParent.protocol('WM_DELETE_WINDOW', self.OnWMDeleteWindow)
        self.OnFrameApplicationDelete = onframeapplicationdelete
        #--------------------------------------------------------
        # Common
        #--------------------------------------------------------
        #self.FrameParent.rowconfigure(0, weight=1)
        #self.FrameParent.columnconfigure(0, weight=1)
        self.FrameParent.geometry('804x626+66+66')
        #self.FrameParent.geometry('804x626+2022+33')
        self.FrameParent.title(DEF.APPLICATION_TITLE)
        #
        self.IsActive = False
        #--------------------------------------------------------
        # Menu
        #--------------------------------------------------------
        self.Menu = TKI.Menu(self.FrameParent)
        self.FrameParent.config(menu = self.Menu)
        # Menu - System
        self.MenuSystem = TKI.Menu(self.Menu, tearoff=0)
        self.Menu.add_cascade(label = "System", menu = self.MenuSystem)
        self.MenuSystem.add_command(label = "Read Initfile Default", \
                                    command = self.OnReadInitfileDefault)
        self.MenuSystem.add_command(label = "Read Initfile Dialog", \
                                    command = self.OnReadInitfileDialog)
        self.MenuSystem.add_separator()
        self.MenuSystem.add_command(label = "Write Initfile Default", \
                                    command = self.OnWriteInitfileDefault)
        self.MenuSystem.add_command(label = "Write Initfile Dialog", \
                                    command = self.OnWriteInitfileDialog)
        self.MenuSystem.add_command(label = "Exit Application", \
                                    command = self.OnExitApplication)
        # Menu - Device
        self.MenuDevice = TKI.Menu(self.Menu, tearoff=0)
        self.Menu.add_cascade(label = "Protocol", menu = self.MenuDevice)
        self.MenuDevice.add_command(label = "Global", state="disabled")
        self.MenuDevice.add_command(label = "Write to File",
                                    command = self.OnProtocolWriteToFile)
        self.MenuDevice.add_command(label = "Clear All",
                                    command = self.OnProtocolClearAll)
        self.MenuDevice.add_separator()
        self.MenuDevice.add_command(label = "Uart", state="disabled")
        self.MenuDevice.add_command(label = "Write to File",
                                    command = self.OnProtocolUartWriteToFile)
        self.MenuDevice.add_command(label = "Clear All",
                                    command = self.OnProtocolUartClearAll)
        # Menu - Help
        self.MenuHelp = TKI.Menu(self.Menu, tearoff=0)
        self.Menu.add_cascade(label = "Help", menu = self.MenuHelp)
        self.MenuHelp.add_command(label = "Show About", command = self.OnShowAbout)
        #--------------------------------------------------------
        # Notebook
        #--------------------------------------------------------
        self.ntbView = TTK.Notebook(self.FrameParent)
        self.ntbView.place(x=3, y=0, width=800, height=600)
        #--------------------------------------------------------
        # Notebook - Tabsheet - Protocol
        #--------------------------------------------------------
        self.tbsProtocol = FPT.CFrameProtocol(self.ntbView)
        self.ntbView.add(self.tbsProtocol, text='Protocol')
        #--------------------------------------------------------
        # Notebook - Tabsheet - Uart
        #--------------------------------------------------------
        self.tbsUart = FUT.CFrameUart(self.ntbView)
        self.ntbView.add(self.tbsUart, text = "Uart")
        #--------------------------------------------------------
        # FrameCommand (11)
        #--------------------------------------------------------
        self.ntbCommands = TTK.Notebook(self.FrameParent)
        self.ntbCommands.place(x=4, y=600, width=800, height=266)
        #--------------------------------------------------------
        self.tbsSystem= FST.CFrameSystem(self.FrameParent)
        self.ntbCommands.add(self.tbsSystem, text='System')
        #--------------------------------------------------------
        self.PProtocolWriteToFile = None
        self.PProtocolClearAll = None
        self.PProtocolUartWriteToFile = None
        self.PProtocolUartClearAll = None
        #
        return
    #---------------------------------------------------------------------
    # CApplication - Property
    #---------------------------------------------------------------------
    def SetOnProtocolWriteToFile(self, onprotocolwritetofile):
        self.PProtocolWriteToFile = onprotocolwritetofile
    def SetOnProtocolClearAll(self, onprotocolclearall):
        self.PProtocolClearAll = onprotocolclearall
    def SetOnProtocolUartWriteToFile(self, onprotocoluartwritetofile):
        self.PProtocolUartWriteToFile = onprotocoluartwritetofile
    def SetOnProtocolUartClearAll(self, onprotocoluartclearall):
        self.PProtocolUartClearAll = onprotocoluartclearall
    #---------------------------------------------------------------------
    # CApplication - Initdata
    #---------------------------------------------------------------------
    def Initialise(self):
        self.IsActive = True
        self.Protocol('CFrameApplication.Initialise')
        self.ReadInitdata(DEF.NAME_INITFILE)
        return
    #
    def ReadInitdata(self, filename):
        self.Protocol('CFrameApplication.ReadInitdata: begin')
        RID = ID.CReadInitdata()
        RID.Open(filename)
        X = RID.ReadValueInit(DEF.INITDATA_SECTION, DEF.NAME_X, DEF.INIT_X)
        Y = RID.ReadValueInit(DEF.INITDATA_SECTION, DEF.NAME_Y, DEF.INIT_Y)
        W = RID.ReadValueInit(DEF.INITDATA_SECTION, DEF.NAME_W, DEF.INIT_W)
        H = RID.ReadValueInit(DEF.INITDATA_SECTION, DEF.NAME_H, DEF.INIT_H)
        self.FrameParent.geometry('%dx%d+%d+%d' % (int(W), int(H), int(X), int(Y)))
        #
        STI = RID.ReadValueInit(DEF.INITDATA_SECTION, DEF.NAME_SELECTTABINDEX,
                                DEF.INIT_SELECTTABINDEX)
        self.ntbView.select(int(STI))
        #
        self.tbsProtocol.ReadInitdata(RID)
        self.tbsUart.ReadInitdata(RID)
        #
        self.tbsSystem.ReadInitdata(RID)
        #
        RID.Close()
        self.Protocol('CFrameApplication.ReadInitdata: end')
        return
    #
    def WriteInitdata(self, filename):
        self.Protocol('CFrameApplication.WriteInitdata: begin')
        WID = ID.CWriteInitdata()
        WID.Open(filename)
        X = self.FrameParent.winfo_x()
        Y = self.FrameParent.winfo_y()
        W = self.FrameParent.winfo_width()
        H = self.FrameParent.winfo_height()
        WID.WriteSection(DEF.INITDATA_SECTION)
        WID.WriteValue(DEF.INITDATA_SECTION, DEF.NAME_X, str(X))
        WID.WriteValue(DEF.INITDATA_SECTION, DEF.NAME_Y, str(Y))
        WID.WriteValue(DEF.INITDATA_SECTION, DEF.NAME_W, str(W))
        WID.WriteValue(DEF.INITDATA_SECTION, DEF.NAME_H, str(H))
        #
        STI = self.ntbView.index('current')
        WID.WriteValue(DEF.INITDATA_SECTION, DEF.NAME_SELECTTABINDEX, str(STI))
        #
        self.tbsProtocol.WriteInitdata(WID)
        self.tbsUart.WriteInitdata(WID)
        #
        self.tbsSystem.WriteInitdata(WID)
        #
        WID.Close()
        self.Protocol('CFrameApplication.WriteInitdata: end')
        return
    #---------------------------------------------------------------------
    # CApplication - Helper
    #---------------------------------------------------------------------
    def Error(self, text):
        if (self.IsActive):
            self.tbsProtocol.Error(text)
            TKMB.showerror('Error', text)
        return
    def Protocol(self, line):
        if (self.IsActive):
            self.tbsProtocol.Line(line)
        return
    #---------------------------------------------------------------------
    # CApplication - Callback / Event
    #---------------------------------------------------------------------
    def OnWMDeleteWindow(self):
        self.IsActive = False
        self.WriteInitdata(DEF.NAME_INITFILE)
        if (None != self.OnFrameApplicationDelete):
            self.OnFrameApplicationDelete()
        self.FrameParent.destroy()
        return
    #
    def OnReadInitfileDefault(self):
        self.ReadInitdata(DEF.NAME_INITFILE)
        return
    #
    def OnReadInitfileDialog(self):
        FT = (('Initfiles', '*.ini'),
              ('All files', '*.*'))
        FN = DEF.NAME_INITFILE
        FN = TKFD.askopenfilename(title = 'Read Initfile',
                                  initialdir = '../TerminalUart',
                                  filetypes = FT)
        self.ReadInitdata(FN)
        return
    #
    def OnWriteInitfileDefault(self):
        self.WriteInitdata(DEF.NAME_INITFILE)
        return
    #
    def OnWriteInitfileDialog(self):
        FT = (('Initfiles', '*.ini'),
              ('All files', '*.*'))
        FN = DEF.NAME_INITFILE
        FF = TKFD.asksaveasfile(initialfile = FN,
                                defaultextension = '.ini',
                                filetypes = FT)
        if (None != FF):
            FN = FF.name
            FF.close()
            self.WriteInitdata(FN)
        return
    #
    def OnProtocolWriteToFile(self):
        if (None != self.PProtocolWriteToFile):
            self.PProtocolWriteToFile()
        return
    def OnProtocolClearAll(self):
        if (None != self.PProtocolClearAll):
            self.PProtocolClearAll()
        return
    #
    def OnProtocolUartWriteToFile(self):
        if (None != self.PProtocolUartWriteToFile):
            self.PProtocolUartWriteToFile()
        return
    def OnProtocolUartClearAll(self):
        if (None != self.PProtocolUartClearAll):
            self.PProtocolUartClearAll()
        return
    def OnShowAbout(self):
        TKMB.showinfo("About", DEF.INFO_ABOUT)
    #
    def OnExitApplication(self):
        self.OnWMDeleteWindow()
    #---------------------------------------------------------------------
    # CApplication - Handler
    #---------------------------------------------------------------------
    def Execute(self):
        self.FrameParent.mainloop()
    #
    #
#
#

  •  Module : (Frame...).py :
     FrameCommand.py
     FrameProtocol.py
     FrameSystem.py
     FrameSystemCommon.py
     FrameSystemLed.py
     FrameSystemLedState.py
     FrameUart.py
     FrameUartProtocol.py
     FrameUartSetup.py

  •  Modul : Initdata.py :
#
# ------------------------------------------------------------------
#   Initdata
# ------------------------------------------------------------------
#   Version: 02V11
#   Date   : 220915
#   Time   : 1040
#   Author : OMDevelop
#
import configparser as CFP
#
import Helper as HLP
#
class CWriteInitdata():
    #
    def __init__(self):
        self.Parser = CFP.ConfigParser()
        self.Parser.optionxform = str
    #
    def Open(self, filename):
        self.Filename = filename
    #
    def Close(self):
        self.File = open(self.Filename, 'w')
        self.Parser.write(self.File)
        self.File.close()
        self.Parser = None
    #
    def WriteSection(self, section):
        self.Parser.add_section(section)
        # debug print("WriteSection[" + section + "]")

    def WriteValue(self, section, name, value):
        self.Parser.set(section, name, value)
        # debug print("WriteValue[" + section + "] Name[" + name + "] Value[" + value + "]")
#
#
#
class CReadInitdata():
    #
    def __init__(self):
        self.Parser = CFP.ConfigParser()
        self.Parser.optionxform = str
    #
    def Open(self, filename):
        self.Parser.read(filename)
    #
    def Close(self):
        self.Parser = None
    #
    def ReadValue(self, section, name):
        Value = "???"
        try:
            Value = self.Parser.get(section, name)
            # debug print("ReadValue[" + section + "] Name[" + name + "] Value[" + Value + "]")
            return Value
        except:
            # debug print("ReadValue[" + section + "] Name[" + name + "] Value[" + Value + "]")
            return "?"
    #
    def ReadValueInit(self, section, name, init):
        Value = init
        try:
            Value = self.Parser.get(section, name)
            # debug print("ReadValue[" + section + "] Name[" + name + "] Value[" + Value + "][" + init + "]")
            return Value
        except:
            # debug print("ReadValue[" + section + "] Name[" + name + "] Value[" + Value + "][" + init + "]")
            return Value
#
#

  •  Modul : Uart.py :
#
import tkinter as TKI
#
import Define as DEF
import Uart as URT
import FrameApplication as FRA
import FrameSystemLedState as FSLS
#
global FrameApplication
#---------------------------------------------------------
# Main - Function
#---------------------------------------------------------
def OnError(text):
    FrameApplication.Error(text)
def OnProtocol(line):
    FrameApplication.Protocol(line)
#
def SystemOnAbort():
    UartController.Abort()
#------------------------------------------------------------
# Callback - Uart
#------------------------------------------------------------
def UartOnOpen():
    FrameApplication.tbsUart.FrameUartProtocol.ControlsEnable()
    FrameApplication.tbsSystem.ControlsEnable()
    return
def UartOnClose():
    FrameApplication.tbsUart.FrameUartProtocol.ControlsDisable()
    FrameApplication.tbsSystem.ControlsDisable()
    return
def UartOnLineReceived(rxline):
    # ':xxx' in Uart RxLine respected
    FrameApplication.tbsUart.FrameUartProtocol.AddRxLine(rxline)
    if ('!Error:' in rxline):
        OnProtocol(rxline)
        SystemOnAbort() # reenable Handshake
        Text = rxline[8:-1]
        OnError(Text)
        return
    if ('!SYS' in rxline):
        Text = rxline[5:]
        Tokens = Text.split(' ')
        #debug print('>>>', Tokens)
        FRM = FrameApplication.tbsSystem.frmSystemCommon
        FRM.SetControllerTicks(float(Tokens[0]) / 1000.0)
        return
    if ('!LSO' == rxline):
        FRM = FrameApplication.tbsSystem.frmSystemLedState
        FRM.SetState(FSLS.EStateLed.sldOn)
        return
    if ('!LSF' == rxline):
        FRM = FrameApplication.tbsSystem.frmSystemLedState
        FRM.SetState(FSLS.EStateLed.sldOff)
        return
    return
def UartOnLineTransmit(txline):
    FrameApplication.tbsUart.FrameUartProtocol.AddTxLine(txline)
    return
#------------------------------------------------------------
# Callback - FrameSetupGlobal
#------------------------------------------------------------
def FrameUartProtocolOnTransmitLine(txline):
    UartController.TransmitLine(txline)
#------------------------------------------------------------
# Callback - FrameSystemCommon
#------------------------------------------------------------
def FrameSystemCommonOnReset():
    UartController.TransmitLine('R')
def FrameSystemCommonOnAbort():
    UartController.TransmitLine('A')
def FrameSystemCommonOnRefreshInterval(interval):
    UartController.TransmitLine('SRI {0}'.format(interval))
#------------------------------------------------------------
# Callback - FrameSystemLed
#------------------------------------------------------------
def FrameSystemLedOnSetOn():
    UartController.TransmitLine('LSO')
def FrameSystemLedOnSetOff():
    UartController.TransmitLine('LSF')
def FrameSystemLedOnInvert():
    UartController.TransmitLine('LSI')
def FrameSystemLedOnBlink(blinkcount, timeon, timeoff):
    UartController.TransmitLine('LSB {0} {1} {2}'.format(blinkcount, timeon, timeoff))
#------------------------------------------------------------
# Callback - Protocol
#------------------------------------------------------------
def FrameProtocolOnWriteToFile():
    FrameApplication.tbsProtocol.WriteToFile()
    return
def FrameProtocolOnClearAll():
    FrameApplication.tbsProtocol.ClearAll()
    return
# Uart
def FrameProtocolUartOnWriteToFile():
    FrameApplication.tbsProtocolUart.WriteToFile()
    return
def FrameProtocolUartOnClearAll():
    FrameApplication.tbsProtocolUart.ClearAll()
    return
#---------------------------------------------------------
# Main - Callback
#---------------------------------------------------------
def OnFrameApplicationDelete():
    try:
        UartController.Close()
        FrameApplication.WriteInitdata(DEF.NAME_INITFILE)
    except:
        pass
#--------------------------------------------------------------------
#   Field - Global
#--------------------------------------------------------------------
UartController = URT.CUart()
UartController.SetOnProtocol(OnProtocol)
UartController.SetOnOpen(UartOnOpen)
UartController.SetOnClose(UartOnClose)
UartController.SetOnLineReceived(UartOnLineReceived)
UartController.SetOnLineTransmit(UartOnLineTransmit)
#
FrameApplication = FRA.CFrameApplication(TKI.Tk(),
                                         OnFrameApplicationDelete)
FrameApplication.SetOnProtocolWriteToFile(FrameProtocolOnWriteToFile)
FrameApplication.SetOnProtocolClearAll(FrameProtocolOnClearAll)
FrameApplication.SetOnProtocolUartWriteToFile(FrameProtocolUartOnWriteToFile)
FrameApplication.SetOnProtocolUartClearAll(FrameProtocolUartOnClearAll)
#
FRM = FrameApplication.tbsSystem.frmSystemCommon
FRM.SetSystemOnReset(FrameSystemCommonOnReset)
FRM.SetSystemOnAbort(FrameSystemCommonOnAbort)
FRM.SetSystemOnRefreshInterval(FrameSystemCommonOnRefreshInterval)
#
FrameApplication.tbsSystem.frmSystemLed.SetLedSystemOnSetOn(FrameSystemLedOnSetOn)
FrameApplication.tbsSystem.frmSystemLed.SetLedSystemOnSetOff(FrameSystemLedOnSetOff)
FrameApplication.tbsSystem.frmSystemLed.SetLedSystemOnInvert(FrameSystemLedOnInvert)
FrameApplication.tbsSystem.frmSystemLed.SetLedSystemOnBlink(FrameSystemLedOnBlink)
#
FrameApplication.tbsUart.FrameUartSetup.SetLinkUart(UartController)
FrameApplication.tbsUart.FrameUartProtocol.SetOnTransmitLine(FrameUartProtocolOnTransmitLine)

  •  Modul : Task.py :
#
# ------------------------------------------------------------------
#   Task
# ------------------------------------------------------------------
#   Version: 02V06
#   Date   : 221005
#   Time   : 1522
#   Author : OMDevelop
#
import threading as THR
# NC import time
#
class CEvent:
    def __init__(self, initstate = False):
        self.FEvent = THR.Event()
        if (initstate):
            self.FEvent.set()
        else:
            self.FEvent.clear()
    #
    def Clear(self):
        self.FEvent.clear()
    def Set(self):
        self.FEvent.set()
    #
    def Wait(self):
        self.FEvent.wait()
#
#
class CTask:
    def __init__(self, id, cbonstart, cbonabort, cbonexecute):
        self.ID = id
        self.FThread = None
        self.DoLoop = True
        self.CBOnStart = cbonstart
        self.CBOnAbort = cbonabort
        self.CBOnExecute = cbonexecute
    #
    def SetCBOnExecute(self, callback):
        self.CBOnExecute = callback
    #
    def IsBusy(self):
        return self.DoLoop
    #
    def Start(self):
        self.DoLoop = True
        if isinstance(self.FThread, THR.Thread):
            self.Abort()
        self.FThread = None
        self.FThread = THR.Thread(target = self.OnExecute)
        self.FThread.start()
        if (None != self.CBOnStart):
            self.CBOnStart(self)
    #
    def Abort(self):
        try:
            self.DoLoop = False
            if (None != self.CBOnAbort):
                self.CBOnAbort(self)
            # hangsup if (None != self.FThread):
            # hangsup     self.FThread.join()
            # hangsup if isinstance(self.FThread, threading.Thread):
            # hangsup     self.FThread.join()
        except:
            pass
    #
    def OnExecute(self):
        try:
            self.DoLoop = True;
            while (True == self.DoLoop):
                if (None != self.CBOnExecute):
                    self.DoLoop = self.CBOnExecute(self)
            self.Abort()
        except:
            pass

  •  Modul : Define.py :
#
#------------------------------------------------------------------
#   Global Constant
#------------------------------------------------------------------
APPLICATION_TITLE       = "PcCommandDispatcher"
APPLICATION_VERSION     = "01V08"
APPLICATION_DATE        = "221206"
APPLICATION_TIME        = "1405"
APPLICATION_AUTHOR      = "OMDevelop"
#
APPLICATION_ABSTRACT_00 = "PC-Command Dispatcher"
APPLICATION_ABSTRACT_01 = ""
APPLICATION_ABSTRACT_02 = ""
#
INFO_ABOUT = APPLICATION_TITLE + "\r\n\r\n" + \
             "Version: " + APPLICATION_VERSION + "\r\n" + \
             "Date: " + APPLICATION_DATE + "\r\n" + \
             "Time: " + APPLICATION_TIME + "\r\n" + \
             "Author: " + APPLICATION_AUTHOR + "\r\n" + \
             "\r\n" + \
             "Abstract:\r\n" + \
             "- " + APPLICATION_ABSTRACT_00 + "\r\n" + \
             "- " + APPLICATION_ABSTRACT_01 + "\r\n" + \
             "- " + APPLICATION_ABSTRACT_02 + ""
#
NAME_INITFILE = APPLICATION_TITLE + ".ini"
INITDATA_SECTION = "WindowMain"
NAME_X = "X"
NAME_Y = "Y"
NAME_W = "W"
NAME_H = "H"
NAME_SELECTTABINDEX = "SelectTabIndex"
#
INIT_X = "10"
INIT_Y = "10"
INIT_W = "690"
INIT_H = "546"
INIT_SELECTTABINDEX = "0"
#--------------------------------------
FRAMEINDEX_SETUP         = 0
FRAMEINDEX_UARTDATAFLOW  = 1
FRAMEINDEX_REPORT        = 2
FRAMEINDEX_PLOT2D        = 3
FRAMEINDEX_HARDWARE      = 4
#
DOTS_X      = 600
DOTS_Y      = 600
DOTSPERINCH = 100
#
LIMIT_X_LOW           =  +0.0
LIMIT_X_HIGH          = +10.0
LIMIT_Y_LOW           =  +0.0
LIMIT_Y_HIGH          = +10.0
LIMIT_Z_LOW           =  -5.0
LIMIT_Z_HIGH          =  +5.0
##
PAD_X = 2
PAD_Y = 2
FONTSIZE_LISTBOX = 11
COLOR_BACK = "#F8FEEE"
#
#
TIME_REFRESH            = 0.10 # [s] -> GCodeSimulator!
#
INIT_AZIMUTH            = +30.00 # [deg]
INIT_DAZIMUTH           =  +0.50 # [deg]
INIT_ELEVATION          = +30.00 # [deg]
INIT_DELEVATION         =  +0.25 # [deg]
#
#
##############################################
#
#----------------------------------------------
#   F-Code
#----------------------------------------------
CODE_F      = 'F'       # Set Feedrate [mm/s]
#----------------------------------------------
#   G-Code
#----------------------------------------------
CODE_G      = 'G'
#
CODE_G0     = 'G0'      # Rapid Positioning at Feedrate : G0 X50 Y50 Z0
CODE_G00    = 'G0'      # G0
CODE_G1     = 'G1'      # Linear Movement at Feedrate : G1 X100 Y100 Z0 F100
CODE_G01    = 'G1'      # G1
CODE_G2     = 'G2'      # Cut Clockwise Arc : G2 X8Y5 I8 J5 F100
CODE_G02    = 'G2'      # G2
CODE_G3     = 'G3'      # Cut AntiClockwise Arc
CODE_G03    = 'G3'      # G3
CODE_G4     = 'G4'      # Pause [seconds]
CODE_G04    = 'G4'      # G4
#
CODE_G17    = 'G17'     #
CODE_G18    = 'G18'
CODE_G19    = 'G19'
CODE_G20    = 'G20'     # Select Imperial Units [inch]
CODE_G21    = 'G21'     # Select Metric Units [meter]
CODE_G28    = 'G28'     # Goto Predefined Position
CODE_G28p2  = 'G28.2'   # Run Homing Cycle
#
CODE_G38p2  = 'G38.2'   # Probe moves to Workpart with distanceout : G38.2 Z-65 F100
CODE_G38p3  = 'G38.3'   # Probe moves to Workpart without check : G38.3 Z-65 F100
CODE_G38p4  = 'G38.4'   # Probe moves from Workpart with distanceout : G38.4 Z-65 F100
CODE_G38p5  = 'G38.5'   # Probe moves from Workpart without check : G38.5 Z-65 F100
#
CODE_G53    = 'G53'     # Motion in MachineCoordinates (only G0/G1) : G53 G0 X50 Y50 Z0
CODE_G54    = 'G54'     # Select Coordinate System 1 : ???
CODE_G55    = 'G54'     # Select Coordinate System 2 : ???
CODE_G56    = 'G54'     # Select Coordinate System 3 : ???
CODE_G57    = 'G54'     # Select Coordinate System 4 : ???
CODE_G58    = 'G54'     # Select Coordinate System 5 : ???
CODE_G59    = 'G54'     # Select Coordinate System 6 : ???
#
CODE_G80    = 'G80'     # Cancel Motion Modes : ???
#
CODE_G90    = 'G90'     # Moving in Absolute (Machine)Coordinates : G90 G0 X50
CODE_G91    = 'G91'     # Moving in Relative Coordinates : G91 G0 X50
CODE_G92    = 'G92'     # Defines WorkCoordinates at X/Y/Z
CODE_G92p1  = 'G92.1'   # Resets WorkCoordinates to MachineCoordinates
#
CODE_G94    = 'G94'     # Feed per Minute Mode [mm/s] -> [mm/min]
#
#-----------------------------------------------------------------------------------------
#   M-Code
#-----------------------------------------------------------------------------------------
CODE_M      = 'M'
#
CODE_M0     = 'M0'      # Program End : M0
CODE_M2     = 'M1'      # Sleep / Stop : M2
CODE_M3     = 'M3'      # Switch Spindle On (S:Speed[rot/s]): M3 S12000
CODE_M5     = 'M5'      # Switch Spindle Off : M5
CODE_M6     = 'M6'      # Replace with Tool, display Message: M6 T42 (T42-message)
CODE_M8     = 'M8'      # Switch Coolant On : M8
CODE_M9     = 'M9'      # Switch Coolant Off : M9
#
CODE_M30    = 'M30'     # Program Pause and End : M30
#
#
#----------------------------------------------
#   Parameter-Code
#----------------------------------------------
CODE_NULL    = ''
CODE_COMMENT = ';'
CODE_X       = 'X'
CODE_Y       = 'Y'
CODE_Z       = 'Z'
CODE_H       = 'H'
CODE_I       = 'I'
CODE_J       = 'J'
CODE_K       = 'K'
CODE_L       = 'L'
CODE_N       = 'N'
CODE_P       = 'P'
CODE_R       = 'R'
CODE_S       = 'S'
CODE_T       = 'T'
CODE_F       = 'F'
#
#

  •  Modul : Helper.py :
#
# Helper
#
import numpy as NUM
#
#-----------------------------------------------------------
# Constant
#-----------------------------------------------------------
PIRAD  = NUM.pi
PIDRAD = 2.0 * NUM.pi
PIHRAD = 0.5 * NUM.pi
PIQRAD = 0.25 * NUM.pi
#
PIDEG  = 180.0
PIDDEG = 360.0
PIHDEG = 90.0
PIQDEG = 45.0
#
#----------------------------------------------
#   Conversion
#----------------------------------------------
def BooleanString(bvalue):
    if (True == bvalue):
        return "True"
    return "False"
#
def StringBoolean(text):
    Text = text.upper()
    if ("T" in Text):
        return True
    if ("1" in Text):
        return True
    return False
#
def RadDeg(rad):
    return PIDEG * rad / PIRAD
def DegRad(deg):
    return PIRAD * deg / PIDEG
#
def ArcTanPos(dy, dx):
    AR = NUM.arctan2(dy, dx)
    if (AR < 0.0):
        AR += PIDRAD
    return AR
#
#

Signalfluss

  •  Main-Modul : PcCommandDispatcher.py
     Aufruf der Initialisierung des Application-Moduls
     Aufruf Execute-Methode Application-Modul

  •  Modul : System.py
     Globale Callback-Funktionen Messages
     Globale Callback-Funktionen Uart
     Globale Callback-Funktionen Commands
     OnDelete-Callback beim Schliessen des Programms
     Zentraler Set-Verteiler für alle Callback-Funktionen

  •  Modul : FrameApplication.py
     Constructor mit Menu- und Control-Definitionen
     Verzweigung zu allen SubFrames Frame-Hierachie
     Read/WriteInitdata zum Lesen/Schreiben der FrameApplication-Init-Daten
     On-Callback-Funktionen für Menu- und Button-Funktionen
     Execute-Methode mit Aufruf vom Main-Module

  •  alle restlichen Module : Frame(...).py
     Verteiler für Control-Funktionen
     besitzen Read/WriteInitdata zum Lesen/Schreiben der Control-Values

  •  Module : Initdata.py mit Classes CWrite/CReadInitdata
     Zentrales Modul aller CWriteInitdata-Class-Methoden
     Zentrales Modul aller CReadInitdata-Class-Methoden
     Alle Transfer-Daten vom Typ String

  •  Module : Uart.py mit Class CUart
     Uart-Module mit Kapselung der seriellen Read- Und Write-Methoden
     Callback-Funktion zur Behandlung aller einkommenden Daten
     eigener Thread für glatten Verlauf der Rx- und TxDaten

  •  Module : Task.py mit Class CTask
     Callback-Methoden OnStart/OnAbort/OnExecute für Benutzer-Methoden
     CEvent als Signal-Class zur Synchronisation von mehreren Threads

  •  Module : Define.py
     beinhaltet alle globalen Term-Defitionen

  •  Module : Helper.py
     beinhaltet allgemeine globale Funktionen (String-, Mathe-,...)

WebSites    Projekte    CCD_ControllerCommandDispatcher