예제 #1
0
    def __init__(self, master, _ControlPoint, NumTrimmer, _commESP): #########################################
        self.allure = 0  # Initially stopped
        self.CTE=Constante("common.h")       # From ParseCommonHeader.py
        self.CTE.ParseFile()
        self.commESP = _commESP  # get the liste of Server, contain only communicationa artefacts
        self.ControlPoint =  _ControlPoint
        self.NumTrimmer   =  NumTrimmer

        self.top = Toplevel(master)  # Link with master window
        self.top.withdraw()  # Dp Not display empty window
        self.top.grab_set()

        self.CreateTrimScale(self.top)
예제 #2
0
    def __init__(self, CtrlServerLst):
        i = 0
        # Get the constant from 'common.h' file active.
        CTE = Constante("common.h")
        CTE.ParseFile()

        # Get the host IP address.
        #        if your PC / Host have several Ethernet/IP port,
        #        you might not get the IP address you want !!!!!!!!
        self.ipLocal = socket.gethostbyname(socket.gethostname())

        # The list of Server from
        self.ServerLst = []  # Array of server with IP, Port and name
        self.UDPClientSocket = [
        ]  # Array of the socket created: one per server.

        # Assigned the port for each server, then create the socket associated to each server
        for i in range(0, len(CtrlServerLst)):
            CtrlPt = CtrlServerLst[i]
            BYTES = CtrlPt.ip.split(
                '.'
            )  # Socket Port number  as port = 43150 + the fourth digit of the IP Address
            Byte4 = int(
                BYTES[3]
            )  # ==> For 192.168.1.100 the port will be 43150 + 100 ==> 43250
            CtrlPt.port = CTE.PORT + Byte4

            self.server = server(CtrlPt.name, CtrlPt.ip, CtrlPt.port)
            self.ServerLst.append(self.server)

            sock = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
            # Use full trace
            print("Create socket for", CtrlPt.name, "IP:", CtrlPt.ip, "PORT:",
                  CtrlPt.port)
            sock.bind((self.ipLocal, CtrlPt.port))
            sock.setblocking(0)
            self.UDPClientSocket.append(sock)
예제 #3
0
                    0]  # Read current value
                minVal = key.getElementsByTagName(TagMin)[0]

                oldMinValue = minVal.firstChild.nodeValue  # Get previous values
                oldMaxValue = maxVal.firstChild.nodeValue
                print("Replacing minValue:" + oldMinValue + " by new value:" +
                      str(MinValue))
                print("Replacing maxValue:" + oldMaxValue + " by new value:" +
                      str(MaxValue))

                minVal.firstChild.nodeValue = MinValue  # Assign new values
                maxVal.firstChild.nodeValue = MaxValue

                with open('ControlServer_test.xml', 'w') as f:
                    f.write(self.doc.toxml())
                    f.close()

                break

        return CtrlPoint


if __name__ == "__main__":
    CTE = Constante("common.h")  # From ParseCommonHeader.py
    CTE.ParseFile()
    CtrlServerLst = []  # ControlServers without the HMI aspect

    XML = XMLConfig(CTE.XML_cfgFile, "Locomotive", "TrackSwitch")
    CtrlServerLst = XML.ParseXML()
    XML.UpdateTrackSwitch(CTE.XML_cfgFile, "192.168.1.108", 0, 11, 111)
