Ejemplo n.º 1
0
def comm_check():
    global comm
    global updateRunning
    global connected
    global connectionInProgress

    try:
        connectionInProgress = True
        ip = selectedIPAddress.get()
        port = int(selectedProcessorSlot.get())

        if (not connected or comm.IPAddress != ip or comm.ProcessorSlot != port or changePLC.get() == 1):
            if not comm is None:
                comm.Close()
                comm = None

            comm = PLC()
            comm.IPAddress = ip

            if checkVarMicro800.get() == 0:
                comm.ProcessorSlot = port
                comm.Micro800 = False
            else:
                comm.Micro800 = True

            plcTime = comm.GetPLCTime()

            lbConnectionMessage.delete(0, 'end')
            lbErrorMessage.delete(0, 'end')

            if plcTime.Value is None:
                if btnStop['state'] == 'disabled':
                    btnStart['state'] = 'disabled'
                    btnStart['bg'] = 'lightgrey'
                lbConnectionMessage.insert(1, ' Not Connected')
                lbErrorMessage.insert(1, ' ' + plcTime.Status)
                connected = False
                root.after(5000, start_connection)
            else:
                lbConnectionMessage.insert(1, ' Connected')
                if not updateRunning:
                    updateRunning = True

                connected = True
                connectionInProgress = False

                if btnStop['state'] == 'disabled':
                    btnStart['state'] = 'normal'
                    btnStart['bg'] = 'lightgreen'
                else:
                    start_update()

        changePLC.set(0)
    except Exception as e:
        if app_closing:
            pass
        else:
            print(str(e))
Ejemplo n.º 2
0
def comm_check():
    global comm

    ip = selectedIPAddress.get()
    port = int(selectedProcessorSlot.get())

    if (comm.IPAddress != ip or comm.ProcessorSlot != port):
        comm.Close()
        comm = None
        comm = PLC()
        comm.IPAddress = ip
        comm.ProcessorSlot = port
Ejemplo n.º 3
0
def getTags():
    try:
        lbTags.delete(0, 'end')

        commGT = PLC()
        commGT.IPAddress = selectedIPAddress.get()
        if checkVarMicro800.get() == 0:
            commGT.ProcessorSlot = int(selectedProcessorSlot.get())

        tags = commGT.GetTagList()

        if not tags is None:
            if not tags.Value is None:
                # save tags to a file
                if checkVarSaveTags.get() == 1:
                    with open('tags_list.txt', 'w') as f:
                        for t in tags.Value:
                            if t.DataType == '':
                                f.write(t.TagName + '\n')
                            else:
                                f.write(t.TagName + ' (DataType - ' + t.DataType + ')\n')

                for t in tags.Value:
                    j = 1
                    if t.DataType == '':
                        lbTags.insert(j, t.TagName)
                    else:
                        lbTags.insert(j, t.TagName + ' (DataType - ' + t.DataType + ')')
                    j = j + 1
            else:
                lbTags.insert(1, 'No Tags Retrieved')
        else:
            lbTags.insert(1, 'No Tags Retrieved')

        commGT.Close()
        commGT = None
    except Exception as e:
        if not commGT is None:
            commGT.Close()
            commGT = None

        if app_closing:
            pass
        else:
            print(str(e))
Ejemplo n.º 4
0
from pylogix import PLC
from ping3 import ping
import sys
import time


def read_tag(tag):
    return comm.Read(tag)


# Setup the PLC object with initial parameters
comm = PLC()
controller_ip = '192.168.176.1'  # Change to your plc ip address
controller_slot = 1  # Change to your plc slot number, Only do this if slot is not 0
comm.IPAddress = controller_ip
comm.ProcessorSlot = controller_slot

# ensure plc is pingable, else exit the program
if ping(controller_ip) is None:
    print("Controller unreachable, check pc ip settings")
    sys.exit()

# try to read a tag, else print error
try:
    while True:
        value = read_tag('bool_01')
        time.sleep(1)  # Change seconds here
        print(value)  # Do Ctrl + C to interrupt process
except NameError as e:
    print(e)
except ValueError as e:
Ejemplo n.º 5
0
    /_____/_/    \____/

    """
    print(ascii_art)
    print("Data Preserve Utility " + CODE_VERSION)
    print("Author: Fernando ***REMOVED***")
    print("Source: " + "https://github.com/TheFern2/Data_Preserve")


if __name__ == '__main__':

    config = configparser.ConfigParser()
    config.read('Settings.ini')
    main_controller_ip = config['Settings']['PLC_IP']
    comm.IPAddress = main_controller_ip
    comm.ProcessorSlot = int(config['Settings']['PLC_SLOT'])
    dp_save_remote_path = config['Settings']['Remote_Save_Path']
    dp_save_local_path = config['Settings']['Local_Save_Path']
    file_extension = config['Settings']['Files_Extension']

    # load remote file names from ini
    for key in config['Remote_Files']:
        remote_files.append(config['Remote_Files'][key])

    # load local file names from ini
    for key in config['Local_Files']:
        local_files.append(config['Local_Files'][key])

    for key in config['Folder_Copy_On_Load']:
        paths_on_load.append(config['Folder_Copy_On_Load'][key])
Ejemplo n.º 6
0
'''
the following import is only necessary because eip is not in this directory
'''
import sys
sys.path.append('..')


'''
The simplest example of reading a tag from a PLC

NOTE: You only need to call .Close() after you are done exchanging
data with the PLC.  If you were going to read in a loop or read
more tags, you wouldn't want to call .Close() every time.
'''
from pylogix import PLC

comm = PLC()
comm.IPAddress = '192.168.111.249'
comm.ProcessorSlot = 3 
value = comm.Read('Dest_IP')
print(value)
comm.Close()