예제 #1
0
 def __init__(self, plc='clx', ip='0.0.0.0'):
     if plc == 'clx':
         self.driver = ClxDriver()
     if plc == 'slc':
         self.driver = SlcDriver()
     self.ip = ip
     self.open()
예제 #2
0
def check_connection(ip_address):
    d = SlcDriver()
    try:
        if d.open(ip_address):
            return True
    except Exception as e:
        return e
def collect_cwps_data(ip, t_):
    c1 = SlcDriver()
    # t_ = time.time()
    if c1.open(ip):
        dbc.execute('''INSERT into cwps VALUES(?,?,?,?,?)''', \
            (t_, float(c1.read_tag("F8:5")), float(c1.read_tag("F8:15")), float(c1.read_tag("F8:7")), float(c1.read_tag("F8:4"))))

        # print(t_, float(c1.read_tag("F8:5")), float(c1.read_tag("F8:15")), float(c1.read_tag("F8:7")), float(c1.read_tag("F8:4")))
    conn.commit()
예제 #4
0
class Slc:
    def __init__(self):
        self.cur = SlcDriver()
        self.ip_address = None

    def set_ip_address(self, ip):
        self.ip_address = ip

    def open_connection(self):
        self.cur.open(self.ip_address)

    def close_connection(self):
        self.cur.close()

    def get_tag_value(self, tag):
        return self.cur.read_tag(tag)

    def check_tag(self, tag):
        if self.ip_address:
            self.open_connection()
            try:
                if self.cur.read_tag(tag):
                    self.close_connection()
                    return True
            except Exception as e:
                self.close_connection()
                return False
예제 #5
0
    def _poll(self):
        """The blocking function pinging the plc for data.

        This scrapes all endpoints every n seconds and publishes
        the received data.
        """
        endpoints = []
        for a, v in self._endpoints.items():
            for t in v:
                endpoints.append((a, t))
        c = SlcDriver()
        Logger.info('Starting polling of PLCs', fields={
            'poll_interval': self._poll_interval,
        })
        while self._run:
            Logger.trace('starting polling iteration')
            for address, tag_name in endpoints:
                Logger.trace('reading', fields={
                    'address': address,
                    'tag_name': tag_name,
                })
                timestamp, value = None, None
                if c.open(address):
                    timestamp = datetime.now()
                    value = c.read_tag(tag_name)
                    Logger.trace('received value', fields={
                        'timestamp': timestamp.isoformat(),
                        'value': value,
                    })
                else:
                    Logger.warning('Failed connecting to PLC', fields={
                        'address': address,
                        'tag': tag_name
                    })
                c.close()
                if timestamp is not None and value is not None:
                    self._publish(address, tag_name, timestamp, value)
            time.sleep(self._poll_interval)
예제 #6
0
    def __init__(self):
        self.cur = SlcDriver()

        self.ip_address = None
        self.operators = None
        self.barcode = ''
        self.status_from_plc = 'B3:4/13'
        self.ready_status_to_plc = 'B3:4/14'
        self.current_operator_tag = 'N7:0'
        self.current_operator_str = None

        self.tag_dict = {
            'B3:4/10': None,
            'B3:4/11': None,
            'B3:4/2': None,
            'B3:4/3': None,
            'B3:4/4': None,
            'B3:4/5': None,
            'B3:4/6': None,
            'B3:4/7': None,
            'B3:4/8': None,
            'B3:4/9': None,
            'B3:4/0': None,
            'B3:4/1': None,
            'F8:5': None,
            'F8:6': None,
            'F8:7': None,
            'F8:8': None,
            'F8:9': None,
            'F8:10': None,
            'F8:11': None,
            'F8:12': None,
            'F8:13': None,
            'F8:14': None,
            'F8:15': None,
            'F8:16': None,
            'F8:17': None,
            'F8:18': None,
            'F8:19': None,
            'F8:20': None,
            'F8:21': None,
            'F8:22': None
        }

        self.barcode_words = [
            'B11:0', 'B11:1', 'B11:2', 'B11:3', 'B11:4', 'B11:5', 'B11:6',
            'B11:7', 'B11:8', 'B11:9'
        ]
예제 #7
0
    def __init__(self, ip_address=None, mode=DRY_RUN):
        self.ip_address = ip_address or None
        self.mode = mode
        self.done = False

        if self.mode == PRODUCTION:
            self.plc = Driver()
        else:
            self.plc = Simulator()
        try:
            connected = self.plc.open(self.ip_address)
            if not connected:
                msg = 'Failed to connect to {}'.format(self.ip_address)
                raise ConnectionException(msg)
        except ConnectionException as e:
            print(e.msg)

        self.write_tag = self.plc.write_tag
        self.read_tag = self.plc.read_tag

        super(Controller, self).__init__(dimx=DIMX,
                                         dimy=DIMY,
                                         dimz=DIMZ)
예제 #8
0
__author__ = 'agostino'

from pycomm.ab_comm.slc import Driver as SlcDriver


if __name__ == '__main__':
    c = SlcDriver(True, 'delete_slc.log')
    if c.open('172.16.2.160'):

        while 1:
            try:
                print c.read_tag('S:1/5')
                print c.read_tag('S:60', 2)

                print c.write_tag('N7:0', [-30, 32767, -32767])
                print c.write_tag('N7:0', 21)
                print c.read_tag('N7:0', 10)

                print c.write_tag('F8:0', [3.1, 4.95, -32.89])
                print c.write_tag('F8:0', 21)
                print c.read_tag('F8:0', 3)

                print c.write_tag('B3:100', [23, -1, 4, 9])
                print c.write_tag('B3:100', 21)
                print c.read_tag('B3:100', 4)

                print c.write_tag('T4:3.PRE', 431)
                print c.read_tag('T4:3.PRE')
                print c.write_tag('C5:0.PRE', 501)
                print c.read_tag('C5:0.PRE')
                print c.write_tag('T4:3.ACC', 432)
예제 #9
0
__author__ = 'agostino'

from pycomm.ab_comm.slc import Driver as SlcDriver
import logging
import time

if __name__ == '__main__':
    logging.basicConfig(filename="SlcDriver.log",
                        format="%(levelname)-10s %(asctime)s %(message)s",
                        level=logging.DEBUG)
    c = SlcDriver()
    if c.open('10.0.0.252'):

        while 1:
            time.sleep(2)
            try:
                #print(c.read_tag('S:1/5'))
                # print c.read_tag('S:60', 2)
                #
                #print(c.write_tag('N7:0', [-30, 32767, -32767]))
                print "Write N7:0 ", c.write_tag('N7:0', 21)
                print "Read N7:0 ", c.read_tag('N7:0', 1)
                print "Read N7:1 ", c.read_tag('N7:1', 1)

                # print c.write_tag('F8:0', [3.1, 4.95, -32.89])
                # print c.write_tag('F8:0', 21)
                # print c.read_tag('F8:0', 3)
                #
                # print c.write_tag('B3:100', [23, -1, 4, 9])
                print c.write_tag('B3:0', 511)
                print "Read B3:0", c.read_tag('B3:0', 1)
예제 #10
0
        c = conn.cursor()
        print c.execute("INSERT INTO conveyor_signal (ID, signal_diff, "
                        "sig_datetime) "
                        "VALUES (?, 0, ?)", (signal, now))


def update_signal(cursor, table, values):
    cursor.execute("UPDATE {} SET ID=?, signal_diff=?, sig_datetime=? "
                   "WHERE ID=?".format(table), values)
    conn.commit()

table_create(cursor, 'conveyor_signal')
initialize_signal(0)
initialize_signal(1)

c = SlcDriver()
if c.open('128.1.0.123'):
    signal_on = None
    signal_off = None
    now = None
    signal_on_time = None
    signal_off_time = None
    conveyor_time = timedelta(0, 0, 0)
    cycle_time = timedelta(0, 0, 0)
    while True:
        start_time = datetime.now()
        tag = c.read_tag('B3:0/2')
        if tag and signal_off:
            signal_off = False
            if signal_on_time is None:
                signal_on_time = datetime.now()