예제 #4
0
class ChangeTrim:
    def __init__(self, master, _ControlPoint, NumTrimmer, _commESP): #########################################
        self.allure = 0  # Initially stopped
        self.CTE=Constante("common.h")       # From ParseCommonHeader.py
        self.CTE.ParseFile()
        self.commESP = _commESP  # get the liste of Server, contain only communicationa artefacts
        self.ControlPoint =  _ControlPoint
        self.NumTrimmer   =  NumTrimmer

        self.top = Toplevel(master)  # Link with master window
        self.top.withdraw()  # Dp Not display empty window
        self.top.grab_set()

        self.CreateTrimScale(self.top)

    def SetTrimValueLeft(self, value):
        print("==> LEFT", value)
        self.ControlPoint.TrimLeft[self.NumTrimmer] = value
        self.commESP.MsgForkLeft[1] = self.NumTrimmer+1
        self.commESP.MsgForkLeft[2] = int(value)
        self.commESP.SendData(self.commESP.MsgForkLeft, self.ControlPoint.numCtrlPoint)
        return

    def SetTrimValueRight(self, value):
        print("==> RIGHT", value)
        self.ControlPoint.TrimRight[self.NumTrimmer] = value
        self.commESP.MsgForkRight[1] = self.NumTrimmer+1
        self.commESP.MsgForkRight[2] = int(value)
        self.commESP.SendData(self.commESP.MsgForkRight, self.ControlPoint.numCtrlPoint)
        return

    def ValidateRight(self):
        print("ValidateRight")
        return

    def ValidateLeft(self):
        print("ValidateRight")
        return

    def CreateTrimScale(self, master):

        Head = Canvas(Toplevel(master), bg='light blue', height=600, width=800, borderwidth=5)
        Head.grid(row=1, column=3, sticky='NW', padx=4, pady=4)

        frameTitre = Frame(Head, width=1200, borderwidth = 3, height=30,bg='dark blue', relief="sunken", highlightcolor="red", highlightthickness=2 )
        frameTitre.grid(row=0, column=3)
        LabelTitre = Label(frameTitre, text="*** Set the minimum and maximum values ​​of the servo motors ***", font="Arial 12", height=2, bg='light blue')
        LabelTitre.grid(row=0, column=3)

        Trim = Frame(Head, width=1200, borderwidth=5, height=30, bg='dark blue', relief="sunken",
                             highlightcolor="red", highlightthickness=2)
        Trim.grid(row=4, column=3, rowspan=1, sticky='NW', padx=4, pady=4)

        SetTrim = Frame(Trim, width=1200, height=50, borderwidth=6, bg='light blue', relief="ridge")
        SetTrim.grid(row=3, column=5, sticky='NW')
        Label1 = Label(SetTrim, text=self.ControlPoint.name + '\n' + self.ControlPoint.ip, font="Arial 12", height=3, width=15,
                          bg='light blue')
        Label1.grid(row=1, column=0, rowspan=3, padx=3)

        TrimmerRight = Scale(SetTrim, variable=self.ControlPoint.TrimRight[self.NumTrimmer], resolution=1, orient=HORIZONTAL, length=600,bg='light blue',
                                    showvalue=1, from_=0, to_= 90, tickinterval=5,
                                    command=self.SetTrimValueRight)
        TrimmerRight.set(self.ControlPoint.TrimRight[self.NumTrimmer])
        TrimmerRight.grid(row=1, column=1, columnspan=3)
        TrimmerRight.config(state='active')
        TrimmerRight.lower()
        TxtButton2 = 'RIGHT: '+str(self.ControlPoint.TrimRight[self.NumTrimmer])
        LeftButton = Button(SetTrim, text=TxtButton2,  bg='light blue', command=self.ValidateLeft)
        LeftButton.grid(row=1, column=4)

        QuitButton = Button(SetTrim, text="QUIT-SAVE", command=self.QuitSave)
        QuitButton.grid(row=2, column=4)

        TrimmerLeft = Scale(SetTrim, variable=self.ControlPoint.TrimLeft[self.NumTrimmer], orient=HORIZONTAL, length=600,bg='light blue',
                                      showvalue=25, from_=90, to_=180, tickinterval=5,
                                      command=self.SetTrimValueLeft)
        TrimmerLeft.set(self.ControlPoint.TrimLeft[self.NumTrimmer])
        TrimmerLeft.grid(row=3, column=1, columnspan=3)
        TrimmerLeft.config(state='active')
        TrimmerLeft.lower()


        TxtButton1 = 'LEFT:'+str(self.ControlPoint.TrimLeft[self.NumTrimmer])
        RightButton = Button(SetTrim, text=TxtButton1, bg='light blue', command=self.ValidateRight)
        RightButton.grid(row=3, column=4)

        print("Fin CreateTrimScale")

    def QuitSave(self):
        print("QUIT SAVE")
        minValue=self.ControlPoint.TrimLeft[self.NumTrimmer]
        maxValue=self.ControlPoint.TrimRight[self.NumTrimmer]
        print("ControlPoint:"+self.ControlPoint.name+" NumTrim:",self.NumTrimmer)
        print("TrimLeft, min value: " , minValue)
        print("TrimRight, maxValue: " , maxValue)
        XML = CFG.XMLConfig(self.CTE.XML_cfgFile, " ", "TrackSwitch")

#        def UpdateTrackSwitch(self, xmlFilename, ip, NumSwitch, MinValue, MaxValue):
        XML.UpdateTrackSwitch(self.CTE.XML_cfgFile, self.ControlPoint.ip, self.NumTrimmer, minValue, maxValue)

        self.top.destroy()
