Esempio n. 1
0
def timeTestforReadWrite():
    '''
    testing the time to read and write to the PLC
    '''
    from pylogix import PLC
    import time
    DiamondElements = PLC('192.168.1.10')  #AB PLC IP Address

    count = 0
    targetCycleCount = 1000

    startTime = time.time()
    """
    read the bool, write its opposite value, read it again.
    """
    while True:

        returnedValue = DiamondElements.Read('IO_NEEDED_HERE')

        print('Currently read value of ' + returnedValue.TagName + ': ' +
              str(returnedValue.Value))

        if returnedValue.Value == True:
            boolToWrite = 0
        else:
            boolToWrite = 1

        DiamondElements.Write('IO_NEEDED_HERE', boolToWrite)

        newReturnedValue = DiamondElements.Read('IO_NEEDED_HERE')

        print('New value after writing: ' + str(newReturnedValue.Value))

        if count >= targetCycleCount:
            break

        count += 1

    EndTime = time.time()
    totalTime = EndTime - startTime
    print(f"{totalTime:.4f} seconds with {targetCycleCount} read/write cycles")
Esempio n. 2
0
def ReadOutWord():
    comm = PLC()
    comm.IPAddress = '169.254.215.82'
    value = comm.Read('OutWord')
    lbl3 = Label(window,
                 text="OutWord|Value",
                 bg="white",
                 fg="Black",
                 bd=2,
                 relief="solid",
                 width=15,
                 height=2)
    lbl3.place(x=410, y=20)
    lbl4 = Label(window,
                 text=value,
                 bg="Black",
                 fg="lime",
                 bd=3,
                 relief="raised",
                 width=15,
                 height=5)
    lbl4.place(x=410, y=60)
    window.after(550, ReadOutWord)
    return
Esempio n. 3
0
def ReadSEQCount():
    comm = PLC()
    comm.IPAddress = '169.254.215.82'
    valueseqcount = comm.Read('SEQCount')
    lbl6 = Label(window,
                 text="Sequence Count",
                 bg="white",
                 fg="Black",
                 bd=2,
                 relief="solid",
                 width=15,
                 height=2)
    lbl6.place(x=540, y=180)
    lbl7 = Label(window,
                 text=valueseqcount,
                 bg="Black",
                 fg="lime",
                 bd=3,
                 relief="raised",
                 width=15,
                 height=5)
    lbl7.place(x=540, y=220)
    window.after(550, ReadSEQCount)
    return
Esempio n. 4
0

'''
Read a list of tags at once

Reading lists and arrays is much more efficient than
reading them individually. You can create a list of tags
and pass it to .Read() to read them  all in one packet.
The values returned will be in the same order as the tags
you passed to Read()

NOTE:  Packets have a ~500 byte limit, so you have to be cautions
about not exceeding that or the read will fail.  It's a little
difficult to predict how many bytes your reads will take up becuase
the send packet will depend on the length of the tag name and the
reply will depened on the data type.  Strings are a lot longer than
DINT's for example.

I'll usually read no more than 5 strings at once, or 10 DINT's)
'''
from pylogix import PLC

tag_list = ['Zone1ASpeed', 'Zone1BSpeed', 'Zone2ASpeed', 'Zone2BSpeed', 'Zone3ASpeed', 'Zone3BSpeed',
            'Zone4ASpeed', 'ZOne4BSpeed', 'Zone1Case', 'Zone2Case']

with PLC() as comm:
    comm = PLC()
    comm.IPAddress = '192.168.1.9'
    value = comm.Read(tag_list)
    print(value)
Esempio n. 5
0
def get_tag(tag, ipAddress, slot):
    comm = PLC(ipAddress, slot)
    regularTags = []
    arrayTags = dict()
    results = []
    readArray = False
    arrayElementCount = 0
    showBoolAsOneZero = False

    if tag.startswith('[') and tag.endswith(']'):  # array of mixed tags
        tags = (tag[1:-1].replace(' ', '')).split(';')

        for t in tags:
            if not t == '':
                if t.endswith(
                        '}') and '{' in t:  # 1 or 2 or 3 dimensional array tag
                    try:
                        arrayElementCount = int(t[t.index('{') +
                                                  1:t.index('}')])
                        readArray = True
                        t = t[:t.index('{')]
                        arrayTags.update({t: arrayElementCount})
                    except:
                        pass
                else:
                    regularTags.append(t)

        if len(regularTags) > 0:
            ret = comm.Read(regularTags)

            if ret[0].Value is None:
                comm.Close()
                return jsonify(ret[0].Status)

            for i in range(0, len(ret)):
                if showBoolAsOneZero and (str(ret[i].Value) == 'True'
                                          or str(ret[i].Value) == 'False'):
                    results.append({
                        "tagName":
                        str(ret[i].TagName),
                        "value":
                        1 if str(ret[i].Value) == 'True' else 0,
                        "status":
                        str(ret[i].Status)
                    })
                else:
                    results.append({
                        "tagName": str(ret[i].TagName),
                        "value": str(ret[i].Value),
                        "status": str(ret[i].Status)
                    })

        if len(arrayTags) > 0:
            for tag in arrayTags:
                ret = comm.Read(tag, arrayTags[tag])

                if ret.Value is None:
                    comm.Close()
                    return jsonify(ret.Status)

                if showBoolAsOneZero and (str(ret.Value[0]) == 'True'
                                          or str(ret.Value[0]) == 'False'):
                    newBoolArray = []
                    for val in range(0, len(ret.Value)):
                        newBoolArray.append(1 if str(ret.Value[val]) ==
                                            'True' else 0)

                    results.append({
                        "tagName": ret.TagName,
                        "value": newBoolArray,
                        "status": ret.Status
                    })
                else:
                    results.append({
                        "tagName": ret.TagName,
                        "value": ret.Value,
                        "status": ret.Status
                    })

        comm.Close()

        if len(regularTags) > 0 or len(arrayTags) > 0:
            return jsonify({'tags': results})
        else:
            return jsonify('Not a valid tag!')
    else:
        if tag.endswith('}') and '{' in tag:  # 1 or 2 or 3 dimensional array
            try:
                arrayElementCount = int(tag[tag.index('{') + 1:tag.index('}')])
                readArray = True
                tag = tag[:tag.index('{')]
            except:
                pass
        else:
            pass

        if readArray and arrayElementCount > 0:
            ret = comm.Read(tag, arrayElementCount)

            if ret.Value is None:
                comm.Close()
                return jsonify(ret.Status)

            if showBoolAsOneZero and (str(ret.Value[0]) == 'True'
                                      or str(ret.Value[0]) == 'False'):
                newBoolArray = []
                for val in range(0, len(ret.Value)):
                    newBoolArray.append(1 if str(ret.Value[val]) ==
                                        'True' else 0)

                results.append({
                    "tagName": ret.TagName,
                    "value": newBoolArray,
                    "status": ret.Status
                })
            else:
                results.append({
                    "tagName": ret.TagName,
                    "value": ret.Value,
                    "status": ret.Status
                })
        else:
            ret = comm.Read(tag)

            if ret.Value is None:
                comm.Close()
                return jsonify(ret.Status)

            if showBoolAsOneZero and (str(ret.Value) == 'True'
                                      or str(ret.Value) == 'False'):
                results.append({
                    "tagName": ret.TagName,
                    "value": 1 if str(ret.Value) == 'True' else 0,
                    "status": ret.Status
                })
            else:
                results.append({
                    "tagName": ret.TagName,
                    "value": ret.Value,
                    "status": ret.Status
                })

        comm.Close()

        return jsonify({'tag': results})
Esempio n. 6
0
'''
the following import is only necessary because eip.py is not in this directory
'''
import sys

sys.path.append('..')
'''
Read an array of values

I have a tag called "LargeArray", which is DINT[10000]
We can read as many of them as we'd like, which makes
reading arrays the most efficient way to read data.
Read will handle multi-packet replies.

We're going to pass Read() the tag and the number
to read.
'''
from pylogix import PLC

with PLC() as comm:
    comm = PLC()
    comm.IPAddress = '192.168.1.9'
    ret = comm.Read('LargeArray[0]', 500)
    print(ret.value)
Esempio n. 7
0
class CondorSkill(MycroftSkill):

    # The constructor of the skill, which calls Mycroft Skill's constructor
    def __init__(self):
        super(CondorSkill, self).__init__(name="CondorSkill")
        self.myKeywords = []
        # self.client = ''  # mqtt.Client()

        # Initialize settings values
        self.client = mqtt.Client(self.id_generator())
        #self.MQTT_Enabled = False
        #self.settings["MQTT_Enabled"] = False
        #self.broker_address = "192.168.0.43"
        #self.settings["broker_address"] = ""  #self.broker_address
        #self.broker_port = 1883
        #self.settings["broker_port"] = ""  # self.broker_port
        #self.settings["plc_address"] = ""  # '142.156.204.41'
        #self.plcOutTagName = "StartRobot"
        #self.settings["plc_out_tag_name"] = ""  # self.plcOutTagName
        #self.plcInTagName = "RobotStarted"
        #self.settings["plc_in_tag_name"] = ""  # self.plcInTagName
        #self.cardRequestFreq = 2
        #self.settings["card_request_interval"] = 2
        self.comm = PLC()
        self._is_setup = False
        self.io_pins = []
        self.notifier_bool = True

    # This method loads the files needed for the skill's functioning, and
    # creates and registers each intent that the skill uses
    def initialize(self):
        self.io_pins = [
            3, 5, 7, 29, 31, 26, 24, 21, 19, 23, 32, 33, 8, 10, 36, 11, 12, 35,
            38, 40, 15, 16, 18, 22, 37, 13
        ]
        GPIO.setmode(GPIO.BOARD)
        self.load_data_files(dirname(__file__))

        #  Check and then monitor for credential changes
        self.settings.set_changed_callback(self.on_websettings_changed)
        self.on_websettings_changed()

        self.add_event('recognizer_loop:wakeword',
                       self.handle_listen)  # should be "utterance"
        self.add_event('recognizer_loop:utterance',
                       self.handle_utterances)  # should be "utterances"
        self.add_event('speak', self.handle_speak)  # should be "utterance"

    def on_websettings_changed(self):  # called when updating mycroft home page
        #if not self._is_setup:
        self.MQTT_Enabled = self.settings.get(
            "MQTT_Enabled", False)  # used to enable / disable mqtt
        self.broker_address = self.settings.get("broker_address",
                                                "192.168.0.43")
        self.broker_port = self.settings.get("broker_port", 1883)
        self.comm.IPAddress = self.settings.get(
            "plc_address", '142.156.204.41')  # PLC Address
        self.plcOutTagName = self.settings.get("plc_out_tag_name",
                                               "StartRobot")
        self.plcInTagName = self.settings.get("plc_in_tag_name",
                                              "RobotStarted")
        self.cardRequestFreq = self.settings.get("card_request_interval", 2)
        self._is_setup = True
        LOG.info("Websettings Changed! " + str(self.MQTT_Enabled) + ", " +
                 self.broker_address + ", " + str(self.broker_port))

    def id_generator(self,
                     size=6,
                     chars=string.ascii_uppercase + string.digits):
        return ''.join(random.choice(chars) for _ in range(size))

    @intent_handler(
        IntentBuilder("GPIOIntent").require("GpioKeyword").one_of(
            "OnKeyword", "OffKeyword").build())
    def handle_gpio_intent(self, message):
        str_limits = []
        str_remainder = str(message.utterance_remainder())
        if (str_remainder.find('for') != -1) or (str_remainder.find('four') !=
                                                 -1):
            str_limits = [4]
        else:
            str_limits = re.findall('\d+', str_remainder)
        if str_limits:
            gpio_request = int(str_limits[0])
            if (gpio_request > 1) and (gpio_request < 28):
                pin_index = gpio_request - 2
                board_pin = self.io_pins[pin_index]
                LOG.info('The pin number requested was: ' + str(board_pin))
                if "OnKeyword" in message.data:
                    self.gpio_on(board_pin, gpio_request)
                if "OffKeyword" in message.data:
                    self.gpio_off(board_pin, gpio_request)
            else:
                self.speak_dialog("error",
                                  data={"result": str(gpio_request)},
                                  wait=True)
        else:
            self.speak('No GPIO Pin was specified')

    @intent_handler(
        IntentBuilder("WikiIntent").require("TellKeyword").require(
            "AboutKeyword").require("ConestogaKeyword").build())
    def handle_wiki_intent(self, message):
        LOG.info('Condor.ai was asked: ' + message.data.get('utterance'))
        str_remainder = str(message.utterance_remainder())
        self.speak_dialog("about", wait=True)
        self.card_conversation()

    @intent_handler(
        IntentBuilder("AcademicIntent").require("WhatKeyword").require(
            "AcademicKeyword").optionally("ConestogaKeyword").build())
    def handle_academic_intent(self, message):
        LOG.info('Condor.ai was asked: ' + message.data.get('utterance'))
        str_remainder = str(message.utterance_remainder())
        self.speak_dialog("academic1", wait=True)
        self.speak_dialog("academic2", wait=True)
        self.card_conversation()

    # @intent_handler(IntentBuilder("CampusIntent").require("WhereKeyword").
    #                 require("CampusKeyword").optionally("ConestogaKeyword").build())
    @intent_handler(
        IntentBuilder("CampusIntent").require("WhereKeyword").optionally(
            "CampusKeyword").require("ConestogaKeyword").build())
    def handle_campus_intent(self, message):
        LOG.info('Condor.ai was asked: ' + message.data.get('utterance'))
        str_remainder = str(message.utterance_remainder())
        self.speak_dialog("campus_intro", wait=True)
        self.speak_dialog("campus", wait=True)
        self.card_conversation()

    @intent_handler(
        IntentBuilder("SetStackLightIntent").require("SetKeyword").require(
            "StackLightKeyword").require("ColorKeyword").build())
    def handle_set_stack_light_intent(self, message):
        LOG.info('Condor.ai was asked: ' + message.data.get('utterance'))
        color_kw = message.data.get("ColorKeyword")
        self.speak_dialog("set_stacklight",
                          data={"result": str(color_kw)},
                          wait=True)

    @intent_handler(
        IntentBuilder("RobotStartIntent").require("BusinessKeyword").require(
            "CardKeyword").optionally("ConestogaKeyword").build())
    def handle_robot_start_intent(self, message):
        LOG.info('Condor.ai was asked: ' + message.data.get('utterance'))
        str_remainder = str(message.utterance_remainder())
        self.start_robot()

    @intent_handler(
        IntentBuilder("CardConversationIntent").require(
            "BusinessCardContextKeyword").one_of('YesKeyword',
                                                 'NoKeyword').build())
    def handle_card_conversation_intent(self, message):
        LOG.info('Condor.ai was asked: ' + message.data.get('utterance'))
        str_remainder = str(message.utterance_remainder())
        self.set_context('BusinessCardContextKeyword', '')
        if "YesKeyword" in message.data:
            self.start_robot()
        else:
            self.speak_dialog("no_card", wait=False)

    def card_conversation(self):
        low_number = 1
        high_number = self.cardRequestFreq
        my_number = random.randint(low_number, high_number)
        LOG.info('Card Request Context ID: ' + str(my_number) + '/' +
                 str(high_number))
        if my_number == high_number:
            self.set_context('BusinessCardContextKeyword',
                             'SetBusinessCardContext')
            self.speak_dialog("ask_card", wait=True, expect_response=True)

    def gpio_on(self, board_number, gpio_request_number):
        GPIO.setup(board_number, GPIO.OUT, initial=0)
        GPIO.output(board_number, True)
        LOG.info('Turning On GPIO Number: ' + str(gpio_request_number))
        self.speak_dialog("on",
                          data={"result": str(gpio_request_number)},
                          wait=True)

    def gpio_off(self, board_number, gpio_request_number):
        GPIO.setup(board_number, GPIO.OUT, initial=0)
        GPIO.output(board_number, False)
        LOG.info('Turning Off GPIO Number: ' + str(gpio_request_number))
        self.speak_dialog("off",
                          data={"result": str(gpio_request_number)},
                          wait=True)

    def get_card(self, program_select):
        GPIO.setup(program_select, GPIO.OUT, initial=0)
        GPIO.output(program_select, True)

    def start_robot(self):
        LOG.info(self.comm.IPAddress)
        self.write_plc("StartRobot", 1)
        LOG.info('PLC Output Should be On')
        self.speak_dialog("retrieve_card", wait=False)
        sleep(1)
        self.write_plc(self.plcOutTagName, 0)
        LOG.info('PLC Output Should be Off')
        inTag = self.comm.Read(self.plcInTagName)
        while inTag.value == 0:
            inTag = self.comm.Read(self.plcInTagName)
            LOG.info('Checking Robot Complete Status: ' + str(inTag.value))
            if inTag.value == 1:
                self.speak_dialog("card_delivered", wait=False)
            else:
                sleep(1)

    def write_plc(self, myTagName, myTagValue):
        LOG.info('Writing: ' + myTagName + ' A value of: ' + str(myTagValue))
        self.comm.Write(myTagName, myTagValue)
        self.comm.Close()

    # listening event used for kodi notifications
    def handle_listen(self, message):
        voice_payload = message.data.get('utterance')
        if self.notifier_bool:
            try:
                LOG.info(voice_payload)
            except Exception as e:
                LOG.error(e)
                self.on_websettings_changed()

    # utterance event used for notifications ***This is what the user says***
    def handle_utterances(self, message):
        voice_payload = str(message.data.get('utterances')[0])
        if self.notifier_bool:
            try:
                LOG.info(voice_payload)
                self.send_MQTT("Mycroft/Student", voice_payload)

            except Exception as e:
                LOG.error(e)
                self.on_websettings_changed()

    # mycroft speaking event used for notificatons ***This is what mycroft says***
    def handle_speak(self, message):
        voice_payload = message.data.get('utterance')
        if self.notifier_bool:
            try:
                LOG.info(voice_payload)
                self.send_MQTT("Mycroft/AI", voice_payload)
                #self.card_conversation()
            except Exception as e:
                LOG.error(e)
                self.on_websettings_changed()

    def send_MQTT(self, myTopic, myMessage):
        if self.MQTT_Enabled:
            LOG.info("MQTT: " + myTopic + ", " + myMessage)
            myID = self.id_generator()
            #LOG.info("MyID: " + str(myID))
            #self.client = mqtt.Client(myID)
            #self.client.connect(self.broker_address, self.broker_port)  # connect to broker
            #self.client.publish(myTopic, myMessage)  # publish
            #self.client.disconnect()
            LOG.info("address: " + self.broker_address + ", Port: " +
                     str(self.broker_port))
            publish.single(myTopic, myMessage, hostname=self.broker_address)

        else:
            LOG.info(
                "MQTT has been disabled in the websettings at https://home.mycroft.ai"
            )

    def stop(self):
        pass
Esempio n. 8
0
import sys
sys.path.append('..')
'''
Read a little faster by providing the data type
up front

This only really makes sense to do if you have to
read a lot of unique tags. Typically, when you read a
tag, it has to fetch the data type first.  This only
happens the first time you read a uniuqe tag name.  Once
we have read a tag, we remember the type.

If you have, for example, 1000 tags to read and they are
all unique, you would have have to fetch the data type,
then the value, which is quite a bit of overhead.

If you pass the data type up front, it will skip that
initial read...
'''
from pylogix import PLC

with PLC() as comm:
    comm = PLC()
    comm.IPAddress = '192.168.1.9'
    tags = [
        'BaseINT', ['BaseDINT', 196], ('BaseBOOL', 193), ['BaseSTRING', 160]
    ]
    ret = comm.Read(tags)
    for r in ret:
        print(r.value)
Esempio n. 9
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.1.9'
ret = comm.Read('CurrentScreen')
print(ret.Value)
comm.Close()
Esempio n. 10
0
'''
the following import is only necessary because eip.py is not in this directory
'''
import sys

sys.path.append('..')
'''
Read a program scoped tag

I have a program named "MiscHMI" in my main task.
In MiscHMI, the tag I'm reading will be TimeArray[0]
You have to specify that the tag will be program scoped
by appending the tag name with "Program" and the beginning,
then add the program name, finally the tag name.  So our
example will look like this:

Program:MiscHMI.TimeArray[0]
'''
from pylogix import PLC

with PLC() as comm:
    comm = PLC()
    comm.IPAddress = '192.168.1.9'
    value = comm.Read('Program:MiscHMI.TimeArray[0]')
    print(value)
Esempio n. 11
0
'''
the following import is only necessary because eip.py is not in this directory
'''
import sys
sys.path.append('..')
'''
A simple single read using a with statement.

One advantage of using a with statement is that
you don't have to call .Close() when you are done,
this is handled automatically.
'''
from pylogix import PLC

with PLC() as comm:
    comm = PLC()
    comm.IPAddress = '192.168.1.9'
    value = comm.Read('CurrentScreen')
    print(value)
Esempio n. 12
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()
Esempio n. 13
0
def ReadConditions():
    comm = PLC()
    comm.IPAddress = '169.254.215.82'
    ECR = comm.Read('indicate.0')  #!Estop Control Relay PLC
    MCR = comm.Read('indicate.1')  #Master Control Relay PLC
    SCR = comm.Read('indicate.2')  #!Sequence Control Relay PLC
    SSR = comm.Read('indicate.3')  #Sequence Stop Relay PLC
    SPR = comm.Read('indicate.4')  #Sequence Pause Relay PLC
    SRR = comm.Read('indicate.5')  #Sequence Resume Relay PLC
    window.after(2000, ReadConditions)
    if ECR == True:
        lbl18 = Label(window,
                      text="EStop On",
                      fg="yellow",
                      bg="red",
                      bd=2,
                      relief="raised",
                      width=12,
                      height=2)
        lbl18.place(x=31, y=150)
    elif ECR == False:
        lbl18 = Label(window,
                      text="No_EStop",
                      fg="red",
                      bg="yellow",
                      bd=2,
                      relief="flat",
                      width=12,
                      height=2)
        lbl18.place(x=31, y=150)
    if MCR == True:
        lbl19 = Label(window,
                      text="Master On",
                      fg="White",
                      bg="Firebrick4",
                      bd=2,
                      relief="raised",
                      width=12,
                      height=2)
        lbl19.place(x=161, y=150)
    elif MCR == False:
        lbl19 = Label(window,
                      text="Master Off",
                      fg="Firebrick4",
                      bg="white",
                      bd=2,
                      relief="flat",
                      width=12,
                      height=2)
        lbl19.place(x=161, y=150)
    if SCR == True:
        lbl20 = Label(window,
                      text="Seq On",
                      fg="White",
                      bg="Green",
                      bd=2,
                      relief="raised",
                      width=12,
                      height=2)
        lbl20.place(x=291, y=400)
    elif SCR == False:
        lbl20 = Label(window,
                      text="Seq Off",
                      fg="Green",
                      bg="white",
                      bd=2,
                      relief="flat",
                      width=12,
                      height=2)
        lbl20.place(x=291, y=400)
    if SSR == True:
        lbl21 = Label(window,
                      text="Seq Off",
                      fg="White",
                      bg="Red",
                      bd=2,
                      relief="raised",
                      width=12,
                      height=2)
        lbl21.place(x=291, y=440)
    elif SSR == False:
        lbl21 = Label(window,
                      text="Seq On",
                      fg="Red",
                      bg="white",
                      bd=2,
                      relief="flat",
                      width=12,
                      height=2)
        lbl21.place(x=291, y=440)
    if SPR == True:
        lbl22 = Label(window,
                      text="Paused",
                      fg="White",
                      bg="Navy",
                      bd=2,
                      relief="raised",
                      width=12,
                      height=2)
        lbl22.place(x=291, y=480)
    elif SPR == False:
        lbl22 = Label(window,
                      text="Resumed",
                      fg="Navy",
                      bg="White",
                      bd=2,
                      relief="flat",
                      width=12,
                      height=2)
        lbl22.place(x=291, y=480)
    if SRR == True:
        lbl23 = Label(window,
                      text="Resumed",
                      fg="White",
                      bg="Olive Drab",
                      bd=2,
                      relief="raised",
                      width=12,
                      height=2)
        lbl23.place(x=291, y=520)
    elif SRR == False:
        lbl23 = Label(window,
                      text="Paused",
                      fg="Olive Drab",
                      bg="White",
                      bd=2,
                      relief="flat",
                      width=12,
                      height=2)
        lbl23.place(x=291, y=520)
    return
Esempio n. 14
0
from pylogix import PLC

# Setup the PLC object with initial parameters
# Change to your plc ip address, and slot, default is 0, shown for clarity
comm = PLC('192.168.1.207', 0)

# Read returns Response class (.TagName, .Value, .Status)
ret = comm.Read('bool_01')
print(ret.TagName, ret.Value, ret.Status)

# Close Open Connection to the PLC
comm.Close()
Esempio n. 15
0
from pylogix import PLC

# Setup the PLC object with initial parameters
# Change to your plc ip address, and slot, default is 0, shown for clarity
comm = PLC('192.168.1.207', 0)

# Read returns Response class (.TagName, .Value, .Status)
ret = comm.Read('Program:MainProgram.bool_01')
print(ret.TagName, ret.Value, ret.Status)

# Close Open Connection to the PLC
comm.Close()
Esempio n. 16
0
Read a list of tags at once

Reading lists and arrays is much more efficient than
reading them individually. You can create a list of tags
and pass it to .Read() to read them  all in one packet.
The values returned will be in the same order as the tags
you passed to Read()

NOTE:  Packets have a ~500 byte limit, so you have to be cautions
about not exceeding that or the read will fail.  It's a little
difficult to predict how many bytes your reads will take up becuase
the send packet will depend on the length of the tag name and the
reply will depened on the data type.  Strings are a lot longer than
DINT's for example.