def collect_wsc_data(ip, t_):
    c2 = SlcDriver()
    if c2.open(ip):
        dbc.execute('''INSERT into wsc1_rwp VALUES(?,?,?,?,?,?)''', \
            (t_, float(c2.read_tag("F8:20")), float(c2.read_tag("F8:23")), \
                float(c2.read_tag("F8:22")), float(c2.read_tag("F8:2")), float(c2.read_tag("F8:1"))))

        dbc.execute('''INSERT into wsc1_fwp VALUES(?,?,?,?,?,?)''', \
            (t_, float(c2.read_tag("F8:5")), float(c2.read_tag("F8:15")), \
                float(c2.read_tag("F8:7")), float(c2.read_tag("F8:4")), float(c2.read_tag("F8:0"))))

    conn.commit()
예제 #12
0
class Simulador():

    DEBUG = True

    def __init__(self, plc='clx', ip='0.0.0.0'):
        if plc == 'clx':
            self.driver = ClxDriver()
        if plc == 'slc':
            self.driver = SlcDriver()
        self.ip = ip
        self.open()

    def open(self):
        try:
            self.driver.open(self.ip)
        except:
            self.error(0)
        else:
            return True

    def error(self, code):
        if code == 0:
            self.log('Could not connect to IP')

    def log(self, message):
        if self.DEBUG == True:
            print(message)
        with open('log', 'w') as f:
            f.write(message)
            f.close()

    def simular(self, time_step=1):
        self.seconds = 0
        self.minutes = 0
        self.hours = 0
        self.days = 0

        while True:
            exec_start = time()
            print(self.step_clock(1))

            delta = time() - exec_start
            self.wait_step(delta, time_step)

    def step_clock(self, step):
        self.seconds += step
        if self.seconds >= 60:
            self.minutes += floor(self.seconds / 60)
            self.seconds = self.seconds % 60
        if self.minutes >= 60:
            self.hours += floor(self.minutes / 60)
            self.minutes = self.minutes % 60
        if self.hours >= 24:
            self.days += floor(self.hours / 24)
            self.hours = self.hours % 24
        return (self.days, self.hours, self.minutes, self.seconds)

    def wait_step(self, delta, step):
        if delta > step:
            self.error(1)
            return False
        sleep(step - delta)

    # funcao para transformar inteiro em array de binarios
    def formatar_binario(self, inteiro, numero_bits):
        b = []
        if numero_bits == 32:
            for n in '{0:032b}'.format(inteiro):
                b.append(int(n))
        if numero_bits == 16:
            for n in '{0:016b}'.format(inteiro):
                b.append(int(n))
        b.reverse()
        return b

    # funcao para transformar array de binarios em inteiro
    def formatar_inteiro(self, array_binario):
        array_binario.reverse()
        binario = ''
        for b in array_binario:
            binario = binario + str(b)
        decimal = 0
        for digito in binario:
            decimal = decimal * 2 + int(digito)
        return decimal
예제 #13
0
from pycomm.ab_comm.slc import Driver as SlcDriver
import logging
from time import sleep

test_dict = {'B3:4/3': None, 'B3:4/2': None}

c = SlcDriver()
if c.open('192.168.1.20'):
    for key in test_dict.keys():
        test_dict[key] = c.read_tag(key)

print test_dict

# ************************************************************************************************

# stuff = ''
#
# test_list = [1, 2, 3, 4]
#
# for val in test_list:
#     stuff += str(val)
#
# print stuff

# ************************************************************************************************

# from communications import HeliosStation
# import configparser
#
#
# class FileParser:
예제 #14
0
 def __init__(self):
     self.cur = SlcDriver()
     self.ip_address = None
예제 #15
0
#
# 	There Is No Such Thing As Free Beer 1.0
#
#########################################################
from pycomm.ab_comm.slc import Driver as SlcDriver
import time

# Argument Checking
if (len(sys.argv) != 2):
    print("USAGE: python ./tinstafb.py <host> <left|right|lock>")
    sys.exit()

host = sys.argv[1]
command = sys.argv[2]

c = SlcDriver()
if c.open(host):

    if command == "left":
        # Left tap on
        c.write_tag('B3:0/0', 1)
        # Pour the perfect beer
        time.sleep(5)
        # left tap off
        c.write_tag('B3:0/0', 0)
    elif command == "right":
        # right tap on
        c.write_tag('B3:0/1', 1)
        # Pour the perfect beer
        time.sleep(5)
        # right tap off
예제 #16
0
import sys
import time
sys.path.append('../')

from pycomm.ab_comm.slc import Driver as SlcDriver
import logging

if __name__ == '__main__':
    logging.basicConfig(format="%(levelname)-10s %(message)s",
                        level=logging.DEBUG)
    c = SlcDriver()
    if c.open('localhost'):
        print('connected')
        print(c.read_tag('F11:0'))
        print(c.read_tag('F11:1'))
        time.sleep(1)
        print(c.read_tag('F11:1'))
        print(c.read_tag('F11:0'))
예제 #17
0
class HeliosBridge:
    def __init__(self):
        self.cur = SlcDriver()

        self.ip_address = None
        self.operators = None
        self.barcode = ''
        self.status_from_plc = 'B3:4/13'
        self.ready_status_to_plc = 'B3:4/14'
        self.current_operator_tag = 'N7:0'
        self.current_operator_str = None

        self.tag_dict = {
            'B3:4/10': None,
            'B3:4/11': None,
            'B3:4/2': None,
            'B3:4/3': None,
            'B3:4/4': None,
            'B3:4/5': None,
            'B3:4/6': None,
            'B3:4/7': None,
            'B3:4/8': None,
            'B3:4/9': None,
            'B3:4/0': None,
            'B3:4/1': None,
            'F8:5': None,
            'F8:6': None,
            'F8:7': None,
            'F8:8': None,
            'F8:9': None,
            'F8:10': None,
            'F8:11': None,
            'F8:12': None,
            'F8:13': None,
            'F8:14': None,
            'F8:15': None,
            'F8:16': None,
            'F8:17': None,
            'F8:18': None,
            'F8:19': None,
            'F8:20': None,
            'F8:21': None,
            'F8:22': None
        }

        self.barcode_words = [
            'B11:0', 'B11:1', 'B11:2', 'B11:3', 'B11:4', 'B11:5', 'B11:6',
            'B11:7', 'B11:8', 'B11:9'
        ]

    def _open_connection(self):
        self.cur.open(self.ip_address)

    def _close_connection(self):
        self.cur.close()

    # Delete this
    def read_test(self):
        return self.cur.read_tag('B3:0/0')

    def check_connection(self):
        try:
            if self.cur.open(self.ip_address):
                connection_state = True
                self.cur.close()
                return connection_state
        except Exception as e:
            return False

    def set_ip_address(self, ip):
        self.ip_address = ip

    def get_ip_address(self):
        return self.ip_address

    def set_operators(self, operators):
        self.operators = operators

    def get_operators(self):
        return self.operators

    def set_current_operator(self):
        self._open_connection()
        operator_int = self.cur.read_tag(self.current_operator_tag)
        self._close_connection()

        if operator_int == 0:
            self.current_operator_str = 'None'
        else:
            self.current_operator_str = self.operators[operator_int - 1]

    def get_current_operator(self):
        return self.current_operator_str

    def clear_current_operator(self):
        self.current_operator_str = None

    def get_plc_test_status(self):
        return self.cur.read_tag(self.status_from_plc)

    def set_plc_ready_status(self):
        self.cur.write_tag(self.ready_status_to_plc, 1)

    def set_tag_values(self):
        self._open_connection()
        for key in self.tag_dict.keys():
            self.tag_dict[key] = self.cur.read_tag(key)
        self._close_connection()

    def get_tag_values(self):
        return self.tag_dict

    def clear_tag_values(self):
        self.tag_dict = {
            'B3:4/10': None,
            'B3:4/11': None,
            'B3:4/2': None,
            'B3:4/3': None,
            'B3:4/4': None,
            'B3:4/5': None,
            'B3:4/6': None,
            'B3:4/7': None,
            'B3:4/8': None,
            'B3:4/9': None,
            'B3:4/0': None,
            'B3:4/1': None,
            'F8:5': None,
            'F8:6': None,
            'F8:7': None,
            'F8:8': None,
            'F8:9': None,
            'F8:10': None,
            'F8:11': None,
            'F8:12': None,
            'F8:13': None,
            'F8:14': None,
            'F8:15': None,
            'F8:16': None,
            'F8:17': None,
            'F8:18': None,
            'F8:19': None,
            'F8:20': None,
            'F8:21': None,
            'F8:22': None
        }

    def set_barcode(self):
        self._open_connection()
        for word in self.barcode_words:
            self.barcode += str(self.cur.read_tag(word))
        self._close_connection()

    def get_barcode(self):
        return self.barcode

    def clear_barcode(self):
        self.barcode = ''