예제 #5
0
class UDP_comm:

    CTE = Constante(
        "common.h"
    )  # The message codes are store in the common.h file (shared with server C Code)
    CTE.ParseFile()  # Parse the file and initialize the CTR class.

    # Liste of message of for Power Control (the bytes set 0x00 might be changed by the HMI)
    MsgPowerOrder = bytearray([CTE.PW_CHANGE, 0x00, 0x00, 0x00, 0x00, 0x00])
    MsgLightOn = bytearray([CTE.LIGHT_ORDER, 0x00, 0x00, 0x00, 0x00, 0x00])
    MsgLightOff = bytearray([CTE.LIGHT_ORDER, 0x01, 0x00, 0x00, 0x00, 0x00])
    MsgStopOrder = bytearray([CTE.STOP_ORDER, 0x00, 0x00, 0x00, 0x00, 0x00])
    MsgStartOrder = bytearray([CTE.FWD_ORDER, 0x00, 0x00, 0x00, 0x00, 0x00])
    MsgBackwardOrder = bytearray([CTE.BWD_ORDER, 0x00, 0x00, 0x00, 0x00, 0x00])

    #  Liste of message for Swith Control (the bytes set 0x00 might be changed by the HMI)
    MsgForkRight = bytearray([CTE.FORK_RIGHT, 0x00, 0x00, 0x00, 0x00, 0x00])
    MsgForkLeft = bytearray([CTE.FORK_LEFT, 0x00, 0x00, 0x00, 0x00, 0x00])
    MsgForkMiddle = bytearray([CTE.FORK_MIDDLE, 0x00, 0x00, 0x00, 0x00, 0x00])
    MsgForkSetPos = bytearray([CTE.FORK_SET_POS, 0x00, 0x00, 0x00, 0x00, 0x00])

    def __init__(self, CtrlServerLst):
        i = 0
        # Get the constant from 'common.h' file active.
        CTE = Constante("common.h")
        CTE.ParseFile()

        # Get the host IP address.
        #        if your PC / Host have several Ethernet/IP port,
        #        you might not get the IP address you want !!!!!!!!
        self.ipLocal = socket.gethostbyname(socket.gethostname())

        # The list of Server from
        self.ServerLst = []  # Array of server with IP, Port and name
        self.UDPClientSocket = [
        ]  # Array of the socket created: one per server.

        # Assigned the port for each server, then create the socket associated to each server
        for i in range(0, len(CtrlServerLst)):
            CtrlPt = CtrlServerLst[i]
            BYTES = CtrlPt.ip.split(
                '.'
            )  # Socket Port number  as port = 43150 + the fourth digit of the IP Address
            Byte4 = int(
                BYTES[3]
            )  # ==> For 192.168.1.100 the port will be 43150 + 100 ==> 43250
            CtrlPt.port = CTE.PORT + Byte4

            self.server = server(CtrlPt.name, CtrlPt.ip, CtrlPt.port)
            self.ServerLst.append(self.server)

            sock = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
            # Use full trace
            print("Create socket for", CtrlPt.name, "IP:", CtrlPt.ip, "PORT:",
                  CtrlPt.port)
            sock.bind((self.ipLocal, CtrlPt.port))
            sock.setblocking(0)
            self.UDPClientSocket.append(sock)

    def SendData(self, Msg, numLoco):
        #
        # The ESP32_SendData function is sending data to a given server using UDP
        # After sending the data, the procedure is looking for some acknowledgment message.
        # However there is no error or 'retry' procedure if such message is not received.
        #
        # The 'cpt, cpt1' variables are only there for debugging purpose
        cpt1 = 0
        cpt = 0

        DestAdr = self.ServerLst[numLoco].ip
        port = self.ServerLst[numLoco].port
        self.UDPClientSocket[numLoco].sendto(Msg, (DestAdr, port))
        print("Dest Adr, Port:" + DestAdr + " - " + str(port) + " Msg: " +
              str(Msg[0]) + " - " + str(Msg[1]) + " - " + str(Msg[2]))
        time.sleep(0.100)
        try:
            msg, addr = self.UDPClientSocket[numLoco].recvfrom(
                self.CTE.SIZE_MESSAGE)
            print("<===", msg, cpt)
        except BlockingIOError:
            #        print("IO error")
            cpt1 = cpt1 + 1
        time.sleep(0.100)
        try:
            msg, addr = self.UDPClientSocket[numLoco].recvfrom(
                self.CTE.SIZE_MESSAGE)
            print("<===", msg, cpt)
        except BlockingIOError:
            #        print("IO error")
            cpt1 = cpt1 + 1
예제 #6
0
                              highlightthickness=2)
        frameTitre.grid(row=0, column=14)
        LabelTitre = tk.Label(frameTitre,
                              text="*** Network view ***",
                              font="Arial 14",
                              height=2,
                              bg='light blue')
        LabelTitre.grid(row=0, column=14)

        x = 2
        index = 1
        cptServo = 0
        for _row in range(1, self.Line):
            for _column in range(1, self.Column):
                b1 = tk.Button(frameTitre, text=' ADJUST ', bg='light blue')
                b1.grid(row=_row, column=_column, sticky='NW')


if __name__ == "__main__":
    CTE = Constante("common.h")
    CTE.ParseFile()

    root = tk.Tk()
    hmi = AnimatedIHM(root, 10, 20, 400, 800, "NETWORK")
    root.mainloop()

#    img1 = tk.PhotoImage(file='Montagnarde2.png')
#    can1 = tk.Canvas(root, width = 200, height = 200, bg = 'white')
#    photo =can1.create_image(150,150,image=img1)
#    can1.pack()