최신 코드4_printdebug

This commit is contained in:
yjchu 2023-10-18 19:21:07 +09:00
parent e9cc977949
commit c8453eac62
1 changed files with 112 additions and 103 deletions

View File

@ -66,7 +66,7 @@ with open(f"{ROOT_PATH}/config.json","r") as f:
for key in do_dict:
do_dict[key] = "1"
print(do_dict)
#print("do_dict", "\n", di_dict)
#print(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:
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 = np.array(c)
@ -93,6 +95,7 @@ c = np.array(c)
###############################################################################
# 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[:] = a[:]
#print("Get data from shm-DO : ", do_value)
print("Get data from shm-DO : ", do_value)
#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[:] = c[:]
#print("Get data from shm-CORR : ",correction_value)
print("Get data from shm-CORR : ",correction_value)
###############################################################################
@ -165,16 +168,16 @@ 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()
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_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_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_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
@ -226,17 +229,20 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
except:
a_isSuccess = False
print("fail")
print("a_ai fail")
#if isSuccess:
# prev_a_ai = ai_array
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
except:
print("fail")
print(port_A_DO)
print("a_do fail")
None
# PORT B
@ -247,22 +253,25 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
try:
b_ai_data=port_B_AI.read_registers(0x32, 32)
prev_b_ai = b_ai_data
print("b_ai ;", b_ai_data)
# suc_cnt_ai = suc_cnt_ai +1
except:
b_isSuccess = False
print("fial")
print("b_ai fail")
#if isSuccess:
# prev_b_ai = ai_array
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
except:
None
print("fail")
print("b_do fail")
if a_isSuccess:
queue_a.put([timenow,a_ai_data, port_a_do_value])
@ -342,13 +351,13 @@ def data_process_thread(data_queue, ch, chamber):
for i in ai:
#짝수 current (확인 필요)
ai_index = ai_index +1
print("ai list :", ai)
#print("ai list :", ai)
if (ai_index%2) == 0:
current.append(int(i))
print("current :", current)
#print("current :", current)
else:
voltage.append(int(i))
print("voltage :", voltage)
#print("voltage :", voltage)
calculated_voltage = voltage + np.array(correction_value_array)
@ -462,8 +471,8 @@ def data_process_thread(data_queue, ch, chamber):
#mult_element_count = [element_count[i] * do[i] for i in range(len(do))]
#이건 아닌거 같다 카운트는 계속 올라갈 거고 10일 때 DO가 켜지면 또 에러 발생임
#print("check do : " ,do)
#print("voltage list : ", calculated_voltage_list)
print("check do : " ,do)
print("voltage list : ", calculated_voltage_list)
#print("element cosunts : ", element_counts,"\r\n")
cycle_counts += 1
@ -558,8 +567,8 @@ def data_process_thread(data_queue, ch, chamber):
"assetCode":"S0NQR0423090001", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset)
"dataType":"DATA",
"data": {
"channel": ch, # 채널 입력 ?
"chamber":chamber, #chamber 도 입력 ?
"channel": ch, # 채널 입력 <EFBFBD>
"chamber":chamber, #chamber 도 입력 <EFBFBD>
"slot": ch, #슬롯 값은 chamber와 ch 값으로 만든다
"list": data_list_for_send_1
}
@ -572,8 +581,8 @@ def data_process_thread(data_queue, ch, chamber):
"assetCode":"S0NQR0423090001", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset)
"dataType":"DATA",
"data": {
"channel": ch, # 채널 입력 ?
"chamber":chamber, #chamber 도 입력 ?
"channel": ch, # 채널 입력 <EFBFBD>
"chamber":chamber, #chamber 도 입력 <EFBFBD>
"slot": ch, #슬롯 값은 chamber와 ch 값으로 만든다
"list": data_list_for_send_2
}
@ -627,8 +636,8 @@ if __name__ == '__main__':
chip0_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_chip1 = threading.Thread(target=cwt_thread,args=(chip1_evt, 1, 9,10, 13,14, ch3_queue, ch4_queue))
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, 5,6, 7,8, ch3_queue, ch4_queue))
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))