예제 #18
0
__author__ = 'agostino'

from pycomm.ab_comm.slc import Driver as SlcDriver
import logging

if __name__ == '__main__':
    logging.basicConfig(filename="SlcDriver.log",
                        format="%(levelname)-10s %(asctime)s %(message)s",
                        level=logging.DEBUG)
    c = SlcDriver()
    if c.open('192.168.1.15'):

        while 1:
            try:
                print c.read_tag('S:1/5')
                print c.read_tag('S:60', 2)

                print c.write_tag('N7:0', [-30, 32767, -32767])
                print c.write_tag('N7:0', 21)
                print c.read_tag('N7:0', 10)

                print c.write_tag('F8:0', [3.1, 4.95, -32.89])
                print c.write_tag('F8:0', 21)
                print c.read_tag('F8:0', 3)

                print c.write_tag('B3:100', [23, -1, 4, 9])
                print c.write_tag('B3:100', 21)
                print c.read_tag('B3:100', 4)

                print c.write_tag('T4:3.PRE', 431)
                print c.read_tag('T4:3.PRE')
예제 #19
0
#!/usr/bin/python

from pycomm.ab_comm.slc import Driver as SlcDriver
from time import sleep
import logging
import sys

#logging.basicConfig(
#   level=logging.DEBUG
#)

c = SlcDriver()

def write_data(num, val):
  print "Write data: %d" % val
  c.write_tag('B1:%d' % num, val)

def read_tap(num):
  print c.read_tag('B1:%d' % num)[3]

val=int(sys.argv[1])

if c.open('10.10.10.1'):
  #write_data(1, val)
  #sleep(5)
  read_tap(1)

#c.close()
예제 #20
0
파일: tinstafb.py 프로젝트: sjhilt/scripts
#
# 	There Is No Such Thing As Free Beer 1.0
#
#########################################################
from pycomm.ab_comm.slc import Driver as SlcDriver
import time

# Argument Checking
if (len(sys.argv) != 2): 
	print("USAGE: python ./tinstafb.py <host> <left|right|lock>")
	sys.exit()
	
host=sys.argv[1]
command=sys.argv[2]

c = SlcDriver()
if c.open(host):

  if command == "left":
    # Left tap on
    c.write_tag('B3:0/0', 1)
    # Pour the perfect beer
    time.sleep(5)
    # left tap off
    c.write_tag('B3:0/0', 0)
  elif command == "right":
    # right tap on
    c.write_tag('B3:0/1', 1)
    # Pour the perfect beer
    time.sleep(5)
    # right tap off
예제 #21
0
            "sig_datetime) "
            "VALUES (?, 0, ?)", (signal, now))


def update_signal(cursor, table, values):
    cursor.execute(
        "UPDATE {} SET ID=?, signal_diff=?, sig_datetime=? "
        "WHERE ID=?".format(table), values)
    conn.commit()


table_create(cursor, 'conveyor_signal')
initialize_signal(0)
initialize_signal(1)

c = SlcDriver()
if c.open('128.1.0.123'):
    signal_on = None
    signal_off = None
    now = None
    signal_on_time = None
    signal_off_time = None
    conveyor_time = timedelta(0, 0, 0)
    cycle_time = timedelta(0, 0, 0)
    while True:
        start_time = datetime.now()
        tag = c.read_tag('B3:0/2')
        if tag and signal_off:
            signal_off = False
            if signal_on_time is None:
                signal_on_time = datetime.now()