示例#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))
示例#2
0
    # discover devices
    devices = comm.Discover()

    for device in devices.Value:
        print(device.IPAddress)
        print('  Product Code: ' + device.ProductName + ' ' +
              str(device.ProductCode))
        print('  Vendor/Device ID:' + device.Vendor + ' ' +
              str(device.DeviceID))
        print('  Revision/Serial:' + device.Revision + ' ' +
              device.SerialNumber)
        print('')

    # get plc time for clx, and compact
    if not is_micro800:
        response = comm.GetPLCTime()
        print(response.Value)

    # ask for a controller / global tag
    controller_tag = input(
        """Enter a controller tag (CLX/Compactlogix), or global variable (Micro8xx):
        Examples:
        tag_name
        array_name[index]
        udt_name.tag_member\n
        """)

    # using new 0.4.0 response object
    # fetch one controller/global tag
    response = read_tag(controller_tag)
    if response.Value is not None: