Posts: 13
Threads: 6
Joined: Sep 2021
Hi friends,
I am reading one minute tcp data and parsing and writing to database continuous data delay is happening to update how to avoid that delay for updating .
Posts: 12,022
Threads: 484
Joined: Sep 2016
Show your code so we can provide an intelligent answer.
Posts: 13
Threads: 6
Joined: Sep 2021
Feb-09-2022, 09:42 AM
(This post was last modified: Feb-09-2022, 02:28 PM by Larz60+.)
(Feb-09-2022, 08:30 AM)Larz60+ Wrote: Show your code so we can provide an intelligent answer.
def FillReceviedData(nRecvDataArray,mac_id):
data_type_string = nRecvDataArray[0:2].decode("ASCII")
data_type_value = int(data_type_string)
# print('FillReceviedData RegDataType :' , data_type_value)
pClientRegDataType = data_type_value
# print('pClientRegDataType ',pClientRegDataType)
del nRecvDataArray[0:2]
#IPAddr, port = ipaddr
if(pClientRegDataType == ClientRegDataType.CLIENT_ID):
return
if (pClientRegDataType == ClientRegDataType.REG_DATA_NORMAL.value):
data_seconds_string = unhexlify(nRecvDataArray[0:8])
#print('data_seconds_string ',data_seconds_string)
data_seconds_value = int.from_bytes(data_seconds_string, "little")
# print('seconds ' , data_seconds_value)
del nRecvDataArray[0:8]
data_nanoseconds_string = unhexlify(nRecvDataArray[0:8])
data_nanoseconds_value = int.from_bytes(data_nanoseconds_string, "little")
# print('nanoseconds ' , data_nanoseconds_value)
del nRecvDataArray[0:8]
data_config_string = unhexlify(nRecvDataArray[0:8])
data_config_value = int.from_bytes(data_config_string, "little")
# print('config ' , data_config_value)
del nRecvDataArray[0:8]
timestamp = data_seconds_value
dt_object = datetime.fromtimestamp(timestamp)
dt_object = dt_object
timestampStr = dt_object.strftime("%d-%m-%Y %I:%M:%S.")+str(data_nanoseconds_value)
if(data_config_value & UPDATE_HALFCYCLE):
nLength = ctypes.sizeof(UpdatedatHalfCycle)
#print('\n UPDATE_HALFCYCLE nLength ',nLength)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatHalfCycle)):
print("\n Error: Recevied Data is too short for UpdatedatHalfCycle.")
return
m_pUpdatedatHalfCycle = UpdatedatHalfCycle()
m_pUpdatedatHalfCycle = UpdatedatHalfCycle.from_buffer(bytearray_RecvData)
if db_conn is not None:
return
voltage_task = ((m_pUpdatedatHalfCycle.avrmsone*VOLTAGE_MUL_FACTOR),(m_pUpdatedatHalfCycle.bvrmsone*VOLTAGE_MUL_FACTOR),
(m_pUpdatedatHalfCycle.cvrmsone*VOLTAGE_MUL_FACTOR),timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
v_sql = ''' UPDATE voltagemonitor SET avrmsone = ? ,bvrmsone = ? ,cvrmsone = ? ,voltage_updated_at = ?,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(v_sql,voltage_task)
db_conn.commit()
current_task =((m_pUpdatedatHalfCycle.airmsone*CURRENT_MUL_FACTOR),(m_pUpdatedatHalfCycle.birmsone*CURRENT_MUL_FACTOR),
(m_pUpdatedatHalfCycle.cirmsone*CURRENT_MUL_FACTOR),(m_pUpdatedatHalfCycle.nirms*CURRENT_MUL_FACTOR),
(m_pUpdatedatHalfCycle.nirmsone*CURRENT_MUL_FACTOR),(m_pUpdatedatHalfCycle.isumrms*CURRENT_MUL_FACTOR),
timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
i_sql = ''' UPDATE currentmonitor SET airmsone = ? ,birmsone = ? ,cirmsone = ? ,nirms = ? ,nirmsone = ? ,isumrms = ? ,current_updated_at = ?,
updated_at = ? WHERE mac_id = ?'''
db_conn.execute(i_sql,current_task)
db_conn.commit()
#db_conn.commit()
del nRecvDataArray[0:nLength]
if (data_config_value & UPDATE_10CYCLE):
nLength = ctypes.sizeof(Updatedat10Cycles)
#print('\n UPDATE_10CYCLE nLength ',nLength)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(Updatedat10Cycles)):
print("\n Error: Recevied Data is too short for Updatedat10Cycles.")
return
m_pUpdatedat10Cycles = Updatedat10Cycles()
m_pUpdatedat10Cycles = Updatedat10Cycles.from_buffer(bytearray_RecvData)
#print("\n Ipaddr ",IPAddr," m_pUpdatedat10Cycles.avrms1012: {:#x}".format(m_pUpdatedat10Cycles.avrms1012))
if db_conn is not None:
return
voltage_task = ((m_pUpdatedat10Cycles.avrms1012*VOLTAGE_MUL_FACTOR),(m_pUpdatedat10Cycles.bvrms1012*VOLTAGE_MUL_FACTOR),
(m_pUpdatedat10Cycles.cvrms1012*VOLTAGE_MUL_FACTOR),timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
v_sql = ''' UPDATE voltagemonitor SET avrms1012 = ? ,bvrms1012 = ? ,cvrms1012 = ? ,voltage_updated_at = ?,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(v_sql,voltage_task)
db_conn.commit()
current_task =((m_pUpdatedat10Cycles.airms1012*CURRENT_MUL_FACTOR),(m_pUpdatedat10Cycles.birms1012*CURRENT_MUL_FACTOR),
(m_pUpdatedat10Cycles.cirms1012*CURRENT_MUL_FACTOR),(m_pUpdatedat10Cycles.nirms1012*CURRENT_MUL_FACTOR),
timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
i_sql = ''' UPDATE currentmonitor SET airms1012 = ? ,birms1012 = ?,cirms1012 = ? ,nirms1012 = ? ,current_updated_at = ?,
updated_at = ? WHERE mac_id = ?'''
db_conn.execute(i_sql,current_task)
db_conn.commit()
#db_conn.commit()
del nRecvDataArray[0:nLength]
if (data_config_value & UPDATE_8KSPS):
nLength = ctypes.sizeof(Updatedat8ksps)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(Updatedat8ksps)):
print("\n Error: Recevied Data is too short for Updatedat8ksps.")
return
m_pUpdatedat8ksps = Updatedat8ksps()
m_pUpdatedat8ksps = Updatedat8ksps.from_buffer(bytearray_RecvData)
#print("\n Ipaddr ",IPAddr," m_pUpdatedat8ksps.avrms: {:#x}".format(m_pUpdatedat8ksps.avrms),"m_pUpdatedat8ksps.bvrms: {:#x}".format(m_pUpdatedat8ksps.bvrms), " m_pUpdatedat8ksps.cvrms: {:#x}".format(m_pUpdatedat8ksps.cvrms))
#print("\n Ipaddr ",IPAddr,' Current DataTime ',timestampStr)
#avrms = "{:#x}".format(m_pUpdatedat8ksps.avrms,'X')[::-1]
#avrms_convert=
print("\n TimeStamp: ",datetime.now().strftime("%d-%m-%Y %H:%M:%S"), " avrms: ",(m_pUpdatedat8ksps.avrms*VOLTAGE_MUL_FACTOR)," bvrms: ",(m_pUpdatedat8ksps.bvrms*VOLTAGE_MUL_FACTOR),
" cvrms: ",(m_pUpdatedat8ksps.cvrms*VOLTAGE_MUL_FACTOR))
if db_conn is not None:
return
voltage_task = ((m_pUpdatedat8ksps.avrms*VOLTAGE_MUL_FACTOR),(m_pUpdatedat8ksps.bvrms*VOLTAGE_MUL_FACTOR),
(m_pUpdatedat8ksps.cvrms*VOLTAGE_MUL_FACTOR),timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
v_sql = ''' UPDATE voltagemonitor SET avrms = ? ,bvrms = ? ,cvrms = ? ,voltage_updated_at = ?,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(v_sql,voltage_task)
db_conn.commit()
current_task =((m_pUpdatedat8ksps.airms*CURRENT_MUL_FACTOR),(m_pUpdatedat8ksps.birms*CURRENT_MUL_FACTOR),
(m_pUpdatedat8ksps.cirms*CURRENT_MUL_FACTOR),(m_pUpdatedat8ksps.aifrms*CURRENT_MUL_FACTOR),
(m_pUpdatedat8ksps.bifrms*CURRENT_MUL_FACTOR),(m_pUpdatedat8ksps.cifrms*CURRENT_MUL_FACTOR),
timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
i_sql = ''' UPDATE currentmonitor SET airms = ? ,birms = ? ,cirms = ? ,aifrms = ? ,bifrms = ? ,cifrms = ? ,current_updated_at = ?,
updated_at = ? WHERE mac_id = ?'''
db_conn.execute(i_sql,current_task)
db_conn.commit()
# db_conn.commit()
#print("\n TimeStamp: ",datetime.now().strftime("%d-%m-%Y %H:%M:%S")," airms",(m_pUpdatedat8ksps.airms*CURRENT_MUL_FACTOR),"birms",(m_pUpdatedat8ksps.birms*CURRENT_MUL_FACTOR),"cirms", (m_pUpdatedat8ksps.cirms*CURRENT_MUL_FACTOR))
del nRecvDataArray[0:nLength]
if (data_config_value & UPDATE_1_024S):
nLength = ctypes.sizeof(Updatedat1_024s)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(Updatedat1_024s)):
print("\n Error: Recevied Data is too short for Updatedat1_024s.")
return
m_pUpdatedat1_024s = Updatedat1_024s()
m_pUpdatedat1_024s = Updatedat1_024s.from_buffer(bytearray_RecvData)
#print("\n m_pUpdatedat1_024s : ",m_pUpdatedat1_024s.apf)
#print("m_pUpdatedat1_024s.apf: {:#x}".format((m_pUpdatedat1_024s.apf) ), " m_pUpdatedat1_024s.bpf: {:#x}".format((m_pUpdatedat1_024s.bpf))," m_pUpdatedat1_024s.cpf: {:#x}".format((m_pUpdatedat1_024s.cpf)))
#print("\n Phase_A_PF",((m_pUpdatedat1_024s.apf )*POWERFACTOR_MUL_FACTOR),"Phase_B_PF",((m_pUpdatedat1_024s.bpf )*POWERFACTOR_MUL_FACTOR),
#"Phase_C_PF",((m_pUpdatedat1_024s.cpf )*POWERFACTOR_MUL_FACTOR))
#print("\n m_pUpdatedat1_024s.avthd: {:#x}".format(m_pUpdatedat1_024s.avthd), " m_pUpdatedat1_024s.bvthd: {:#x}".format(m_pUpdatedat1_024s.bvthd)
#," m_pUpdatedat1_024s.cvthd: {:#x}".format(m_pUpdatedat1_024s.cvthd))
#print("\n m_pUpdatedat1_024s.avthd cal :" , (m_pUpdatedat1_024s.avthd*THD_MUL_FACTOR),"m_pUpdatedat1_024s.bvthd cal :" , (m_pUpdatedat1_024s.bvthd*THD_MUL_FACTOR),
#"m_pUpdatedat1_024s.cvthd cal :" , (m_pUpdatedat1_024s.cvthd*THD_MUL_FACTOR))
#print("\n m_pUpdatedat1_024s.aithd: {:#x}".format(m_pUpdatedat1_024s.aithd), " m_pUpdatedat1_024s.bithd: {:#x}".format(m_pUpdatedat1_024s.bithd),
#" m_pUpdatedat1_024s.cithd:{:#x}".format(m_pUpdatedat1_024s.cithd))
if db_conn is not None:
return
thd_task =(m_pUpdatedat1_024s.avthd,m_pUpdatedat1_024s.bvthd,m_pUpdatedat1_024s.cvthd,m_pUpdatedat1_024s.aithd,m_pUpdatedat1_024s.bithd,
m_pUpdatedat1_024s.cithd,(m_pUpdatedat1_024s.avthd*THD_MUL_FACTOR),(m_pUpdatedat1_024s.bvthd*THD_MUL_FACTOR),
(m_pUpdatedat1_024s.cvthd*THD_MUL_FACTOR),(m_pUpdatedat1_024s.aithd*THD_MUL_FACTOR),(m_pUpdatedat1_024s.bithd*THD_MUL_FACTOR),
(m_pUpdatedat1_024s.cithd*THD_MUL_FACTOR),timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
thd_sql = ''' UPDATE thdmonitor SET avthd = ? ,bvthd = ? ,cvthd = ? ,aithd = ?,bithd = ? ,cithd = ?,
avthd_per = ? ,bvthd_per = ? ,cvthd_per = ? ,aithd_per = ?,bithd_per = ? ,cithd_per = ?,
thd_updated_at = ? ,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(thd_sql,thd_task)
db_conn.commit()
pf_task = (m_pUpdatedat1_024s.apf,m_pUpdatedat1_024s.bpf,m_pUpdatedat1_024s.cpf,
(m_pUpdatedat1_024s.apf*POWERFACTOR_MUL_FACTOR),(m_pUpdatedat1_024s.bpf*POWERFACTOR_MUL_FACTOR),(m_pUpdatedat1_024s.cpf*POWERFACTOR_MUL_FACTOR),
timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
pf_sql = ''' UPDATE powerfactormonitor SET apf = ?, bpf = ?,cpf = ?, phase_A_pf = ?, phase_B_pf =?, phase_C_pf=?,
powerfactor_updated_at = ? ,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(pf_sql,pf_task)
db_conn.commit()
del nRecvDataArray[0:nLength]
if(data_config_value & UPDATE_NORMAL):
nLength = ctypes.sizeof(UpdatedatNormalRate)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatNormalRate)):
print("\n Error: Recevied Data is too short for UpdatedatNormalRate.")
return
m_pUpdatedatNormalRate = UpdatedatNormalRate()
m_pUpdatedatNormalRate = UpdatedatNormalRate.from_buffer(bytearray_RecvData)
if db_conn is not None:
return
voltage_task = (m_pUpdatedatNormalRate.vpeak,timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
v_sql = ''' UPDATE voltagemonitor SET vpeak = ? ,voltage_updated_at = ?,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(v_sql,voltage_task)
db_conn.commit()
current_task =(m_pUpdatedatNormalRate.ipeak,timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
i_sql = ''' UPDATE currentmonitor SET ipeak = ? ,current_updated_at = ?, updated_at = ? WHERE mac_id = ?'''
db_conn.execute(i_sql,current_task)
db_conn.commit()
del nRecvDataArray[0:nLength]
if (data_config_value & UPDATE_THRESHOLD):
nLength = ctypes.sizeof(UpdatedatSpecialRate)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatSpecialRate)):
print("\n Error: Recevied Data is too short for UpdatedatSpecialRate.")
return
m_pUpdatedatSpecialRate = UpdatedatSpecialRate()
m_pUpdatedatSpecialRate = UpdatedatSpecialRate.from_buffer(bytearray_RecvData)
del nRecvDataArray[0:nLength]
if(data_config_value & UPDATE_PWR_TIME):
nLength = ctypes.sizeof(UpdatedatPWR_TIME)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatPWR_TIME)):
print("\n Error: Recevied Data is too short for UpdatedatPWR_TIME.")
return
m_pUpdatedatPWR_TIME = UpdatedatPWR_TIME()
m_pUpdatedatPWR_TIME = UpdatedatPWR_TIME.from_buffer(bytearray_RecvData)
del nRecvDataArray[0:nLength]
if (data_config_value & UPDATE_EGY_TIME):
nLength = ctypes.sizeof(UpdatedatEGY_TIME)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatEGY_TIME)):
print("\n Error: Recevied Data is too short for UpdatedatEGY_TIME.")
return
m_pUpdatedatEGY_TIME = UpdatedatEGY_TIME()
m_pUpdatedatEGY_TIME = UpdatedatEGY_TIME.from_buffer(bytearray_RecvData)
del nRecvDataArray[0:nLength]
if(data_config_value & UPDATE_DIP):
nLength = ctypes.sizeof(UpdatedatDIPCondition)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatDIPCondition)):
print("\n Error: Recevied Data is too short for UpdatedatDIPCondition.")
return
m_pUpdatedatDIPCondition = UpdatedatDIPCondition()
m_pUpdatedatDIPCondition = UpdatedatDIPCondition.from_buffer(bytearray_RecvData)
#print("\n dipa: {:#x}".format(m_pUpdatedatDIPCondition.dipa)," dipb: {:#x}".format(m_pUpdatedatDIPCondition.dipb)," dipc: {:#x}".format(m_pUpdatedatDIPCondition.dipc),
#"dip_lvl: {:#x}".format(m_pUpdatedatDIPCondition.dip_lvl),"dip_cyc: {:#x}".format(m_pUpdatedatDIPCondition.dip_cyc))
#print("\n dip_lvl" ,(m_pUpdatedatDIPCondition.dip_lvl*VOLTAGE_MUL_FACTOR)," dip_cyc", m_pUpdatedatDIPCondition.dip_cyc,
#"dipa " ,(m_pUpdatedatDIPCondition.dipa*VOLTAGE_MUL_FACTOR)," dipb",(m_pUpdatedatDIPCondition.dipb*VOLTAGE_MUL_FACTOR),
#" dipc" ,(m_pUpdatedatDIPCondition.dipc*VOLTAGE_MUL_FACTOR))
if db_conn is not None:
return
dip_task = (m_pUpdatedatDIPCondition.dip_cyc,(m_pUpdatedatDIPCondition.dip_lvl*VOLTAGE_MUL_FACTOR),
(m_pUpdatedatDIPCondition.dipa*VOLTAGE_MUL_FACTOR),(m_pUpdatedatDIPCondition.dipb*VOLTAGE_MUL_FACTOR),
(m_pUpdatedatDIPCondition.dipc*VOLTAGE_MUL_FACTOR),True,True,True,timestampStr,timestampStr,timestampStr,
datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
dip_sql = ''' UPDATE dipmonitor SET dip_cycles=?, dip_level=?, dip_A = ?, dip_B=?, dip_C=?,
dip_A_status = ? ,dip_B_status = ?,dip_C_status = ? ,
dip_A_updated_at = ?, dip_B_updated_at = ?, dip_C_updated_at = ?,
updated_at = ? WHERE mac_id = ?'''
db_conn.execute(dip_sql,dip_task)
db_conn.commit()
del nRecvDataArray[0:nLength]
if(data_config_value & UPDATE_SWELL):
nLength = ctypes.sizeof(UpdatedatSWELLCondition)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatSWELLCondition)):
print("\n Error: Recevied Data is too short for UpdatedatSWELLCondition.")
return
m_pUpdatedatSWELLCondition = UpdatedatSWELLCondition()
m_pUpdatedatSWELLCondition = UpdatedatSWELLCondition.from_buffer(bytearray_RecvData)
#print("\nswell_leve1 ", (m_pUpdatedatSwellCondition.swell_lvl*VOLTAGE_MUL_FACTOR),
#" swell_cycles ", m_pUpdatedatSwellCondition.swell_cyc,
#" swell_A ", (m_pUpdatedatSwellCondition.swella*VOLTAGE_MUL_FACTOR),
#" swell_B " , (m_pUpdatedatSwellCondition.swellb*VOLTAGE_MUL_FACTOR),
#" swell_C " ,(m_pUpdatedatSwellCondition.swellc*VOLTAGE_MUL_FACTOR))
if db_conn is not None:
return
swell_task = (m_pUpdatedatSWELLCondition.swell_cyc,(m_pUpdatedatSWELLCondition.swell_lvl*VOLTAGE_MUL_FACTOR),
(m_pUpdatedatSWELLCondition.swella*VOLTAGE_MUL_FACTOR),(m_pUpdatedatSWELLCondition.swellb*VOLTAGE_MUL_FACTOR),
(m_pUpdatedatSWELLCondition.swellc*VOLTAGE_MUL_FACTOR),True,True,True,timestampStr,timestampStr,timestampStr,
datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
swell_sql = ''' UPDATE swellmonitor SET swell_cycles=?, swell_level=?, swell_A = ?, swell_B=?, swell_C=?,
swell_A_status = ? ,swell_B_status = ?,swell_C_status = ? ,
swell_A_updated_at = ?, swell_B_updated_at = ?, swell_C_updated_at = ?,
updated_at = ? WHERE mac_id = ?'''
db_conn.execute(swell_sql,swell_task)
db_conn.commit()
del nRecvDataArray[0:nLength]
if(data_config_value & UPDATE_ZX):
nLength = ctypes.sizeof(UpdatedatZXCondition)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatZXCondition)):
print("\n Error: Recevied Data is too short for UpdatedatSWELLCondition.")
return
m_pUpdatedatZXCondition = UpdatedatZXCondition()
m_pUpdatedatZXCondition = UpdatedatZXCondition.from_buffer(bytearray_RecvData)
#print("\n zx_thrsh ", (m_pUpdatedatZXCondition.zx_thrsh)," zx_tout " , (m_pUpdatedatZXCondition.zx_tout))
#print("\n zx_thrsh ", (m_pUpdatedatZXCondition.zx_thrsh*VOLTAGE_MUL_FACTOR),
#" zx_tout " , ((m_pUpdatedatZXCondition.zx_tout+1)/8000))
del nRecvDataArray[0:nLength]
if(data_config_value & UPDATE_OI):
nLength = ctypes.sizeof(UpdatedatOICondition)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatOICondition)):
print("\n Error: Recevied Data is too short for UpdatedatOICondition.")
return
m_pUpdatedatOICondition = UpdatedatOICondition()
m_pUpdatedatOICondition = UpdatedatOICondition.from_buffer(bytearray_RecvData)
if db_conn is not None:
return
overcurrent_task = (m_pUpdatedatOICondition.oi_lvl*CURRENT_MUL_FACTOR,(m_pUpdatedatOICondition.oia*CURRENT_MUL_FACTOR),
(m_pUpdatedatOICondition.oib*CURRENT_MUL_FACTOR),(m_pUpdatedatOICondition.oic*CURRENT_MUL_FACTOR),
(m_pUpdatedatOICondition.oin*CURRENT_MUL_FACTOR),
timestampStr,timestampStr,timestampStr,timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
overcurrent_sql = ''' UPDATE overcurrentmonitor SET oi_level = ?,oi_A = ?,oi_B = ?, oi_C = ?,oi_N = ?,
oi_A_updated_at = ?,oi_B_updated_at = ?,oi_C_updated_at = ?,oi_N_updated_at = ?,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(overcurrent_sql,overcurrent_task)
db_conn.commit()
del nRecvDataArray[0:nLength]
Larz60+ write Feb-09-2022, 02:28 PM:Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBcode tags on future posts.
Posts: 13
Threads: 6
Joined: Sep 2021
(Feb-09-2022, 09:42 AM)satyanarayana Wrote: (Feb-09-2022, 08:30 AM)Larz60+ Wrote: Show your code so we can provide an intelligent answer.
def FillReceviedData(nRecvDataArray,mac_id):
data_type_string = nRecvDataArray[0:2].decode("ASCII")
data_type_value = int(data_type_string)
# print('FillReceviedData RegDataType :' , data_type_value)
pClientRegDataType = data_type_value
# print('pClientRegDataType ',pClientRegDataType)
del nRecvDataArray[0:2]
#IPAddr, port = ipaddr
if(pClientRegDataType == ClientRegDataType.CLIENT_ID):
return
if (pClientRegDataType == ClientRegDataType.REG_DATA_NORMAL.value):
data_seconds_string = unhexlify(nRecvDataArray[0:8])
#print('data_seconds_string ',data_seconds_string)
data_seconds_value = int.from_bytes(data_seconds_string, "little")
# print('seconds ' , data_seconds_value)
del nRecvDataArray[0:8]
data_nanoseconds_string = unhexlify(nRecvDataArray[0:8])
data_nanoseconds_value = int.from_bytes(data_nanoseconds_string, "little")
# print('nanoseconds ' , data_nanoseconds_value)
del nRecvDataArray[0:8]
data_config_string = unhexlify(nRecvDataArray[0:8])
data_config_value = int.from_bytes(data_config_string, "little")
# print('config ' , data_config_value)
del nRecvDataArray[0:8]
timestamp = data_seconds_value
dt_object = datetime.fromtimestamp(timestamp)
dt_object = dt_object
timestampStr = dt_object.strftime("%d-%m-%Y %I:%M:%S.")+str(data_nanoseconds_value)
if(data_config_value & UPDATE_HALFCYCLE):
nLength = ctypes.sizeof(UpdatedatHalfCycle)
#print('\n UPDATE_HALFCYCLE nLength ',nLength)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatHalfCycle)):
print("\n Error: Recevied Data is too short for UpdatedatHalfCycle.")
return
m_pUpdatedatHalfCycle = UpdatedatHalfCycle()
m_pUpdatedatHalfCycle = UpdatedatHalfCycle.from_buffer(bytearray_RecvData)
if db_conn is not None:
return
voltage_task = ((m_pUpdatedatHalfCycle.avrmsone*VOLTAGE_MUL_FACTOR),(m_pUpdatedatHalfCycle.bvrmsone*VOLTAGE_MUL_FACTOR),
(m_pUpdatedatHalfCycle.cvrmsone*VOLTAGE_MUL_FACTOR),timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
v_sql = ''' UPDATE voltagemonitor SET avrmsone = ? ,bvrmsone = ? ,cvrmsone = ? ,voltage_updated_at = ?,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(v_sql,voltage_task)
db_conn.commit()
current_task =((m_pUpdatedatHalfCycle.airmsone*CURRENT_MUL_FACTOR),(m_pUpdatedatHalfCycle.birmsone*CURRENT_MUL_FACTOR),
(m_pUpdatedatHalfCycle.cirmsone*CURRENT_MUL_FACTOR),(m_pUpdatedatHalfCycle.nirms*CURRENT_MUL_FACTOR),
(m_pUpdatedatHalfCycle.nirmsone*CURRENT_MUL_FACTOR),(m_pUpdatedatHalfCycle.isumrms*CURRENT_MUL_FACTOR),
timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
i_sql = ''' UPDATE currentmonitor SET airmsone = ? ,birmsone = ? ,cirmsone = ? ,nirms = ? ,nirmsone = ? ,isumrms = ? ,current_updated_at = ?,
updated_at = ? WHERE mac_id = ?'''
db_conn.execute(i_sql,current_task)
db_conn.commit()
#db_conn.commit()
del nRecvDataArray[0:nLength]
if (data_config_value & UPDATE_10CYCLE):
nLength = ctypes.sizeof(Updatedat10Cycles)
#print('\n UPDATE_10CYCLE nLength ',nLength)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(Updatedat10Cycles)):
print("\n Error: Recevied Data is too short for Updatedat10Cycles.")
return
m_pUpdatedat10Cycles = Updatedat10Cycles()
m_pUpdatedat10Cycles = Updatedat10Cycles.from_buffer(bytearray_RecvData)
#print("\n Ipaddr ",IPAddr," m_pUpdatedat10Cycles.avrms1012: {:#x}".format(m_pUpdatedat10Cycles.avrms1012))
if db_conn is not None:
return
voltage_task = ((m_pUpdatedat10Cycles.avrms1012*VOLTAGE_MUL_FACTOR),(m_pUpdatedat10Cycles.bvrms1012*VOLTAGE_MUL_FACTOR),
(m_pUpdatedat10Cycles.cvrms1012*VOLTAGE_MUL_FACTOR),timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
v_sql = ''' UPDATE voltagemonitor SET avrms1012 = ? ,bvrms1012 = ? ,cvrms1012 = ? ,voltage_updated_at = ?,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(v_sql,voltage_task)
db_conn.commit()
current_task =((m_pUpdatedat10Cycles.airms1012*CURRENT_MUL_FACTOR),(m_pUpdatedat10Cycles.birms1012*CURRENT_MUL_FACTOR),
(m_pUpdatedat10Cycles.cirms1012*CURRENT_MUL_FACTOR),(m_pUpdatedat10Cycles.nirms1012*CURRENT_MUL_FACTOR),
timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
i_sql = ''' UPDATE currentmonitor SET airms1012 = ? ,birms1012 = ?,cirms1012 = ? ,nirms1012 = ? ,current_updated_at = ?,
updated_at = ? WHERE mac_id = ?'''
db_conn.execute(i_sql,current_task)
db_conn.commit()
#db_conn.commit()
del nRecvDataArray[0:nLength]
if (data_config_value & UPDATE_8KSPS):
nLength = ctypes.sizeof(Updatedat8ksps)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(Updatedat8ksps)):
print("\n Error: Recevied Data is too short for Updatedat8ksps.")
return
m_pUpdatedat8ksps = Updatedat8ksps()
m_pUpdatedat8ksps = Updatedat8ksps.from_buffer(bytearray_RecvData)
#print("\n Ipaddr ",IPAddr," m_pUpdatedat8ksps.avrms: {:#x}".format(m_pUpdatedat8ksps.avrms),"m_pUpdatedat8ksps.bvrms: {:#x}".format(m_pUpdatedat8ksps.bvrms), " m_pUpdatedat8ksps.cvrms: {:#x}".format(m_pUpdatedat8ksps.cvrms))
#print("\n Ipaddr ",IPAddr,' Current DataTime ',timestampStr)
#avrms = "{:#x}".format(m_pUpdatedat8ksps.avrms,'X')[::-1]
#avrms_convert=
print("\n TimeStamp: ",datetime.now().strftime("%d-%m-%Y %H:%M:%S"), " avrms: ",(m_pUpdatedat8ksps.avrms*VOLTAGE_MUL_FACTOR)," bvrms: ",(m_pUpdatedat8ksps.bvrms*VOLTAGE_MUL_FACTOR),
" cvrms: ",(m_pUpdatedat8ksps.cvrms*VOLTAGE_MUL_FACTOR))
if db_conn is not None:
return
voltage_task = ((m_pUpdatedat8ksps.avrms*VOLTAGE_MUL_FACTOR),(m_pUpdatedat8ksps.bvrms*VOLTAGE_MUL_FACTOR),
(m_pUpdatedat8ksps.cvrms*VOLTAGE_MUL_FACTOR),timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
v_sql = ''' UPDATE voltagemonitor SET avrms = ? ,bvrms = ? ,cvrms = ? ,voltage_updated_at = ?,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(v_sql,voltage_task)
db_conn.commit()
current_task =((m_pUpdatedat8ksps.airms*CURRENT_MUL_FACTOR),(m_pUpdatedat8ksps.birms*CURRENT_MUL_FACTOR),
(m_pUpdatedat8ksps.cirms*CURRENT_MUL_FACTOR),(m_pUpdatedat8ksps.aifrms*CURRENT_MUL_FACTOR),
(m_pUpdatedat8ksps.bifrms*CURRENT_MUL_FACTOR),(m_pUpdatedat8ksps.cifrms*CURRENT_MUL_FACTOR),
timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
i_sql = ''' UPDATE currentmonitor SET airms = ? ,birms = ? ,cirms = ? ,aifrms = ? ,bifrms = ? ,cifrms = ? ,current_updated_at = ?,
updated_at = ? WHERE mac_id = ?'''
db_conn.execute(i_sql,current_task)
db_conn.commit()
# db_conn.commit()
#print("\n TimeStamp: ",datetime.now().strftime("%d-%m-%Y %H:%M:%S")," airms",(m_pUpdatedat8ksps.airms*CURRENT_MUL_FACTOR),"birms",(m_pUpdatedat8ksps.birms*CURRENT_MUL_FACTOR),"cirms", (m_pUpdatedat8ksps.cirms*CURRENT_MUL_FACTOR))
del nRecvDataArray[0:nLength]
if (data_config_value & UPDATE_1_024S):
nLength = ctypes.sizeof(Updatedat1_024s)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(Updatedat1_024s)):
print("\n Error: Recevied Data is too short for Updatedat1_024s.")
return
m_pUpdatedat1_024s = Updatedat1_024s()
m_pUpdatedat1_024s = Updatedat1_024s.from_buffer(bytearray_RecvData)
#print("\n m_pUpdatedat1_024s : ",m_pUpdatedat1_024s.apf)
#print("m_pUpdatedat1_024s.apf: {:#x}".format((m_pUpdatedat1_024s.apf) ), " m_pUpdatedat1_024s.bpf: {:#x}".format((m_pUpdatedat1_024s.bpf))," m_pUpdatedat1_024s.cpf: {:#x}".format((m_pUpdatedat1_024s.cpf)))
#print("\n Phase_A_PF",((m_pUpdatedat1_024s.apf )*POWERFACTOR_MUL_FACTOR),"Phase_B_PF",((m_pUpdatedat1_024s.bpf )*POWERFACTOR_MUL_FACTOR),
#"Phase_C_PF",((m_pUpdatedat1_024s.cpf )*POWERFACTOR_MUL_FACTOR))
#print("\n m_pUpdatedat1_024s.avthd: {:#x}".format(m_pUpdatedat1_024s.avthd), " m_pUpdatedat1_024s.bvthd: {:#x}".format(m_pUpdatedat1_024s.bvthd)
#," m_pUpdatedat1_024s.cvthd: {:#x}".format(m_pUpdatedat1_024s.cvthd))
#print("\n m_pUpdatedat1_024s.avthd cal :" , (m_pUpdatedat1_024s.avthd*THD_MUL_FACTOR),"m_pUpdatedat1_024s.bvthd cal :" , (m_pUpdatedat1_024s.bvthd*THD_MUL_FACTOR),
#"m_pUpdatedat1_024s.cvthd cal :" , (m_pUpdatedat1_024s.cvthd*THD_MUL_FACTOR))
#print("\n m_pUpdatedat1_024s.aithd: {:#x}".format(m_pUpdatedat1_024s.aithd), " m_pUpdatedat1_024s.bithd: {:#x}".format(m_pUpdatedat1_024s.bithd),
#" m_pUpdatedat1_024s.cithd:{:#x}".format(m_pUpdatedat1_024s.cithd))
if db_conn is not None:
return
thd_task =(m_pUpdatedat1_024s.avthd,m_pUpdatedat1_024s.bvthd,m_pUpdatedat1_024s.cvthd,m_pUpdatedat1_024s.aithd,m_pUpdatedat1_024s.bithd,
m_pUpdatedat1_024s.cithd,(m_pUpdatedat1_024s.avthd*THD_MUL_FACTOR),(m_pUpdatedat1_024s.bvthd*THD_MUL_FACTOR),
(m_pUpdatedat1_024s.cvthd*THD_MUL_FACTOR),(m_pUpdatedat1_024s.aithd*THD_MUL_FACTOR),(m_pUpdatedat1_024s.bithd*THD_MUL_FACTOR),
(m_pUpdatedat1_024s.cithd*THD_MUL_FACTOR),timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
thd_sql = ''' UPDATE thdmonitor SET avthd = ? ,bvthd = ? ,cvthd = ? ,aithd = ?,bithd = ? ,cithd = ?,
avthd_per = ? ,bvthd_per = ? ,cvthd_per = ? ,aithd_per = ?,bithd_per = ? ,cithd_per = ?,
thd_updated_at = ? ,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(thd_sql,thd_task)
db_conn.commit()
pf_task = (m_pUpdatedat1_024s.apf,m_pUpdatedat1_024s.bpf,m_pUpdatedat1_024s.cpf,
(m_pUpdatedat1_024s.apf*POWERFACTOR_MUL_FACTOR),(m_pUpdatedat1_024s.bpf*POWERFACTOR_MUL_FACTOR),(m_pUpdatedat1_024s.cpf*POWERFACTOR_MUL_FACTOR),
timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
pf_sql = ''' UPDATE powerfactormonitor SET apf = ?, bpf = ?,cpf = ?, phase_A_pf = ?, phase_B_pf =?, phase_C_pf=?,
powerfactor_updated_at = ? ,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(pf_sql,pf_task)
db_conn.commit()
del nRecvDataArray[0:nLength]
if(data_config_value & UPDATE_NORMAL):
nLength = ctypes.sizeof(UpdatedatNormalRate)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatNormalRate)):
print("\n Error: Recevied Data is too short for UpdatedatNormalRate.")
return
m_pUpdatedatNormalRate = UpdatedatNormalRate()
m_pUpdatedatNormalRate = UpdatedatNormalRate.from_buffer(bytearray_RecvData)
if db_conn is not None:
return
voltage_task = (m_pUpdatedatNormalRate.vpeak,timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
v_sql = ''' UPDATE voltagemonitor SET vpeak = ? ,voltage_updated_at = ?,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(v_sql,voltage_task)
db_conn.commit()
current_task =(m_pUpdatedatNormalRate.ipeak,timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
i_sql = ''' UPDATE currentmonitor SET ipeak = ? ,current_updated_at = ?, updated_at = ? WHERE mac_id = ?'''
db_conn.execute(i_sql,current_task)
db_conn.commit()
del nRecvDataArray[0:nLength]
if (data_config_value & UPDATE_THRESHOLD):
nLength = ctypes.sizeof(UpdatedatSpecialRate)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatSpecialRate)):
print("\n Error: Recevied Data is too short for UpdatedatSpecialRate.")
return
m_pUpdatedatSpecialRate = UpdatedatSpecialRate()
m_pUpdatedatSpecialRate = UpdatedatSpecialRate.from_buffer(bytearray_RecvData)
del nRecvDataArray[0:nLength]
if(data_config_value & UPDATE_PWR_TIME):
nLength = ctypes.sizeof(UpdatedatPWR_TIME)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatPWR_TIME)):
print("\n Error: Recevied Data is too short for UpdatedatPWR_TIME.")
return
m_pUpdatedatPWR_TIME = UpdatedatPWR_TIME()
m_pUpdatedatPWR_TIME = UpdatedatPWR_TIME.from_buffer(bytearray_RecvData)
del nRecvDataArray[0:nLength]
if (data_config_value & UPDATE_EGY_TIME):
nLength = ctypes.sizeof(UpdatedatEGY_TIME)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatEGY_TIME)):
print("\n Error: Recevied Data is too short for UpdatedatEGY_TIME.")
return
m_pUpdatedatEGY_TIME = UpdatedatEGY_TIME()
m_pUpdatedatEGY_TIME = UpdatedatEGY_TIME.from_buffer(bytearray_RecvData)
del nRecvDataArray[0:nLength]
if(data_config_value & UPDATE_DIP):
nLength = ctypes.sizeof(UpdatedatDIPCondition)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatDIPCondition)):
print("\n Error: Recevied Data is too short for UpdatedatDIPCondition.")
return
m_pUpdatedatDIPCondition = UpdatedatDIPCondition()
m_pUpdatedatDIPCondition = UpdatedatDIPCondition.from_buffer(bytearray_RecvData)
#print("\n dipa: {:#x}".format(m_pUpdatedatDIPCondition.dipa)," dipb: {:#x}".format(m_pUpdatedatDIPCondition.dipb)," dipc: {:#x}".format(m_pUpdatedatDIPCondition.dipc),
#"dip_lvl: {:#x}".format(m_pUpdatedatDIPCondition.dip_lvl),"dip_cyc: {:#x}".format(m_pUpdatedatDIPCondition.dip_cyc))
#print("\n dip_lvl" ,(m_pUpdatedatDIPCondition.dip_lvl*VOLTAGE_MUL_FACTOR)," dip_cyc", m_pUpdatedatDIPCondition.dip_cyc,
#"dipa " ,(m_pUpdatedatDIPCondition.dipa*VOLTAGE_MUL_FACTOR)," dipb",(m_pUpdatedatDIPCondition.dipb*VOLTAGE_MUL_FACTOR),
#" dipc" ,(m_pUpdatedatDIPCondition.dipc*VOLTAGE_MUL_FACTOR))
if db_conn is not None:
return
dip_task = (m_pUpdatedatDIPCondition.dip_cyc,(m_pUpdatedatDIPCondition.dip_lvl*VOLTAGE_MUL_FACTOR),
(m_pUpdatedatDIPCondition.dipa*VOLTAGE_MUL_FACTOR),(m_pUpdatedatDIPCondition.dipb*VOLTAGE_MUL_FACTOR),
(m_pUpdatedatDIPCondition.dipc*VOLTAGE_MUL_FACTOR),True,True,True,timestampStr,timestampStr,timestampStr,
datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
dip_sql = ''' UPDATE dipmonitor SET dip_cycles=?, dip_level=?, dip_A = ?, dip_B=?, dip_C=?,
dip_A_status = ? ,dip_B_status = ?,dip_C_status = ? ,
dip_A_updated_at = ?, dip_B_updated_at = ?, dip_C_updated_at = ?,
updated_at = ? WHERE mac_id = ?'''
db_conn.execute(dip_sql,dip_task)
db_conn.commit()
del nRecvDataArray[0:nLength]
if(data_config_value & UPDATE_SWELL):
nLength = ctypes.sizeof(UpdatedatSWELLCondition)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatSWELLCondition)):
print("\n Error: Recevied Data is too short for UpdatedatSWELLCondition.")
return
m_pUpdatedatSWELLCondition = UpdatedatSWELLCondition()
m_pUpdatedatSWELLCondition = UpdatedatSWELLCondition.from_buffer(bytearray_RecvData)
#print("\nswell_leve1 ", (m_pUpdatedatSwellCondition.swell_lvl*VOLTAGE_MUL_FACTOR),
#" swell_cycles ", m_pUpdatedatSwellCondition.swell_cyc,
#" swell_A ", (m_pUpdatedatSwellCondition.swella*VOLTAGE_MUL_FACTOR),
#" swell_B " , (m_pUpdatedatSwellCondition.swellb*VOLTAGE_MUL_FACTOR),
#" swell_C " ,(m_pUpdatedatSwellCondition.swellc*VOLTAGE_MUL_FACTOR))
if db_conn is not None:
return
swell_task = (m_pUpdatedatSWELLCondition.swell_cyc,(m_pUpdatedatSWELLCondition.swell_lvl*VOLTAGE_MUL_FACTOR),
(m_pUpdatedatSWELLCondition.swella*VOLTAGE_MUL_FACTOR),(m_pUpdatedatSWELLCondition.swellb*VOLTAGE_MUL_FACTOR),
(m_pUpdatedatSWELLCondition.swellc*VOLTAGE_MUL_FACTOR),True,True,True,timestampStr,timestampStr,timestampStr,
datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
swell_sql = ''' UPDATE swellmonitor SET swell_cycles=?, swell_level=?, swell_A = ?, swell_B=?, swell_C=?,
swell_A_status = ? ,swell_B_status = ?,swell_C_status = ? ,
swell_A_updated_at = ?, swell_B_updated_at = ?, swell_C_updated_at = ?,
updated_at = ? WHERE mac_id = ?'''
db_conn.execute(swell_sql,swell_task)
db_conn.commit()
del nRecvDataArray[0:nLength]
if(data_config_value & UPDATE_ZX):
nLength = ctypes.sizeof(UpdatedatZXCondition)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatZXCondition)):
print("\n Error: Recevied Data is too short for UpdatedatSWELLCondition.")
return
m_pUpdatedatZXCondition = UpdatedatZXCondition()
m_pUpdatedatZXCondition = UpdatedatZXCondition.from_buffer(bytearray_RecvData)
#print("\n zx_thrsh ", (m_pUpdatedatZXCondition.zx_thrsh)," zx_tout " , (m_pUpdatedatZXCondition.zx_tout))
#print("\n zx_thrsh ", (m_pUpdatedatZXCondition.zx_thrsh*VOLTAGE_MUL_FACTOR),
#" zx_tout " , ((m_pUpdatedatZXCondition.zx_tout+1)/8000))
del nRecvDataArray[0:nLength]
if(data_config_value & UPDATE_OI):
nLength = ctypes.sizeof(UpdatedatOICondition)
#print('REG_DATA_NORMAL nRecvDataArray ',nRecvDataArray)
nRecvDataArray_string = unhexlify(nRecvDataArray)
bytearray_RecvData = bytearray(nRecvDataArray_string*2)
if (len(bytearray_RecvData) < ctypes.sizeof(UpdatedatOICondition)):
print("\n Error: Recevied Data is too short for UpdatedatOICondition.")
return
m_pUpdatedatOICondition = UpdatedatOICondition()
m_pUpdatedatOICondition = UpdatedatOICondition.from_buffer(bytearray_RecvData)
if db_conn is not None:
return
overcurrent_task = (m_pUpdatedatOICondition.oi_lvl*CURRENT_MUL_FACTOR,(m_pUpdatedatOICondition.oia*CURRENT_MUL_FACTOR),
(m_pUpdatedatOICondition.oib*CURRENT_MUL_FACTOR),(m_pUpdatedatOICondition.oic*CURRENT_MUL_FACTOR),
(m_pUpdatedatOICondition.oin*CURRENT_MUL_FACTOR),
timestampStr,timestampStr,timestampStr,timestampStr,datetime.now().strftime("%d-%m-%Y %H:%M:%S"),mac_id)
overcurrent_sql = ''' UPDATE overcurrentmonitor SET oi_level = ?,oi_A = ?,oi_B = ?, oi_C = ?,oi_N = ?,
oi_A_updated_at = ?,oi_B_updated_at = ?,oi_C_updated_at = ?,oi_N_updated_at = ?,updated_at = ? WHERE mac_id = ?'''
db_conn.execute(overcurrent_sql,overcurrent_task)
db_conn.commit()
del nRecvDataArray[0:nLength]
|