Fix gestione info verso REDIS
This commit is contained in:
@@ -161,12 +161,16 @@ def ChiudiSerialeEsci():
|
||||
#--------------------------------------------------------------
|
||||
def ReadSeriale():
|
||||
|
||||
global to_serial
|
||||
global to_retry
|
||||
global errormsglen
|
||||
# global to_serial
|
||||
# global to_retry
|
||||
# global errormsglen
|
||||
global ser
|
||||
global redIobMan
|
||||
|
||||
current = '0o'
|
||||
current = '00'
|
||||
# 0x3F se volessimo tagliare ultimi 2 bit...
|
||||
# 0xFF se se leggiamo tutti gli 8 bit...
|
||||
sigMask = 0x3F
|
||||
|
||||
try:
|
||||
|
||||
@@ -176,29 +180,20 @@ def ReadSeriale():
|
||||
if len(sRaw)> 4:
|
||||
lAns = sRaw.split('\r')
|
||||
rawVal = lAns[1]
|
||||
adesso = datetime.now()
|
||||
redIobMan.lastDataIn = adesso.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
# # val = x.replace(cmdCall,'')
|
||||
# dtEve = datetime.utcnow().strftime('%H:%M:%S')
|
||||
# print(f'{dtEve} | Read: {val}')
|
||||
|
||||
# # se non ho trovato la 'i' restituisco '00'
|
||||
# if i == len(current)-1:
|
||||
# return ret
|
||||
# else:
|
||||
# current = current[i+1:i+3]
|
||||
# # levo i due bit piu alti .....
|
||||
# current = "{0:0>2X}".format(int (current, 16) & 0X3F)
|
||||
# #end if
|
||||
|
||||
current = rawVal
|
||||
current = rawVal[0:2]
|
||||
# current = "{0:0>2X}".format(int (current, 16) & 0X3F)
|
||||
current = "{0:0>2X}".format(int (current, 16) & sigMask)
|
||||
|
||||
# richiesta dati ad IOB
|
||||
RequestData()
|
||||
# n_trials = 0
|
||||
# errormsglen = 0
|
||||
# b_ok = True # esco dal loop
|
||||
# b_ok = True # esco dal loop cd
|
||||
else:
|
||||
print('no data')
|
||||
logPro.error('Serial closed, no data')
|
||||
time.sleep(WAIT_RECONN)
|
||||
RiAvviaSeriale()
|
||||
time.sleep(WAIT_RECONN)
|
||||
@@ -208,76 +203,7 @@ def ReadSeriale():
|
||||
logPro.error (f' err. 18 - Serial Port error... --EXIT -- ---> {str(exc)}')
|
||||
RiAvviaSeriale()
|
||||
# ChiudiSerialeEsci()
|
||||
|
||||
# ret = ''
|
||||
# current = '0'
|
||||
# i = 0
|
||||
# n_trials = 0
|
||||
# errormsglen = 0
|
||||
# b_ok = False
|
||||
|
||||
# try:
|
||||
# while (not b_ok):
|
||||
# if ser.inWaiting() < MSGLEN : # se non ci sono abbastanza caratteri
|
||||
# time.sleep (.2) # attesa breve
|
||||
# n_trials = n_trials + 1
|
||||
|
||||
# if (n_trials > 5) :
|
||||
# logPro.error(f'err. 15 - msglen < 5 char - Trial # {str(errormsglen)} | {str(ser.inWaiting())}')
|
||||
# RiAvviaSeriale()
|
||||
# time.sleep(.5)
|
||||
# RequestData()
|
||||
# n_trials = 0
|
||||
# b_ok = True # esco dal loop
|
||||
# #endif n_trials
|
||||
|
||||
# else : # finchè c'è robba .. leggi e tieni i buoni
|
||||
# while ser.inWaiting() > 0 :
|
||||
# try:
|
||||
# c = ser.read(1)
|
||||
# except Exception as exc:
|
||||
# logPro.error(f'err. 13 - error on try ser.read -- EXIT --\n\n{str(exc)}')
|
||||
# ChiudiSerialeEsci()
|
||||
# #end try
|
||||
# #
|
||||
# # filtra caratteri non stampabili
|
||||
# if c > ' ' :
|
||||
# current += c
|
||||
# # sys.stdout.write(current + '<<<<\n')
|
||||
# #end while
|
||||
|
||||
# # ora il messaggio ha il formato xxxxxi00 00xxx : cerco la 'i' iniziale
|
||||
# # ora il messaggio ha il formato xxxxxI00xxx : cerco la 'I' iniziale
|
||||
# try:
|
||||
# while i < len(current) and current[i] != 'I':
|
||||
# i = i + 1
|
||||
# #end while
|
||||
# except:
|
||||
# logPro.error(f'err. 14 - error on find I >>{current}<<')
|
||||
# #end try
|
||||
|
||||
# # se non ho trovato la 'i' restituisco '00'
|
||||
# if i == len(current)-1:
|
||||
# return ret
|
||||
# else:
|
||||
# current = current[i+1:i+3]
|
||||
# # levo i due bit piu alti .....
|
||||
# current = "{0:0>2X}".format(int (current, 16) & 0X3F)
|
||||
# #end if
|
||||
|
||||
# # richiesta dati ad IOB
|
||||
# RequestData()
|
||||
# n_trials = 0
|
||||
# errormsglen = 0
|
||||
# b_ok = True # esco dal loop
|
||||
# # sys.stdout.write (current + '\n')
|
||||
# #endif
|
||||
# #end while not b_ok
|
||||
|
||||
# except Exception as e:
|
||||
# logPro.error (f' err. 18 - Serial Port error... --EXIT -- ---> {str(exc)}')
|
||||
# ChiudiSerialeEsci()
|
||||
|
||||
|
||||
return current
|
||||
#--------------------------------------------------------------
|
||||
|
||||
@@ -288,6 +214,7 @@ def ReadSeriale():
|
||||
def RequestData ():
|
||||
|
||||
global ser
|
||||
global redIobMan
|
||||
|
||||
cmdCall = '$i\r\n'
|
||||
serCall = cmdCall.encode()
|
||||
@@ -297,6 +224,8 @@ def RequestData ():
|
||||
|
||||
ser.reset_input_buffer()
|
||||
ser.write(serCall)
|
||||
adesso = datetime.now()
|
||||
redIobMan.lastDataOut = adesso.strftime("%Y-%m-%d %H:%M:%S")
|
||||
time.sleep(SAMPLETIME)
|
||||
|
||||
except Exception as exc:
|
||||
@@ -421,7 +350,7 @@ def CounterDoIncr():
|
||||
ctr = ctr % 10000 # round robin 10000 eventi x track
|
||||
cont = str(ctr)
|
||||
except:
|
||||
print('errore incremento contatore')
|
||||
logPro.error('errore incremento contatore')
|
||||
#---------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -447,7 +376,7 @@ def AvviaSeriale():
|
||||
RiAvviaSeriale()
|
||||
# ChiudiSerialeEsci()
|
||||
|
||||
print(f'\n\n{PROGRAM_NAME} - init ok \n\n')
|
||||
logPro.info(f'\n\n{PROGRAM_NAME} - init ok \n\n')
|
||||
#---------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -486,9 +415,9 @@ def RiAvviaSeriale():
|
||||
def SendWatchDog():
|
||||
# invio su redis stato
|
||||
adesso = datetime.now()
|
||||
redIobMan.lastUpdate=adesso.strftime("%Y-%m-%d %H:%M:%S")
|
||||
redIobMan.lastDataIn=adesso.strftime("%Y-%m-%d %H:%M:%S")
|
||||
redIobMan.lastDataOut=adesso.strftime("%Y-%m-%d %H:%M:%S")
|
||||
redIobMan.lastUpdate = adesso.strftime("%Y-%m-%d %H:%M:%S")
|
||||
# redIobMan.lastDataIn=adesso.strftime("%Y-%m-%d %H:%M:%S")
|
||||
# redIobMan.lastDataOut=adesso.strftime("%Y-%m-%d %H:%M:%S")
|
||||
# verificare sia DAVVERO online...
|
||||
redIobMan.online = (onLine == '1')
|
||||
rawVal = redIobMan.toJSON()
|
||||
|
||||
@@ -6,7 +6,7 @@ from datetime import datetime
|
||||
|
||||
# constants
|
||||
waitReconn=2
|
||||
sampleTime=0.15
|
||||
sampleTime=0.20
|
||||
|
||||
def doConnect():
|
||||
|
||||
Reference in New Issue
Block a user