Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
yjchu | c8453eac62 | |
yjchu | e9cc977949 | |
yjchu | 0fe6bc1262 | |
yjchu | 6a5545676f |
|
@ -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,26 +95,27 @@ c = np.array(c)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Get Data from Shared Memory_DO #
|
# Get Data from Shared Memory_DO #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
shm_DO = shared_memory.SharedMemory(create=True, size=a.nbytes, name="DO-shm2")
|
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]))
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Get Data from Shared Memory_CORR #
|
# Get Data from Shared Memory_CORR #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
shm_CORR = shared_memory.SharedMemory(create=True, size=c.nbytes, name="Correction_Test2")
|
shm_CORR = shared_memory.SharedMemory(create=True, size=c.nbytes, name="Correction_Test")
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -212,62 +215,73 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
|
||||||
|
|
||||||
# PORT A
|
# PORT A
|
||||||
port_a_do_value = []
|
port_a_do_value = []
|
||||||
for i in list(b[:16]):
|
for i in list(do_value[:16]):
|
||||||
port_a_do_value.append(int(i))
|
port_a_do_value.append(int(i))
|
||||||
port_a_do_value = list(do_value[:16])
|
|
||||||
#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)
|
||||||
# suc_cnt_ai = suc_cnt_ai +1
|
# suc_cnt_ai = suc_cnt_ai +1
|
||||||
|
|
||||||
except:
|
except:
|
||||||
a_isSuccess = False
|
a_isSuccess = False
|
||||||
|
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(port_A_DO)
|
||||||
|
print("a_do fail")
|
||||||
None
|
None
|
||||||
|
|
||||||
# PORT B
|
# PORT B
|
||||||
port_b_do_value = []
|
port_b_do_value = []
|
||||||
for i in list(b[16:32]):
|
for i in list(do_value[16:32]):
|
||||||
port_b_do_value.append(int(i))
|
port_b_do_value.append(int(i))
|
||||||
#print("port b do: ", port_b_do_value)
|
#print("port b do: ", port_b_do_value)
|
||||||
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("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("b_do fail")
|
||||||
|
|
||||||
if a_isSuccess:
|
if a_isSuccess:
|
||||||
queue_a.put([timenow,ai_array, port_a_do_value])
|
queue_a.put([timenow,a_ai_data, port_a_do_value])
|
||||||
else:
|
else:
|
||||||
queue_a.put([0,ai_array, port_a_do_value])
|
queue_a.put([0,prev_a_ai, port_a_do_value])
|
||||||
|
|
||||||
if b_isSuccess:
|
if b_isSuccess:
|
||||||
queue_b.put([timenow,ai_array, port_b_do_value])
|
queue_b.put([timenow,b_ai_data, port_b_do_value])
|
||||||
else:
|
else:
|
||||||
queue_b.put([0,ai_array, port_b_do_value])
|
queue_b.put([0,prev_b_ai, port_b_do_value])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -337,11 +351,13 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
for i in ai:
|
for i in ai:
|
||||||
#짝수 current (확인 필요)
|
#짝수 current (확인 필요)
|
||||||
ai_index = ai_index +1
|
ai_index = ai_index +1
|
||||||
|
#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)
|
||||||
else:
|
else:
|
||||||
voltage.append(int(i))
|
voltage.append(int(i))
|
||||||
#print(voltage)
|
#print("voltage :", voltage)
|
||||||
|
|
||||||
|
|
||||||
calculated_voltage = voltage + np.array(correction_value_array)
|
calculated_voltage = voltage + np.array(correction_value_array)
|
||||||
|
@ -442,7 +458,7 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
|
|
||||||
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)]
|
||||||
|
|
||||||
|
@ -457,14 +473,14 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
|
|
||||||
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:
|
||||||
if count == 10:
|
if count == 10:
|
||||||
print(f"Updating e_count for index {index}")
|
#print(f"Updating e_count for index {index}")
|
||||||
#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))]
|
||||||
|
@ -473,7 +489,7 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
|
|
||||||
#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
|
||||||
|
@ -548,7 +564,7 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
print("data empty")
|
print("data empty")
|
||||||
mqtt_msg = {
|
mqtt_msg = {
|
||||||
"modelCode":"test4",
|
"modelCode":"test4",
|
||||||
"assetCode":"NQ-R04-TEST-003", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset)
|
"assetCode":"S0NQR0423090001", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset)
|
||||||
"dataType":"DATA",
|
"dataType":"DATA",
|
||||||
"data": {
|
"data": {
|
||||||
"channel": ch, # 채널 입력 <20>자
|
"channel": ch, # 채널 입력 <20>자
|
||||||
|
@ -562,7 +578,7 @@ def data_process_thread(data_queue, ch, chamber):
|
||||||
else:
|
else:
|
||||||
mqtt_msg = {
|
mqtt_msg = {
|
||||||
"modelCode":"test4",
|
"modelCode":"test4",
|
||||||
"assetCode":"NQ-R04-TEST-003", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset)
|
"assetCode":"S0NQR0423090001", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset)
|
||||||
"dataType":"DATA",
|
"dataType":"DATA",
|
||||||
"data": {
|
"data": {
|
||||||
"channel": ch, # 채널 입력 <20>자
|
"channel": ch, # 채널 입력 <20>자
|
||||||
|
@ -599,7 +615,7 @@ def timer_event_loop(e1, e2):
|
||||||
|
|
||||||
e1.set()
|
e1.set()
|
||||||
e2.set()
|
e2.set()
|
||||||
time.sleep(1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
@ -620,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))
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
{
|
||||||
|
"1": 1,
|
||||||
|
"2": 2,
|
||||||
|
"3": 3,
|
||||||
|
"4": 4,
|
||||||
|
"5": 5,
|
||||||
|
"6": 6,
|
||||||
|
"7": 7,
|
||||||
|
"8": 8,
|
||||||
|
"9": 9,
|
||||||
|
"10": 5,
|
||||||
|
"11": 5,
|
||||||
|
"12": 5,
|
||||||
|
"13": 5,
|
||||||
|
"14": 5,
|
||||||
|
"15": 15,
|
||||||
|
"16": 16,
|
||||||
|
"17": 17,
|
||||||
|
"18": 5,
|
||||||
|
"19": 5,
|
||||||
|
"20": 5,
|
||||||
|
"21": 5,
|
||||||
|
"22": 5,
|
||||||
|
"23": 5,
|
||||||
|
"24": 5,
|
||||||
|
"25": 5,
|
||||||
|
"26": 5,
|
||||||
|
"27": 5,
|
||||||
|
"28": 5,
|
||||||
|
"29": 5,
|
||||||
|
"30": 5,
|
||||||
|
"31": 31,
|
||||||
|
"32": 32,
|
||||||
|
"33": 33,
|
||||||
|
"34": 5,
|
||||||
|
"35": 5,
|
||||||
|
"36": 5,
|
||||||
|
"37": 5,
|
||||||
|
"38": 5,
|
||||||
|
"39": 5,
|
||||||
|
"40": 0,
|
||||||
|
"41": 0,
|
||||||
|
"42": 0,
|
||||||
|
"43": 0,
|
||||||
|
"44": 0,
|
||||||
|
"45": 0,
|
||||||
|
"46": 5,
|
||||||
|
"47": 47,
|
||||||
|
"48": 48,
|
||||||
|
"49": 49,
|
||||||
|
"50": 0,
|
||||||
|
"51": 0,
|
||||||
|
"52": 0,
|
||||||
|
"53": 0,
|
||||||
|
"54": 0,
|
||||||
|
"55": 0,
|
||||||
|
"56": 5,
|
||||||
|
"57": 0,
|
||||||
|
"58": 0,
|
||||||
|
"59": 0,
|
||||||
|
"60": 0,
|
||||||
|
"61": 0,
|
||||||
|
"62": 0,
|
||||||
|
"63": 0,
|
||||||
|
"64": 64
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue