forked from YujinChu/AWX_collector
최신 코드4_printdebug
This commit is contained in:
parent
e9cc977949
commit
c8453eac62
215
AWX_collector.py
215
AWX_collector.py
|
@ -66,7 +66,7 @@ with open(f"{ROOT_PATH}/config.json","r") as f:
|
||||||
for key in do_dict:
|
for key in do_dict:
|
||||||
do_dict[key] = "1"
|
do_dict[key] = "1"
|
||||||
|
|
||||||
print(do_dict)
|
#print("do_dict", "\n", di_dict)
|
||||||
#print(do_dict["1"])
|
#print(do_dict["1"])
|
||||||
#print(type(do_dict["1"]))
|
#print(type(do_dict["1"]))
|
||||||
|
|
||||||
|
@ -80,7 +80,9 @@ a = np.array(a)
|
||||||
|
|
||||||
with open(f"{ROOT_PATH}/config_corr.json","r") as f:
|
with open(f"{ROOT_PATH}/config_corr.json","r") as f:
|
||||||
corr_dict = json.load(f)
|
corr_dict = json.load(f)
|
||||||
print(corr_dict)
|
#print(corr_dict)
|
||||||
|
for key in corr_dict:
|
||||||
|
corr_dict[key]= "0"
|
||||||
|
|
||||||
c = [corr_dict[str(n+1)] for n in range(64)]
|
c = [corr_dict[str(n+1)] for n in range(64)]
|
||||||
c = np.array(c)
|
c = np.array(c)
|
||||||
|
@ -93,6 +95,7 @@ c = np.array(c)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Get Data from Shared Memory_DO #
|
# Get Data from Shared Memory_DO #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -101,7 +104,7 @@ shm_DO = shared_memory.SharedMemory(create=True, size=a.nbytes, name="DO-shm")
|
||||||
|
|
||||||
do_value = np.ndarray(a.shape, dtype=a.dtype, buffer=shm_DO.buf)
|
do_value = np.ndarray(a.shape, dtype=a.dtype, buffer=shm_DO.buf)
|
||||||
do_value[:] = a[:]
|
do_value[:] = a[:]
|
||||||
#print("Get data from shm-DO : ", do_value)
|
print("Get data from shm-DO : ", do_value)
|
||||||
#print(type(do_value[0]))
|
#print(type(do_value[0]))
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -112,7 +115,7 @@ shm_CORR = shared_memory.SharedMemory(create=True, size=c.nbytes, name="Correcti
|
||||||
|
|
||||||
correction_value = np.ndarray(c.shape, dtype=c.dtype, buffer=shm_CORR.buf)
|
correction_value = np.ndarray(c.shape, dtype=c.dtype, buffer=shm_CORR.buf)
|
||||||
correction_value[:] = c[:]
|
correction_value[:] = c[:]
|
||||||
#print("Get data from shm-CORR : ",correction_value)
|
print("Get data from shm-CORR : ",correction_value)
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -165,17 +168,17 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
|
||||||
_serial_port_B.rs485_mode = serial.rs485.RS485Settings()
|
_serial_port_B.rs485_mode = serial.rs485.RS485Settings()
|
||||||
|
|
||||||
|
|
||||||
port_A_AI = minimalmodbus.Instrument(serial_dev1, port_a_ai_id, debug=True, close_port_after_each_call=False) # port name, slave address (in decimal)
|
port_A_AI = minimalmodbus.Instrument(serial_dev1, port_a_ai_id, debug=False, close_port_after_each_call=False) # port name, slave address (in decimal)
|
||||||
port_A_AI.serial.baudrate = 115200
|
port_A_AI.serial.baudrate = 115200
|
||||||
|
|
||||||
port_A_DO = minimalmodbus.Instrument(serial_dev1, port_a_do_id, debug=True, close_port_after_each_call=False) # port name, slave address (in decimal)
|
port_A_DO = minimalmodbus.Instrument(serial_dev1, port_a_do_id, debug=False, close_port_after_each_call=False) # port name, slave address (in decimal)
|
||||||
port_A_DO.serial.baudrate = 115200
|
port_A_DO.serial.baudrate = 115200
|
||||||
|
|
||||||
port_B_AI = minimalmodbus.Instrument(serial_dev2, port_b_ai_id, debug=True, close_port_after_each_call=False) # port name, slave address (in decimal)
|
port_B_AI = minimalmodbus.Instrument(serial_dev2, port_b_ai_id, debug=False, close_port_after_each_call=False) # port name, slave address (in decimal)
|
||||||
port_B_AI.serial.baudrate = 115200
|
port_B_AI.serial.baudrate = 115200
|
||||||
|
|
||||||
port_B_DO = minimalmodbus.Instrument(serial_dev2, port_b_do_id, debug=True, close_port_after_each_call=False) # port name, slave address (in decimal)
|
port_B_DO = minimalmodbus.Instrument(serial_dev2, port_b_do_id, debug=False, close_port_after_each_call=False) # port name, slave address (in decimal)
|
||||||
port_B_DO.serial.baudrate = 115200
|
port_B_DO.serial.baudrate = 115200
|
||||||
|
|
||||||
|
|
||||||
while isThreadRun:
|
while isThreadRun:
|
||||||
|
@ -189,8 +192,8 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
|
||||||
|
|
||||||
prev_a_ai = ai_array
|
prev_a_ai = ai_array
|
||||||
prev_b_ai = ai_array
|
prev_b_ai = ai_array
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
| AI1 | AI2 | DO1 | DO2 |
|
| AI1 | AI2 | DO1 | DO2 |
|
||||||
Success | 0 | 0 | x | x |
|
Success | 0 | 0 | x | x |
|
||||||
|
@ -205,7 +208,7 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
|
||||||
-> 데이터를 어떻게 할 것이냐
|
-> 데이터를 어떻게 할 것이냐
|
||||||
-> 이전 데이터가 있다면, 이전 데이터를 가지고 더미 데이터로 사용하는 방법 => 안하기로 했었음
|
-> 이전 데이터가 있다면, 이전 데이터를 가지고 더미 데이터로 사용하는 방법 => 안하기로 했었음
|
||||||
'''
|
'''
|
||||||
|
|
||||||
timenow = int(time.time()*1000)
|
timenow = int(time.time()*1000)
|
||||||
a_isSuccess = True
|
a_isSuccess = True
|
||||||
b_isSuccess = True
|
b_isSuccess = True
|
||||||
|
@ -214,29 +217,32 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
|
||||||
port_a_do_value = []
|
port_a_do_value = []
|
||||||
for i in list(do_value[:16]):
|
for i in list(do_value[:16]):
|
||||||
port_a_do_value.append(int(i))
|
port_a_do_value.append(int(i))
|
||||||
|
|
||||||
#print("port a do: ", port_a_do_value)
|
#print("port a do: ", port_a_do_value)
|
||||||
#print("do type: {}".format(type(port_a_do_value[0])))
|
#print("do type: {}".format(type(port_a_do_value[0])))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
a_ai_data=port_A_AI.read_registers(0x32, 32)
|
a_ai_data=port_A_AI.read_registers(0x32, 32)
|
||||||
prev_a_ai = a_ai_data
|
prev_a_ai = a_ai_data
|
||||||
print("a_ai ;", a_ai_data)
|
print("a_ai ;", a_ai_data)
|
||||||
# suc_cnt_ai = suc_cnt_ai +1
|
# suc_cnt_ai = suc_cnt_ai +1
|
||||||
|
|
||||||
except:
|
except:
|
||||||
a_isSuccess = False
|
a_isSuccess = False
|
||||||
print("fail")
|
print("a_ai fail")
|
||||||
|
|
||||||
#if isSuccess:
|
#if isSuccess:
|
||||||
# prev_a_ai = ai_array
|
# prev_a_ai = ai_array
|
||||||
|
|
||||||
try:
|
try:
|
||||||
port_A_DO.write_bits(0, port_a_do_value)
|
#port_A_DO.write_bits(0, port_a_do_value)
|
||||||
|
a_do_value = port_A_DO.write_bits(0, port_a_do_value)
|
||||||
|
print("a_do ;", a_do_value)
|
||||||
# suc_cnt_do = suc_cnt_do +1
|
# suc_cnt_do = suc_cnt_do +1
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print("fail")
|
print(port_A_DO)
|
||||||
|
print("a_do fail")
|
||||||
None
|
None
|
||||||
|
|
||||||
# PORT B
|
# PORT B
|
||||||
|
@ -247,23 +253,26 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
|
||||||
try:
|
try:
|
||||||
b_ai_data=port_B_AI.read_registers(0x32, 32)
|
b_ai_data=port_B_AI.read_registers(0x32, 32)
|
||||||
prev_b_ai = b_ai_data
|
prev_b_ai = b_ai_data
|
||||||
|
print("b_ai ;", b_ai_data)
|
||||||
# suc_cnt_ai = suc_cnt_ai +1
|
# suc_cnt_ai = suc_cnt_ai +1
|
||||||
|
|
||||||
except:
|
except:
|
||||||
b_isSuccess = False
|
b_isSuccess = False
|
||||||
print("fial")
|
print("b_ai fail")
|
||||||
|
|
||||||
#if isSuccess:
|
#if isSuccess:
|
||||||
# prev_b_ai = ai_array
|
# prev_b_ai = ai_array
|
||||||
|
|
||||||
try:
|
try:
|
||||||
port_B_DO.write_bits(0, port_b_do_value)
|
#port_B_DO.write_bits(0, port_b_do_value)
|
||||||
|
b_do_value = port_B_DO.write_bits(0, port_b_do_value)
|
||||||
|
print("b_do ;", b_do_value)
|
||||||
# suc_cnt_do = suc_cnt_do +1
|
# suc_cnt_do = suc_cnt_do +1
|
||||||
|
|
||||||
except:
|
except:
|
||||||
None
|
None
|
||||||
print("fail")
|
print("b_do fail")
|
||||||
|
|
||||||
if a_isSuccess:
|
if a_isSuccess:
|
||||||
queue_a.put([timenow,a_ai_data, port_a_do_value])
|
queue_a.put([timenow,a_ai_data, port_a_do_value])
|
||||||
else:
|
else:
|
||||||
|
@ -295,8 +304,8 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
below_20 = 0
|
below_20 = 0
|
||||||
element_counts = {}
|
element_counts = {}
|
||||||
current_cycle_elements = 0
|
current_cycle_elements = 0
|
||||||
cycle_counts = 0
|
cycle_counts = 0
|
||||||
|
|
||||||
while isThreadRun:
|
while isThreadRun:
|
||||||
# 0.1s 마다 발생할 것으로 예상
|
# 0.1s 마다 발생할 것으로 예상
|
||||||
timestamp, ai, do = data_queue.get()
|
timestamp, ai, do = data_queue.get()
|
||||||
|
@ -311,10 +320,10 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
|
|
||||||
|
|
||||||
#print("timestamp: {timestamp}, \n ai: {ai}, \n do: {do}" .format(timestamp=timestamp, ai=ai, do=do))
|
#print("timestamp: {timestamp}, \n ai: {ai}, \n do: {do}" .format(timestamp=timestamp, ai=ai, do=do))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Distribute AI data, Calculate value with correction #
|
# Distribute AI data, Calculate value with correction #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -325,42 +334,42 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
voltage = []
|
voltage = []
|
||||||
ai_index = 0
|
ai_index = 0
|
||||||
correction_value_array = []
|
correction_value_array = []
|
||||||
|
|
||||||
if data_queue == ch1_queue:
|
if data_queue == ch1_queue:
|
||||||
correction_value_array = np.array(correction_value[:16])
|
correction_value_array = np.array(correction_value[:16])
|
||||||
#key_to_change = str(index+1)
|
#key_to_change = str(index+1)
|
||||||
elif data_queue == ch2_queue:
|
elif data_queue == ch2_queue:
|
||||||
correction_value_array = np.array(correction_value[16:32])
|
correction_value_array = np.array(correction_value[16:32])
|
||||||
#key_to_change = str(index+17)
|
#key_to_change = str(index+17)
|
||||||
elif data_queue == ch3_queue:
|
elif data_queue == ch3_queue:
|
||||||
correction_value_array = np.array(correction_value[32:48])
|
correction_value_array = np.array(correction_value[32:48])
|
||||||
#key_to_change = str(index+33)
|
#key_to_change = str(index+33)
|
||||||
elif data_queue == ch4_queue:
|
elif data_queue == ch4_queue:
|
||||||
correction_value_array = np.array(correction_value[48:64])
|
correction_value_array = np.array(correction_value[48:64])
|
||||||
#key_to_change = str(index+49)
|
#key_to_change = str(index+49)
|
||||||
|
|
||||||
for i in ai:
|
for i in ai:
|
||||||
#짝수 current (확인 필요)
|
#짝수 current (확인 필요)
|
||||||
ai_index = ai_index +1
|
ai_index = ai_index +1
|
||||||
print("ai list :", ai)
|
#print("ai list :", ai)
|
||||||
if (ai_index%2) == 0:
|
if (ai_index%2) == 0:
|
||||||
current.append(int(i))
|
current.append(int(i))
|
||||||
print("current :", current)
|
#print("current :", current)
|
||||||
else:
|
else:
|
||||||
voltage.append(int(i))
|
voltage.append(int(i))
|
||||||
print("voltage :", voltage)
|
#print("voltage :", voltage)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
calculated_voltage = voltage + np.array(correction_value_array)
|
calculated_voltage = voltage + np.array(correction_value_array)
|
||||||
calculated_voltage_list = calculated_voltage.tolist()
|
calculated_voltage_list = calculated_voltage.tolist()
|
||||||
#print("be calculated: ", calculated_voltage)
|
#print("be calculated: ", calculated_voltage)
|
||||||
|
|
||||||
#print("do list : ", do)
|
#print("do list : ", do)
|
||||||
#print("calculated_voltage list :", calculated_voltage_list)
|
#print("calculated_voltage list :", calculated_voltage_list)
|
||||||
#mult_voltage = [do[i] * calculated_voltage_list[i] for i in range(len(do))]
|
#mult_voltage = [do[i] * calculated_voltage_list[i] for i in range(len(do))]
|
||||||
#print("multed value :", mult_voltage)
|
#print("multed value :", mult_voltage)
|
||||||
#print(type(mult_voltage))
|
#print(type(mult_voltage))
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# HJ ORG CODE #
|
# HJ ORG CODE #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -380,13 +389,13 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
else:
|
else:
|
||||||
# count reset
|
# count reset
|
||||||
error_cnt_1[voltage_cnt] = 0
|
error_cnt_1[voltage_cnt] = 0
|
||||||
|
|
||||||
voltage_cnt = voltage_cnt + 1
|
voltage_cnt = voltage_cnt + 1
|
||||||
print("voltage count:",voltage_cnt)
|
print("voltage count:",voltage_cnt)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# YJ TEST CODE #
|
# YJ TEST CODE #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -400,73 +409,73 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
element_counts = [x + 1 if y == 1 else x for x, y in zip(element_counts, do)]
|
element_counts = [x + 1 if y == 1 else x for x, y in zip(element_counts, do)]
|
||||||
#element_counts[i] = element_counts.get(i,0) + 1
|
#element_counts[i] = element_counts.get(i,0) + 1
|
||||||
print(element_counts)
|
print(element_counts)
|
||||||
|
|
||||||
#mult_element_count = [element_count[i] * do[i] for i in range(len(do))]
|
#mult_element_count = [element_count[i] * do[i] for i in range(len(do))]
|
||||||
#이건 아닌거 같다 카운트는 계속 올라갈 거고 10일 때 DO가 켜지면 또 에러 발생임
|
#이건 아닌거 같다 카운트는 계속 올라갈 거고 10일 때 DO가 켜지면 또 에러 발생임
|
||||||
cycle_counts += 1
|
cycle_counts += 1
|
||||||
|
|
||||||
for index, count in element_counts.items():
|
for index, count in element_counts.items():
|
||||||
if cycle_counts % 10 == 0:
|
if cycle_counts % 10 == 0:
|
||||||
if count == 10:
|
if count == 10:
|
||||||
#print(f"Error elements: {index}")
|
#print(f"Error elements: {index}")
|
||||||
error_cnt_1[index] = error_cnt_1[index] +1
|
error_cnt_1[index] = error_cnt_1[index] +1
|
||||||
#error_cnt_1 = [error_cnt_1[index] +1 * do[index] for index in range(len(error_cnt_1))]
|
#error_cnt_1 = [error_cnt_1[index] +1 * do[index] for index in range(len(error_cnt_1))]
|
||||||
mult_error_cnt_1 = [error_cnt_1[i] * do[i] for i in range(len(do))]
|
mult_error_cnt_1 = [error_cnt_1[i] * do[i] for i in range(len(do))]
|
||||||
#mult_error_cnt_1 = [x + 1 * y for x,y in zip(error_cnt_1, do)]
|
#mult_error_cnt_1 = [x + 1 * y for x,y in zip(error_cnt_1, do)]
|
||||||
|
|
||||||
print("check error_cnt_1 : ", error_cnt_1)
|
print("check error_cnt_1 : ", error_cnt_1)
|
||||||
print("check multed value to do index : ", mult_error_cnt_1)
|
print("check multed value to do index : ", mult_error_cnt_1)
|
||||||
|
|
||||||
global do_dict
|
global do_dict
|
||||||
|
|
||||||
#key_to_change = str(index+1)
|
#key_to_change = str(index+1)
|
||||||
if data_queue == ch1_queue:
|
if data_queue == ch1_queue:
|
||||||
key_to_change = str(index+1)
|
key_to_change = str(index+1)
|
||||||
elif data_queue == ch2_queue:
|
elif data_queue == ch2_queue:
|
||||||
key_to_change = str(index+17)
|
key_to_change = str(index+17)
|
||||||
elif data_queue == ch3_queue:
|
elif data_queue == ch3_queue:
|
||||||
key_to_change = str(index+33)
|
key_to_change = str(index+33)
|
||||||
elif data_queue == ch4_queue:
|
elif data_queue == ch4_queue:
|
||||||
key_to_change = str(index+49)
|
key_to_change = str(index+49)
|
||||||
|
|
||||||
if key_to_change in do_dict:
|
if key_to_change in do_dict:
|
||||||
do_dict[key_to_change] = "0"
|
do_dict[key_to_change] = "0"
|
||||||
with open(f"{ROOT_PATH}/config.json","w") as f:
|
with open(f"{ROOT_PATH}/config.json","w") as f:
|
||||||
json.dump(do_dict, f)
|
json.dump(do_dict, f)
|
||||||
|
|
||||||
#print("check do off from config.json: ",do_dict.values())
|
#print("check do off from config.json: ",do_dict.values())
|
||||||
|
|
||||||
element_counts[index] = 0
|
element_counts[index] = 0
|
||||||
#error_cnt_1 = 0
|
#error_cnt_1 = 0
|
||||||
#mult_error_cnt_1 = 0
|
#mult_error_cnt_1 = 0
|
||||||
else:
|
else:
|
||||||
element_counts[index] = 0
|
element_counts[index] = 0
|
||||||
'''
|
'''
|
||||||
ERR1 = 0
|
ERR1 = 0
|
||||||
#count = 0
|
#count = 0
|
||||||
#cycle_counts = 0
|
#cycle_counts = 0
|
||||||
#element_counts = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
#element_counts = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||||
|
|
||||||
for i, value in enumerate(calculated_voltage_list):
|
for i, value in enumerate(calculated_voltage_list):
|
||||||
if value <= 20000 and do[i] == 1:
|
if value <= 20000 and do[i] == 1:
|
||||||
#print(f"Updating count for index {i}")
|
#print(f"Updating count for index {i}")
|
||||||
|
|
||||||
#element_counts = [x + 1 if y == 1 else x for x, y in zip(element_counts, do)]
|
#element_counts = [x + 1 if y == 1 else x for x, y in zip(element_counts, do)]
|
||||||
|
|
||||||
#element_counts[i] += 1
|
#element_counts[i] += 1
|
||||||
element_counts[i] = element_counts.get(i,0) + 1
|
element_counts[i] = element_counts.get(i,0) + 1
|
||||||
|
|
||||||
#print("check do : " ,do)
|
#print("check do : " ,do)
|
||||||
#print("voltage list : ", calculated_voltage_list)
|
#print("voltage list : ", calculated_voltage_list)
|
||||||
|
|
||||||
#mult_element_count = [element_count[i] * do[i] for i in range(len(do))]
|
#mult_element_count = [element_count[i] * do[i] for i in range(len(do))]
|
||||||
#이건 아닌거 같다 카운트는 계속 올라갈 거고 10일 때 DO가 켜지면 또 에러 발생임
|
#이건 아닌거 같다 카운트는 계속 올라갈 거고 10일 때 DO가 켜지면 또 에러 발생임
|
||||||
|
|
||||||
#print("check do : " ,do)
|
print("check do : " ,do)
|
||||||
#print("voltage list : ", calculated_voltage_list)
|
print("voltage list : ", calculated_voltage_list)
|
||||||
#print("element cosunts : ", element_counts,"\r\n")
|
#print("element cosunts : ", element_counts,"\r\n")
|
||||||
cycle_counts += 1
|
cycle_counts += 1
|
||||||
|
|
||||||
error_cnt_1 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
error_cnt_1 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||||
for index, count in element_counts.items():
|
for index, count in element_counts.items():
|
||||||
if cycle_counts % 10 == 0:
|
if cycle_counts % 10 == 0:
|
||||||
|
@ -475,49 +484,49 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
#print(f"Error elements: {index}")
|
#print(f"Error elements: {index}")
|
||||||
error_cnt_1[index] += 1
|
error_cnt_1[index] += 1
|
||||||
#error_cnt_1 = [error_cnt_1[index] +1 * do[index] for index in range(len(error_cnt_1))]
|
#error_cnt_1 = [error_cnt_1[index] +1 * do[index] for index in range(len(error_cnt_1))]
|
||||||
|
|
||||||
#mult_error_cnt_1 = [error_cnt_1[i] * do[i] for i in range(len(do))]
|
#mult_error_cnt_1 = [error_cnt_1[i] * do[i] for i in range(len(do))]
|
||||||
|
|
||||||
#mult_error_cnt_1 = [x + 1 * y for x,y in zip(error_cnt_1, do)] //zip 함수 사용법
|
#mult_error_cnt_1 = [x + 1 * y for x,y in zip(error_cnt_1, do)] //zip 함수 사용법
|
||||||
|
|
||||||
#print("check error_cnt_1 : ", error_cnt_1)
|
#print("check error_cnt_1 : ", error_cnt_1)
|
||||||
#print("check multed value to do index : ", mult_error_cnt_1)
|
#print("check multed value to do index : ", mult_error_cnt_1)
|
||||||
|
|
||||||
global do_dict
|
global do_dict
|
||||||
|
|
||||||
#key_to_change = str(index+1)
|
#key_to_change = str(index+1)
|
||||||
if data_queue == ch1_queue:
|
if data_queue == ch1_queue:
|
||||||
key_to_change = str(index+1)
|
key_to_change = str(index+1)
|
||||||
elif data_queue == ch2_queue:
|
elif data_queue == ch2_queue:
|
||||||
key_to_change = str(index+17)
|
key_to_change = str(index+17)
|
||||||
elif data_queue == ch3_queue:
|
elif data_queue == ch3_queue:
|
||||||
key_to_change = str(index+33)
|
key_to_change = str(index+33)
|
||||||
elif data_queue == ch4_queue:
|
elif data_queue == ch4_queue:
|
||||||
key_to_change = str(index+49)
|
key_to_change = str(index+49)
|
||||||
|
|
||||||
if key_to_change in do_dict:
|
if key_to_change in do_dict:
|
||||||
do_dict[key_to_change] = "0"
|
do_dict[key_to_change] = "0"
|
||||||
with open(f"{ROOT_PATH}/config.json","w") as f:
|
with open(f"{ROOT_PATH}/config.json","w") as f:
|
||||||
json.dump(do_dict, f)
|
json.dump(do_dict, f)
|
||||||
|
|
||||||
#print("check do off from config.json: ",do_dict.values())
|
#print("check do off from config.json: ",do_dict.values())
|
||||||
|
|
||||||
element_counts[index] = 0
|
element_counts[index] = 0
|
||||||
|
|
||||||
#mult_error_cnt_1 = 0
|
#mult_error_cnt_1 = 0
|
||||||
else:
|
else:
|
||||||
element_counts[index] = 0
|
element_counts[index] = 0
|
||||||
|
|
||||||
|
|
||||||
# 로깅 기능을 넣어야 겠다...?
|
# 로깅 기능을 넣어야 겠다...?
|
||||||
# 파일 하나 열어서, 데이터를 쓴다
|
# 파일 하나 열어서, 데이터를 쓴다
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Make data form to json and Publish message #
|
# Make data form to json and Publish message #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
#데이터 만들어서 전달
|
#데이터 만들어서 전달
|
||||||
if timestamp > 0:
|
if timestamp > 0:
|
||||||
#if timestamp == 0:
|
#if timestamp == 0:
|
||||||
|
@ -535,16 +544,16 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
else:
|
else:
|
||||||
data_list_for_send_2.append(data)
|
data_list_for_send_2.append(data)
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
############## Error Do 데이터 잘려오는 증상 추정 원인 개선 방안 중 하나 ################
|
############## Error Do 데이터 잘려오는 증상 추정 원인 개선 방안 중 하나 ################
|
||||||
# -> string 만들어서 전달하자
|
# -> string 만들어서 전달하자
|
||||||
json_obj1 = json.loads(data)
|
json_obj1 = json.loads(data)
|
||||||
if(queue_select_count == 0):
|
if(queue_select_count == 0):
|
||||||
data_list_for_send_1.append(data)
|
data_list_for_send_1.append(data)
|
||||||
else:
|
else:
|
||||||
data_list_for_send_2.append(data)
|
data_list_for_send_2.append(data)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
if queue_count == 10:
|
if queue_count == 10:
|
||||||
|
@ -558,8 +567,8 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
"assetCode":"S0NQR0423090001", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset)
|
"assetCode":"S0NQR0423090001", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset)
|
||||||
"dataType":"DATA",
|
"dataType":"DATA",
|
||||||
"data": {
|
"data": {
|
||||||
"channel": ch, # 채널 입력 ?자
|
"channel": ch, # 채널 입력 <EFBFBD>자
|
||||||
"chamber":chamber, #chamber 도 입력 ?자
|
"chamber":chamber, #chamber 도 입력 <EFBFBD>자
|
||||||
"slot": ch, #슬롯 값은 chamber와 ch 값으로 만든다
|
"slot": ch, #슬롯 값은 chamber와 ch 값으로 만든다
|
||||||
"list": data_list_for_send_1
|
"list": data_list_for_send_1
|
||||||
}
|
}
|
||||||
|
@ -572,8 +581,8 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
"assetCode":"S0NQR0423090001", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset)
|
"assetCode":"S0NQR0423090001", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset)
|
||||||
"dataType":"DATA",
|
"dataType":"DATA",
|
||||||
"data": {
|
"data": {
|
||||||
"channel": ch, # 채널 입력 ?자
|
"channel": ch, # 채널 입력 <EFBFBD>자
|
||||||
"chamber":chamber, #chamber 도 입력 ?자
|
"chamber":chamber, #chamber 도 입력 <EFBFBD>자
|
||||||
"slot": ch, #슬롯 값은 chamber와 ch 값으로 만든다
|
"slot": ch, #슬롯 값은 chamber와 ch 값으로 만든다
|
||||||
"list": data_list_for_send_2
|
"list": data_list_for_send_2
|
||||||
}
|
}
|
||||||
|
@ -589,7 +598,7 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
publish_json_message(client, data_json_str)
|
publish_json_message(client, data_json_str)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -627,8 +636,8 @@ if __name__ == '__main__':
|
||||||
chip0_evt = threading.Event()
|
chip0_evt = threading.Event()
|
||||||
chip1_evt = threading.Event()
|
chip1_evt = threading.Event()
|
||||||
|
|
||||||
read_data_chip0 = threading.Thread(target=cwt_thread,args=(chip0_evt, 0, 1,2, 5,6, ch1_queue, ch2_queue)) #현재 4 개씩 연결되 어 있어서 테스트 용
|
read_data_chip0 = threading.Thread(target=cwt_thread,args=(chip0_evt, 0, 1,2, 13,14, ch1_queue, ch2_queue)) #현재 4개씩 연결되 어 있어서 테스트 용
|
||||||
read_data_chip1 = threading.Thread(target=cwt_thread,args=(chip1_evt, 1, 9,10, 13,14, ch3_queue, ch4_queue))
|
read_data_chip1 = threading.Thread(target=cwt_thread,args=(chip1_evt, 1, 5,6, 7,8, ch3_queue, ch4_queue))
|
||||||
|
|
||||||
data_process_ch1 = threading.Thread(target=data_process_thread,args=(ch1_queue, 1, 1))
|
data_process_ch1 = threading.Thread(target=data_process_thread,args=(ch1_queue, 1, 1))
|
||||||
data_process_ch2 = threading.Thread(target=data_process_thread,args=(ch2_queue, 2, 1))
|
data_process_ch2 = threading.Thread(target=data_process_thread,args=(ch2_queue, 2, 1))
|
||||||
|
@ -642,4 +651,4 @@ if __name__ == '__main__':
|
||||||
data_process_ch2.start()
|
data_process_ch2.start()
|
||||||
data_process_ch3.start()
|
data_process_ch3.start()
|
||||||
data_process_ch4.start()
|
data_process_ch4.start()
|
||||||
event_thread.start()
|
event_thread.start()
|
||||||
|
|
Loading…
Reference in New Issue