Beispiel #1
0
def connect(num, state):
    if (state):
        if (num == 1):
            try:
                global EIP_1, C_A
                EIP_1 = pyeip.EtherNetIP(hostname1)
                C_A = EIP_1.explicit_conn(hostname1)
            except TimeoutError:
                C_A = 1
        elif (num == 2):
            try:
                global EIP_2, C_B
                EIP_2 = pyeip.EtherNetIP(hostname2)
                C_B = EIP_2.explicit_conn(hostname2)
            except TimeoutError:
                C_B = 1
        elif (num == 3):
            try:
                global EIP_3, C_C
                EIP_3 = pyeip.EtherNetIP(hostname3)
                C_C = EIP_3.explicit_conn(hostname3)
            except TimeoutError:
                C_C = 1
    else:
        if (num == 1):
            C_A = 1
        elif (num == 2):
            C_B = 1
        elif (num == 3):
            C_C = 1
Beispiel #2
0
def check_connection(c, ITV):
    if c.isChecked() == True:  #executes if checkbox is checked
        if ITV == 1:  #ITV variable selects which ITV should be connected
            #print("Attempting to connect...")
            try:  #attempt to connect ITV1
                global EIP_1, C_A
                EIP_1 = pyeip.EtherNetIP(hostname1)
                C_A = EIP_1.explicit_conn(hostname1)
            except Exception:  #general catch-all error handler, triggers if no connection detected
                C_A = 1  #set C_A back to disconnected state
        elif ITV == 2:  # checks whatever ITV is specified by variable ITV (passed in from checkbox)
            #print("Attempting to connect...")
            try:
                global EIP_2, C_B
                EIP_2 = pyeip.EtherNetIP(hostname2)
                C_B = EIP_2.explicit_conn(hostname2)
            except Exception:
                C_B = 1
        elif ITV == 3:
            #print("Attempting to connect...")
            try:
                global EIP_3, C_C
                EIP_3 = pyeip.EtherNetIP(hostname3)
                C_C = EIP_3.explicit_conn(hostname3)
            except Exception:
                C_C = 1
    else:  #no connection found, set C_# to non-connected state
        #print("Not Connected")
        if ITV == 1:
            C_A = 1
        elif ITV == 2:
            C_B = 1
        elif ITV == 3:
            C_C = 1
Beispiel #3
0
    def check_connection(self, c, ITV):
        if c.isChecked() == True:
            if ITV == 1:
                print("Attempting to connect...")
                try:
                    global EIP_1, C_A
                    EIP_1 = pyeip.EtherNetIP(hostname1)
                    C_A = EIP_1.explicit_conn(hostname1)
                    print(C_A)
                except TimeoutError:
                    C_A = 1
            elif ITV == 2:
                print("Attempting to connect...")
                try:
                    global EIP_2, C_B
                    EIP_2 = pyeip.EtherNetIP(hostname2)
                    C_B = EIP_2.explicit_conn(hostname2)
                    print(C_B)
                except TimeoutError:
                    C_B = 1
            elif ITV == 3:
                print("Attempting to connect...")
                try:
                    global EIP_3, C_C
                    EIP_3 = pyeip.EtherNetIP(hostname3)
                    C_C = EIP_3.explicit_conn(hostname3)
                    print(C_C)
                except TimeoutError:
                    C_C = 1

        else:
            print("Not Connected")
            if ITV == 1:
                C_A = 1
            elif ITV == 2:
                C_B = 1
            elif ITV == 3:
                C_C = 1
Beispiel #4
0
 def CheckResponse(self,c,ITV):
     if c.isChecked() == True and ITV_A_Net_Status == True:
         SetPoint = value
         x = SetPoint.to_bytes(2, "little") #change to bytes
         data = pyeip.struct.pack("BB", x[0], x[1])
         if C_A != 1:
             print("Write to 1")
             r = C_A.setAttrSingle(0x64, 0x64, 0x03, data) #write to ITV
             if r[0] == 0:
                 print("Wrote!")
             else:
                 print("Failed to write")
             r = C_A.getAttrSingle(0x96, 0x96, 0x03)
             print(r[1])
             if 0 == r[0]:
                 print(int.from_bytes(r[1],"little"))
                 if(r[1][-2:] == b'\x00\x00'):
                     pressure = int.from_bytes(r[1],"little") #in counts
                     pressure = pressure / 31.37 #convert to psi
                     pressure = round(pressure, 3)
                     print(pressure)
                     self.label_ITV_A.setText("ITV 1 (psi): " + str(pressure))
                 else:
                     self.label_ITV_A.setText("ITV 1 (psi): Error Detected")
                     
     elif c.isChecked() == True and ITV_A_Net_Status == False:
         print("Attempting to connect...")
         try:
             global EIP_1
             EIP_1= pyeip.EtherNetIP(hostname1)
             C_A = EIP_1.explicit_conn(hostname1)
             ITV_A_Net_Status == True
             print("ITV 1 connected")
         except TimeoutError:
             ITV_A_Net_Status == False
             C_A = 1
     else:
         print("You're kinda SOL")
         if ITV == 1:
             C_A = 1
         elif ITV == 2:
             C_B = 1
         elif ITV == 3:
             C_C = 1
Beispiel #5
0
# Form implementation generated from reading ui file 'control_ITV.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.

from PyQt5 import QtCore, QtGui, QtWidgets
import pyeip
import time
import tkinter

hostname1 = "192.168.1.20"
hostname2 = "192.168.1.21"
hostname3 = "192.168.1.22"
EIP_1 = pyeip.EtherNetIP(hostname1)
EIP_2 = pyeip.EtherNetIP(hostname2)
EIP_3 = pyeip.EtherNetIP(hostname3)
##global C_A
##global C_B
##global C_C
C_A = 1  #defult value
C_B = 1  #defult value
C_C = 1  #defult value
high = 4095
low = 0
ITV_A_Net_Status = False
value = high


class Ui_MainWindow(object):
Beispiel #6
0
#Library to Generate Set and Get EIP packagees
import pyeip

#variables
hostname = "192.168.1.20"
EIP = pyeip.EtherNetIP(hostname)
C1 = EIP.explicit_conn(hostname)
high = 4095
low = 0

#Get Setpoint
SetPoint = int(input("Enter Setpoint: "))
x = SetPoint.to_bytes(2, "little")
#path = C1.mkReqPath(0x1, 1, None)
data = pyeip.struct.pack("BB", x[0], x[1])

r = C1.setAttrSingle(0x64, 0x64, 0x03, data)
if 0 == r[0]:
    #print(int.from_bytes(r[1],"little"))
    print("Wrote!")
else:
    print("Failed to write")

r = C1.getAttrSingle(0x96, 0x96, 0x03)
if 0 == r[0]:
    print(int.from_bytes(r[1], "little"))
else:
    print("Failed to read")