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
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()
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()
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)
__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')
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'))
__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)
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) # # 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)
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() else: signal_on_time = datetime.now() conveyor_time = signal_on_time - signal_off_time update_signal(cursor, 'conveyor_signal', (1, conveyor_time.total_seconds(), signal_on_time, 1)) elif not tag and signal_on: signal_on = False if signal_on_time is None: signal_off_time = datetime.now() else:
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() else: signal_on_time = datetime.now() conveyor_time = signal_on_time - signal_off_time update_signal( cursor, 'conveyor_signal', (1, conveyor_time.total_seconds(), signal_on_time, 1)) elif not tag and signal_on: signal_on = False if signal_on_time is None: signal_off_time = datetime.now() else:
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 = ''
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: