Coder Social home page Coder Social logo

Abnormal code termination. about pylogix HOT 8 CLOSED

horus61 avatar horus61 commented on July 17, 2024
Abnormal code termination.

from pylogix.

Comments (8)

dmroeder avatar dmroeder commented on July 17, 2024

Can you post a simple example that causes this issue? It will probably be important to know the tags and their data types.

from pylogix.

TheFern2 avatar TheFern2 commented on July 17, 2024

For future reference please provide an mre.

For your case it would be one script with one Read call, in a while loop and a sleep of N seconds. We don't need to know about sms and other stuff going on.

Also ensure that you are using code tags when posting so that is formatted properly.

What are the data types for the tags giving you the exception?

Does the same exception happens when doing individual reads?

When opening an issue there's a template for some questions and you didn't provide those.

OS type and version?
Pylogix version?
Python version?
PLC model?

from pylogix.

horus61 avatar horus61 commented on July 17, 2024

Good morning. The error manifested itself with the following code. The tags I read are two to simplify. The first is an integer, the other is boolean. I would like to point out that the Raspberry Pi 3 is connected to the PLC via a HyperLAN network at a distance of 10 km. Might you need code that checks the connection and avoids blocking code execution? Let me start by saying that I am a newbie. Thank you.
[342, True]
12/10/2023, 11:32:31
['Livello 3.42 mt 😃']
Traceback (most recent call last):
File "/home/nino/TorrreP2/TorreP2Test.py", line 49, in
dati_adesso = leggi_tags()
File "/home/nino/TorrreP2/TorreP2Test.py", line 34, in leggi_tags
ret = comm.Read(tags)
File "/home/nino/.local/lib/python3.9/site-packages/pylogix/eip.py", line 120, in Read
return self._batch_read(tag)
File "/home/nino/.local/lib/python3.9/site-packages/pylogix/eip.py", line 265, in _batch_read
conn = self.conn.connect()
File "/home/nino/.local/lib/python3.9/site-packages/pylogix/lgx_comm.py", line 49, in connect
return self._connect(connected)
File "/home/nino/.local/lib/python3.9/site-packages/pylogix/lgx_comm.py", line 104, in _connect
ret_data = self.receive_data()
File "/home/nino/.local/lib/python3.9/site-packages/pylogix/lgx_comm.py", line 181, in receive_data
part = self.Socket.recv(4096)
socket.timeout: timed out


(program exited with code: 1)
Press return to continue


#from future import print_function
#import gammu
import sys
import logging
import time
#*********************************************************************************************************************
from pylogix import PLC

from datetime import datetime, timedelta
from threading import Timer

#----------------------------------------------------------------------------------------------------------------------------------------
#Timestamp ******************************************************************************************************************************
def Data_Ora():
    DataOraReport = []
    timestamp = time.time()
    date_time = datetime.fromtimestamp(timestamp)
    str_date_time = date_time.strftime("%d/%m/%Y, %H:%M:%S")
    DataOraReport = (str_date_time)
    return DataOraReport

#----------------------------------------------------------------------------------------------------------------------------------------
#Variabili PLC **************************************************************************************************************************
tags=['Program:TIM.MISURA_06','Program:TIM.MISURA_OK_06']

#-----------------------------------------------------------------------------------------------------------------------------------------
#Legge le tags nel PLC *******************************************************************************************************************

def leggi_tags():
    value_tags = [] 

    with PLC() as comm:
        comm.IPAddress = '***.***.***.***'
        ret = comm.Read(tags)

    for r in ret:
        #print(r.Value)
        value_tags.append(r.Value)
        
    return value_tags

dati_prima = leggi_tags()
did_change = False
#------------------------------------------------------------------------------------------------------------------------------------------
while True: 
       
    TimeStampAdesso = Data_Ora()  
          
    dati_adesso = leggi_tags()
    print(dati_adesso)
        
    # Loop che comprende tutti i valori e li compara
    items_variati = []  # <- New list
    indici_variati = [] 
    
    for val_adesso, val_prima in zip(dati_adesso, dati_prima):

        # Compara nuovi valori con quelli precedenti
        if val_adesso != val_prima:
            print(f"I valori {val_adesso} {val_prima} sono diversi")

            items_variati.append(val_adesso)  # <- Aggiungi un item alla lista
            #print(items_variati)
                        
            indici_variati.append(dati_adesso.index(val_adesso))
            #print(indici_variati)
            
    did_change = True

    if did_change:
        dati_prima = dati_adesso
        did_change = False
        
    
# ------------------------------------------------------------------------------------------------------------------------------------------
   

# Verifica Misure Analogiche Idrauliche ****************************************************************************************************

# Livello Torre  *************************************************************************************************************************
    
    LivTorreP2 = (dati_adesso[0]) # integer
    LivTorreP2_OK = (dati_adesso[1]) # boolean
    MesLiv = []
    

    if (LivTorreP2_OK) == True :
        MesLiv.append ("Livello "+ str(LivTorreP2/100) + " mt" + " \U0001F603")
        

        if (LivTorreP2/100) > 4.20 and (LivTorreP2_OK) == True:
            MesLiv.append ("Livello "+ str(LivTorreP2/100) + " mt" + " alto \U00002B06") 

        elif (LivTorreP2/100) < 2.30 and (LivTorreP2_OK) == True:
            MesLiv.append ("Livello "+ str(LivTorreP2/100) + " mt" + " basso \U00002B07")

    else:
        MesLiv.append("Livello " + "***" + " mt" + " \U0001F621")
    
#------------------------------------------------------------------------------------------------------------------------------------------
  
    print(TimeStampAdesso)
    print(MesLiv)

    time.sleep(10)

  • RaspBerry PI 3
  • Raspbian GNU/Linux11 (bulleye)
  • Python 3.9.2
  • Pylogix 0.8.14
  • PLC AB CompactLogix

from pylogix.

dmroeder avatar dmroeder commented on July 17, 2024

Ah, okay, the details about the network are important. Seems like maybe the request makes it to the PLC, but you never get a response. I'll have to recreate the same scenario.

from pylogix.

horus61 avatar horus61 commented on July 17, 2024

Good morning everyone. Is there any news regarding this problem? Thanks for your contribution.

from pylogix.

dmroeder avatar dmroeder commented on July 17, 2024

Nothing yet. I'll work on it as soon as I can

from pylogix.

dmroeder avatar dmroeder commented on July 17, 2024

I see what is going on @horus61, I'm working on a fix.

from pylogix.

dmroeder avatar dmroeder commented on July 17, 2024

@horus61, try 0.9.1

from pylogix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.