diff --git a/IOB-PI/readParallela.py b/IOB-PI/readParallela.py index 44f0e12..9eb3568 100644 --- a/IOB-PI/readParallela.py +++ b/IOB-PI/readParallela.py @@ -1,7 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# readParallela v. 2.6.0 12 Ingressi +# readParallela v. 2.6.1 12 Ingressi # - single instance timer # - invio multiplo x send eventi accodati # - gestione segnali BLINKING @@ -15,12 +15,7 @@ # - (2.5.2) Fix gestione eccezioni con report dettagliato # - (2.5.3) Fix gestione stringhe e print x python 3.11 in debian 12 / raspberry OS 2025 # - (2.6.0) Aggiunto gestione Redis x code salvate ogni minuto e ricaricate all'avvio 2025.04.17 - -#--------------------------------------------------------------- -# levare locking -# timer semplificata -# GPIO global - +# - (2.6.1) Cleanup generale vecchia queue post test vari import time import sys @@ -31,20 +26,16 @@ from datetime import datetime import urllib import urllib.request import configparser -#import ConfigParser import os, sys import logging import logging.handlers import threading -import queue -#import Queue import redis from array import * #-------------------------------------------------------------- - # COSTANTI MSGLEN = 9 TIMEOUTSERIALE = 10 @@ -103,7 +94,6 @@ timer_busy = False # # array per ingressi filtrati - i_counters = array ( 'i',[0,0,0,0,0,0,0,0,0,0,0,0]) B_blinking = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0]) B_previous = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0]) @@ -118,18 +108,12 @@ B_temp = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0]) i_filter_counters = array ( 'i',[0,0,0,0,0,0,0,0,0,0,0,0]) #-------------------------------------------------------------- -# Gestione coda (condivisa) x registrazione eventi ed invio URL -#print ("Creazione coda illimitata") - -#Coda = queue.Queue(0) +# Gestione coda (condivisa) su Redis x registrazione eventi ed invio URL CodaR = redis.Redis(host='localhost', port=6379, db=0, password='24068Seriate') queue_name = 'IOB' -#queueLock = threading.Lock() - #----------------------------------- -# Gestione code REDIS -# per sostituzione 1:1 con coda in ram +# Gestione code REDIS (sost. coda in ram) # Function to add an item to the queue (enqueue) def rqEnqueue(item): @@ -223,7 +207,6 @@ def readParallelaFiltrata(): else: B_input[7] = 1 - if GPIO.input(in_8): B_input[8] = 0 else: @@ -245,9 +228,6 @@ def readParallelaFiltrata(): B_input[11] = 1 - - - #ciclo per ogni segnale for i in range(12) : @@ -363,7 +343,6 @@ def readParallelaFiltrata(): new_value = new_value + 64 if ( B_output[7] == 1 ) : new_value = new_value + 128 - if ( B_output[8] == 1 ) : new_value = new_value + 256 if ( B_output[9] == 1 ) : @@ -373,7 +352,6 @@ def readParallelaFiltrata(): if ( B_output[11] == 1 ) : new_value = new_value + 2048 - current = hex( new_value ).replace ( "0x" , "" ).upper() except Exception as e: @@ -391,11 +369,6 @@ def accoda(): try: dtEve = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] rqEnqueue(dtEve + '#' + value + '#' + cont) - #Coda.put(dtEve + '#' + value + '#' + cont) - - #except queue.Full: - ##except Queue.Full: - # logPro.error( "Queue full" + str(dtEve) + '#' + str(value) + '#' + str(cont) ) except Exception as e: logPro.error( "QUEUE:Errore coda \n\n" ) logPro.error(str(e)) @@ -409,40 +382,35 @@ def svuotaCoda(): global timer_busy global NMAXSEND - #print ("start timer ") - + #logPro.info ("start timer ") if ( timer_busy == False ): timer_busy = True - #print ("start timer ok ") + #logPro.info ("start timer ok ") try: if not rqLen() == 0: - #if not Coda.empty(): - #print ("coda da svuotare!") + #logPro.info ("coda da svuotare!") response = urllib.request.urlopen(URLALIVE) answ = response.read().decode('utf-8') - #print(answ) + #logPro.info(answ) if answ == 'OK': - #print ("OK alive") + #logPro.info ("OK alive") response2 = urllib.request.urlopen(URLENABLED + idxMacchina) answ2 = response2.read().decode('utf-8') if answ2 == 'OK': # aggiorno stato ad online if onLine == '0': logPro.info("IOB ONLINE!") - #print("IOB ONLINE") onLine = '1' # imposto comunque online else: if onLine == '1': logPro.error("IOB offline") - #print("IOB offline") onLine = '0' else: if onLine == '1': logPro.error("Server offline") - #print("Server offline") onLine = '0' @@ -457,14 +425,12 @@ def svuotaCoda(): while i >= 0: if not rqLen() == 0: - #if not Coda.empty(): # formatto dataOra corrente dtCurr = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] #prendo primo elemento dalla coda resp = rqDequeue() - #resp = Coda.get() # recupero valori da elemento coda! dtEve = resp.split("#")[0] @@ -475,11 +441,11 @@ def svuotaCoda(): # CHIAMO URL response3 = urllib.request.urlopen ( url ) answ3 = response3.read().decode('utf-8') - #print(url) + #logSnd.info(url) # log valore inviato! logSnd.info( value + ' ['+ cnt +']' + ' R:' + answ3 ) - #print ("Valore smaltito dalla coda") + #logSnd.info ("Valore smaltito dalla coda") # tolgo 1 al contatore i -= 1 @@ -505,7 +471,6 @@ def svuotaCoda(): if onLine == '1': logPro.error("Server Non raggiungibile") logPro.error(str(e)) - #print ("Non raggiungibile") onLine = '0' @@ -514,10 +479,8 @@ def svuotaCoda(): timer_busy = False #print ("end timer ok") - #print ("end timer ") - #--------------------------------------------------------------- # funzione timer thread #--------------------------------------------------------------- @@ -602,7 +565,6 @@ def avviaParallela(): try: config = configparser.RawConfigParser() - #config = ConfigParser.RawConfigParser() config.read ( 'IOB.cfg' ) SAMPLETIME = config.getfloat ( 'time' , 'SAMPLETIME' ) @@ -637,8 +599,7 @@ try: MAX_COUNTER_BLINK = config.getint ( 'blink' , 'MAX_COUNTER_BLINK' ) - # cv 2.1 se bit = 1 allora inverto segnale in ingresso... - + # cv 2.1 se bit = 1 allora inverto segnale in ingresso... B_inverting[0] = config.getint ( 'invert' , 'bit0' ) B_inverting[1] = config.getint ( 'invert' , 'bit1' ) B_inverting[2] = config.getint ( 'invert' , 'bit2' ) @@ -652,8 +613,7 @@ try: B_inverting[10] = config.getint ( 'invert' , 'bit10' ) B_inverting[11] = config.getint ( 'invert' , 'bit11' ) - # cv 2.2 se bit = 1 allora filtro segnali brevi ... - + # cv 2.2 se bit = 1 allora filtro segnali brevi ... B_filter[0] = config.getint ( 'filter' , 'bit0' ) B_filter[1] = config.getint ( 'filter' , 'bit1' ) B_filter[2] = config.getint ( 'filter' , 'bit2' ) @@ -718,15 +678,6 @@ logPro.info( "Start " + PROGRAM_NAME ) # lettura file configurazione - -# [id] -# idxMacchina = 2001 -# [time] -# SAMPLETIME = 0.1 -# TIMEOUTSHORT = 200 -# TIMEOUTLONG = 6000 - - print ( ' idxMacchina = %s' % ( idxMacchina ) ) print ( ' SAMPLETIME = %4.2f' % ( SAMPLETIME ) ) print ( ' TIMEOUTSHORT = %4.2f' % ( TIMEOUTSHORT ) ) diff --git a/IOB-PI/readParallela_12.py b/IOB-PI/readParallela_12.py index 44f0e12..9eb3568 100644 --- a/IOB-PI/readParallela_12.py +++ b/IOB-PI/readParallela_12.py @@ -1,7 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# readParallela v. 2.6.0 12 Ingressi +# readParallela v. 2.6.1 12 Ingressi # - single instance timer # - invio multiplo x send eventi accodati # - gestione segnali BLINKING @@ -15,12 +15,7 @@ # - (2.5.2) Fix gestione eccezioni con report dettagliato # - (2.5.3) Fix gestione stringhe e print x python 3.11 in debian 12 / raspberry OS 2025 # - (2.6.0) Aggiunto gestione Redis x code salvate ogni minuto e ricaricate all'avvio 2025.04.17 - -#--------------------------------------------------------------- -# levare locking -# timer semplificata -# GPIO global - +# - (2.6.1) Cleanup generale vecchia queue post test vari import time import sys @@ -31,20 +26,16 @@ from datetime import datetime import urllib import urllib.request import configparser -#import ConfigParser import os, sys import logging import logging.handlers import threading -import queue -#import Queue import redis from array import * #-------------------------------------------------------------- - # COSTANTI MSGLEN = 9 TIMEOUTSERIALE = 10 @@ -103,7 +94,6 @@ timer_busy = False # # array per ingressi filtrati - i_counters = array ( 'i',[0,0,0,0,0,0,0,0,0,0,0,0]) B_blinking = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0]) B_previous = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0]) @@ -118,18 +108,12 @@ B_temp = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0]) i_filter_counters = array ( 'i',[0,0,0,0,0,0,0,0,0,0,0,0]) #-------------------------------------------------------------- -# Gestione coda (condivisa) x registrazione eventi ed invio URL -#print ("Creazione coda illimitata") - -#Coda = queue.Queue(0) +# Gestione coda (condivisa) su Redis x registrazione eventi ed invio URL CodaR = redis.Redis(host='localhost', port=6379, db=0, password='24068Seriate') queue_name = 'IOB' -#queueLock = threading.Lock() - #----------------------------------- -# Gestione code REDIS -# per sostituzione 1:1 con coda in ram +# Gestione code REDIS (sost. coda in ram) # Function to add an item to the queue (enqueue) def rqEnqueue(item): @@ -223,7 +207,6 @@ def readParallelaFiltrata(): else: B_input[7] = 1 - if GPIO.input(in_8): B_input[8] = 0 else: @@ -245,9 +228,6 @@ def readParallelaFiltrata(): B_input[11] = 1 - - - #ciclo per ogni segnale for i in range(12) : @@ -363,7 +343,6 @@ def readParallelaFiltrata(): new_value = new_value + 64 if ( B_output[7] == 1 ) : new_value = new_value + 128 - if ( B_output[8] == 1 ) : new_value = new_value + 256 if ( B_output[9] == 1 ) : @@ -373,7 +352,6 @@ def readParallelaFiltrata(): if ( B_output[11] == 1 ) : new_value = new_value + 2048 - current = hex( new_value ).replace ( "0x" , "" ).upper() except Exception as e: @@ -391,11 +369,6 @@ def accoda(): try: dtEve = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] rqEnqueue(dtEve + '#' + value + '#' + cont) - #Coda.put(dtEve + '#' + value + '#' + cont) - - #except queue.Full: - ##except Queue.Full: - # logPro.error( "Queue full" + str(dtEve) + '#' + str(value) + '#' + str(cont) ) except Exception as e: logPro.error( "QUEUE:Errore coda \n\n" ) logPro.error(str(e)) @@ -409,40 +382,35 @@ def svuotaCoda(): global timer_busy global NMAXSEND - #print ("start timer ") - + #logPro.info ("start timer ") if ( timer_busy == False ): timer_busy = True - #print ("start timer ok ") + #logPro.info ("start timer ok ") try: if not rqLen() == 0: - #if not Coda.empty(): - #print ("coda da svuotare!") + #logPro.info ("coda da svuotare!") response = urllib.request.urlopen(URLALIVE) answ = response.read().decode('utf-8') - #print(answ) + #logPro.info(answ) if answ == 'OK': - #print ("OK alive") + #logPro.info ("OK alive") response2 = urllib.request.urlopen(URLENABLED + idxMacchina) answ2 = response2.read().decode('utf-8') if answ2 == 'OK': # aggiorno stato ad online if onLine == '0': logPro.info("IOB ONLINE!") - #print("IOB ONLINE") onLine = '1' # imposto comunque online else: if onLine == '1': logPro.error("IOB offline") - #print("IOB offline") onLine = '0' else: if onLine == '1': logPro.error("Server offline") - #print("Server offline") onLine = '0' @@ -457,14 +425,12 @@ def svuotaCoda(): while i >= 0: if not rqLen() == 0: - #if not Coda.empty(): # formatto dataOra corrente dtCurr = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] #prendo primo elemento dalla coda resp = rqDequeue() - #resp = Coda.get() # recupero valori da elemento coda! dtEve = resp.split("#")[0] @@ -475,11 +441,11 @@ def svuotaCoda(): # CHIAMO URL response3 = urllib.request.urlopen ( url ) answ3 = response3.read().decode('utf-8') - #print(url) + #logSnd.info(url) # log valore inviato! logSnd.info( value + ' ['+ cnt +']' + ' R:' + answ3 ) - #print ("Valore smaltito dalla coda") + #logSnd.info ("Valore smaltito dalla coda") # tolgo 1 al contatore i -= 1 @@ -505,7 +471,6 @@ def svuotaCoda(): if onLine == '1': logPro.error("Server Non raggiungibile") logPro.error(str(e)) - #print ("Non raggiungibile") onLine = '0' @@ -514,10 +479,8 @@ def svuotaCoda(): timer_busy = False #print ("end timer ok") - #print ("end timer ") - #--------------------------------------------------------------- # funzione timer thread #--------------------------------------------------------------- @@ -602,7 +565,6 @@ def avviaParallela(): try: config = configparser.RawConfigParser() - #config = ConfigParser.RawConfigParser() config.read ( 'IOB.cfg' ) SAMPLETIME = config.getfloat ( 'time' , 'SAMPLETIME' ) @@ -637,8 +599,7 @@ try: MAX_COUNTER_BLINK = config.getint ( 'blink' , 'MAX_COUNTER_BLINK' ) - # cv 2.1 se bit = 1 allora inverto segnale in ingresso... - + # cv 2.1 se bit = 1 allora inverto segnale in ingresso... B_inverting[0] = config.getint ( 'invert' , 'bit0' ) B_inverting[1] = config.getint ( 'invert' , 'bit1' ) B_inverting[2] = config.getint ( 'invert' , 'bit2' ) @@ -652,8 +613,7 @@ try: B_inverting[10] = config.getint ( 'invert' , 'bit10' ) B_inverting[11] = config.getint ( 'invert' , 'bit11' ) - # cv 2.2 se bit = 1 allora filtro segnali brevi ... - + # cv 2.2 se bit = 1 allora filtro segnali brevi ... B_filter[0] = config.getint ( 'filter' , 'bit0' ) B_filter[1] = config.getint ( 'filter' , 'bit1' ) B_filter[2] = config.getint ( 'filter' , 'bit2' ) @@ -718,15 +678,6 @@ logPro.info( "Start " + PROGRAM_NAME ) # lettura file configurazione - -# [id] -# idxMacchina = 2001 -# [time] -# SAMPLETIME = 0.1 -# TIMEOUTSHORT = 200 -# TIMEOUTLONG = 6000 - - print ( ' idxMacchina = %s' % ( idxMacchina ) ) print ( ' SAMPLETIME = %4.2f' % ( SAMPLETIME ) ) print ( ' TIMEOUTSHORT = %4.2f' % ( TIMEOUTSHORT ) ) diff --git a/IOB-PI/readParallela_8.py b/IOB-PI/readParallela_8.py index 6b6aeb1..edbdfdc 100644 --- a/IOB-PI/readParallela_8.py +++ b/IOB-PI/readParallela_8.py @@ -1,7 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# readParallela v. 2.6.0 8 Ingressi +# readParallela v. 2.6.1 8 Ingressi # - single instance timer # - invio multiplo x send eventi accodati # - gestione segnali BLINKING @@ -15,12 +15,7 @@ # - (2.5.2) Fix gestione eccezioni con report dettagliato # - (2.5.3) Fix gestione stringhe e print x python 3.11 in debian 12 / raspberry OS 2025 # - (2.6.0) Aggiunto gestione Redis x code salvate ogni minuto e ricaricate all'avvio 2025.04.17 - -#--------------------------------------------------------------- -# levare locking -# timer semplificata -# GPIO global - +# - (2.6.1) Cleanup generale vecchia queue post test vari import time import sys @@ -31,20 +26,16 @@ from datetime import datetime import urllib import urllib.request import configparser -#import ConfigParser import os, sys import logging import logging.handlers import threading -import queue -#import Queue import redis from array import * #-------------------------------------------------------------- - # COSTANTI MSGLEN = 9 TIMEOUTSERIALE = 10 @@ -99,7 +90,6 @@ timer_busy = False # # array per ingressi filtrati - i_counters = array ( 'i',[0,0,0,0,0,0,0,0]) B_blinking = array ( 'B',[0,0,0,0,0,0,0,0]) B_previous = array ( 'B',[0,0,0,0,0,0,0,0]) @@ -114,18 +104,12 @@ B_temp = array ( 'B',[0,0,0,0,0,0,0,0]) i_filter_counters = array ( 'i',[0,0,0,0,0,0,0,0]) #-------------------------------------------------------------- -# Gestione coda (condivisa) x registrazione eventi ed invio URL -#print ("Creazione coda illimitata") - -#Coda = queue.Queue(0) +# Gestione coda (condivisa) su Redis x registrazione eventi ed invio URL CodaR = redis.Redis(host='localhost', port=6379, db=0, password='24068Seriate') queue_name = 'IOB' -#queueLock = threading.Lock() - #----------------------------------- -# Gestione code REDIS -# per sostituzione 1:1 con coda in ram +# Gestione code REDIS (sost. coda in ram) # Function to add an item to the queue (enqueue) def rqEnqueue(item): @@ -348,11 +332,6 @@ def accoda(): try: dtEve = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] rqEnqueue(dtEve + '#' + value + '#' + cont) - #Coda.put(dtEve + '#' + value + '#' + cont) - - #except queue.Full: - ##except Queue.Full: - # logPro.error( "Queue full" + str(dtEve) + '#' + str(value) + '#' + str(cont) ) except Exception as e: logPro.error( "QUEUE:Errore coda \n\n" ) logPro.error(str(e)) @@ -366,40 +345,35 @@ def svuotaCoda(): global timer_busy global NMAXSEND - #print ("start timer ") - + #logPro.info ("start timer ") if ( timer_busy == False ): timer_busy = True - #print ("start timer ok ") + #logPro.info ("start timer ok ") try: if not rqLen() == 0: - #if not Coda.empty(): - #print ("coda da svuotare!") + #logPro.info ("coda da svuotare!") response = urllib.request.urlopen(URLALIVE) answ = response.read().decode('utf-8') - #print(answ) + #logPro.info(answ) if answ == 'OK': - #print ("OK alive") + #logPro.info ("OK alive") response2 = urllib.request.urlopen(URLENABLED + idxMacchina) answ2 = response2.read().decode('utf-8') if answ2 == 'OK': # aggiorno stato ad online if onLine == '0': logPro.info("IOB ONLINE!") - #print("IOB ONLINE") onLine = '1' # imposto comunque online else: if onLine == '1': logPro.error("IOB offline") - #print("IOB offline") onLine = '0' else: if onLine == '1': logPro.error("Server offline") - #print("Server offline") onLine = '0' @@ -414,14 +388,12 @@ def svuotaCoda(): while i >= 0: if not rqLen() == 0: - #if not Coda.empty(): # formatto dataOra corrente dtCurr = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] #prendo primo elemento dalla coda resp = rqDequeue() - #resp = Coda.get() # recupero valori da elemento coda! dtEve = resp.split("#")[0] @@ -432,11 +404,11 @@ def svuotaCoda(): # CHIAMO URL response3 = urllib.request.urlopen ( url ) answ3 = response3.read().decode('utf-8') - #print(url) + #logSnd.info(url) # log valore inviato! logSnd.info( value + ' ['+ cnt +']' + ' R:' + answ3 ) - #print ("Valore smaltito dalla coda") + #logSnd.info ("Valore smaltito dalla coda") # tolgo 1 al contatore i -= 1 @@ -462,7 +434,6 @@ def svuotaCoda(): if onLine == '1': logPro.error("Server Non raggiungibile") logPro.error(str(e)) - #print ("Non raggiungibile") onLine = '0' @@ -471,10 +442,8 @@ def svuotaCoda(): timer_busy = False #print ("end timer ok") - #print ("end timer ") - #--------------------------------------------------------------- # funzione timer thread #--------------------------------------------------------------- @@ -551,7 +520,6 @@ def avviaParallela(): try: config = configparser.RawConfigParser() - #config = ConfigParser.RawConfigParser() config.read ( 'IOB.cfg' ) SAMPLETIME = config.getfloat ( 'time' , 'SAMPLETIME' ) @@ -582,8 +550,7 @@ try: MAX_COUNTER_BLINK = config.getint ( 'blink' , 'MAX_COUNTER_BLINK' ) - # cv 2.1 se bit = 1 allora inverto segnale in ingresso... - + # cv 2.1 se bit = 1 allora inverto segnale in ingresso... B_inverting[0] = config.getint ( 'invert' , 'bit0' ) B_inverting[1] = config.getint ( 'invert' , 'bit1' ) B_inverting[2] = config.getint ( 'invert' , 'bit2' ) @@ -593,8 +560,7 @@ try: B_inverting[6] = config.getint ( 'invert' , 'bit6' ) B_inverting[7] = config.getint ( 'invert' , 'bit7' ) - # cv 2.2 se bit = 1 allora filtro segnali brevi ... - + # cv 2.2 se bit = 1 allora filtro segnali brevi ... B_filter[0] = config.getint ( 'filter' , 'bit0' ) B_filter[1] = config.getint ( 'filter' , 'bit1' ) B_filter[2] = config.getint ( 'filter' , 'bit2' ) @@ -655,15 +621,6 @@ logPro.info( "Start " + PROGRAM_NAME ) # lettura file configurazione - -# [id] -# idxMacchina = 2001 -# [time] -# SAMPLETIME = 0.1 -# TIMEOUTSHORT = 200 -# TIMEOUTLONG = 6000 - - print ( ' idxMacchina = %s' % ( idxMacchina ) ) print ( ' SAMPLETIME = %4.2f' % ( SAMPLETIME ) ) print ( ' TIMEOUTSHORT = %4.2f' % ( TIMEOUTSHORT ) )