I'll usually read no more than 5 strings at once, or 10 DINT's)
'''
from pylogix import PLC

tag_list = [
    'Zone1ASpeed', 'Zone1BSpeed', 'Zone2ASpeed', 'Zone2BSpeed', 'Zone3ASpeed',
    'Zone3BSpeed', 'Zone4ASpeed', 'ZOne4BSpeed', 'Zone1Case', 'Zone2Case'
]

with PLC() as comm:
    comm = PLC()
    comm.IPAddress = '192.168.1.9'
    ret = comm.Read(tag_list)
    for r in ret:
        print(r.Value)
Esempio n. 17
0
'''
the following import is only necessary because eip.py is not in this directory
'''
import sys
sys.path.append('..')
'''
Read an array of values

I have a tag called "LargeArray", which is DINT[10000]
We can read as many of them as we'd like, which makes
reading arrays the most efficient way to read data.
Read will handle multi-packet replies.

We're going to pass Read() the tag and the number
to read.
'''
from pylogix import PLC

with PLC() as comm:
    comm = PLC()
    comm.IPAddress = '192.168.1.9'
    values = comm.Read('LargeArray[0]', 500)
    print(values)
Esempio n. 18
0
'''
the following import is only necessary because eip.py is not in this directory
'''
import sys
sys.path.append('..')
'''
Read a little faster by providing the data type
up front

This only really makes sense to do if you have to
read a lot of unique tags. Typically, when you read a
tag, it has to fetch the data type first.  This only
happens the first time you read a uniuqe tag name.  Once
we have read a tag, we remember the type.

If you have, for example, 1000 tags to read and they are
all unique, you would have have to fetch the data type,
then the value, which is quite a bit of overhead.

If you pass the data type up front, it will skip that
initial read...
'''
from pylogix import PLC

with PLC() as comm:
    comm = PLC()
    comm.IPAddress = '192.168.1.9'
    value = comm.Read('CurrentScreen', datatype=196)
    print(value)
Esempio n. 19
0
fileName = 'Node06'
data0 = 'Timestamp,S1, S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12,S13,S14,S15,S21,S22,S23,S24,S25,S26,S27,S28,S29,S30,S31,S32,S33,S34,S35,S41,S42,S43,S44,S45,S46,S47,S48,S49,S50,S51,S52,S53,S54,S55\n'

# open the file as write mode

#             data = ''.join(data2)
#       data = ''.join(map(str, data0))

while loop_PLC:
    try:
        Time_now = datetime.now()
        second = Time_now.strftime("%S")

        if (second >= "30" and second <= "30"):

            T1 = comm1.Read('Real1')
            T1_data = str(T1).split(' ')
            print(T1_data[1])
            S1 = T1_data[1]
            T2 = comm1.Read('Real2')
            T2_data = str(T2).split(' ')
            print(T2_data[1])
            S2 = T2_data[1]
            T3 = comm1.Read('Real3')
            T3_data = str(T3).split(' ')
            print(T3_data[1])
            S3 = T3_data[1]
            T4 = comm1.Read('Real4')
            T4_data = str(T4).split(' ')
            print(T4_data[1])
            S4 = T4_data[1]