This commit is contained in:
YujinChu 2023-09-11 05:41:27 +00:00
parent edd1801581
commit c40e686cad
2 changed files with 58 additions and 45 deletions

View File

@ -162,12 +162,16 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
#print("read thread get even") #print("read thread get even")
evt.clear() evt.clear()
prev_a_ai = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
prev_b_ai = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
ai_array = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] #prev_a_ai = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
#prev_b_ai = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
ai_array = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
random_index = random.randint(0, len(my_array) -1) random_index = random.randint(0, len(my_array) -1)
ai_array = [random.randint(1,50000) for _ in range(16)] ai_array = [random.randint(1,50000) for _ in range(16)]
prev_a_ai = ai_array
prev_b_ai = ai_array
#value list on -> do control data #value list on -> do control data
#추<><ECB694>에 do power on 할 리스트는 어디선가 읽어서 와야 해요 #추<><ECB694>에 do power on 할 리스트는 어디선가 읽어서 와야 해요
#do1 do2 나눠야 해요 #do1 do2 나눠야 해요
@ -194,13 +198,14 @@ 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 = list(b[:16]) port_a_do_value = list(b[:16])
try: try:
a_ai_data=port_A_AI.read_registers(0x32, 32) #a_ai_data=port_A_AI.read_registers(0x32, 32)
a_ai_data=ai_array
# suc_cnt_ai = suc_cnt_ai +1 # suc_cnt_ai = suc_cnt_ai +1
except: except:
isSuccess = False isSuccess = False
if isSuccess: if isSuccess:
prev_a_ai = ai_array priv_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)
@ -211,8 +216,9 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
# PORT B # PORT B
port_b_do_value = list(b[17:32]) port_b_do_value = list(b[17:32])
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 = ai_array b_ai_data = ai_array
#prev_b_ai = ai_array
# suc_cnt_ai = suc_cnt_ai +1 # suc_cnt_ai = suc_cnt_ai +1
except: except:
isSuccess = False isSuccess = False
@ -230,8 +236,8 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
queue_a.put([timenow,ai_array, port_a_do_value]) queue_a.put([timenow,ai_array, port_a_do_value])
queue_b.put([timenow,ai_array, port_b_do_value]) queue_b.put([timenow,ai_array, port_b_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])
queue_b.put([0,ai_array, port_b_do_value]) queue_b.put([0,prev_a_ai, port_b_do_value])

View File

@ -13,7 +13,7 @@ import paho.mqtt.client as mqtt
import numpy as np import numpy as np
from multiprocessing import shared_memory from multiprocessing import shared_memory
import argparse import argparse
import random
''' '''
전달해야할 데이터 전달해야할 데이터
@ -85,7 +85,7 @@ b[:] = a[:]
############################################################################### ###############################################################################
#MQTT_TOPIC = info['mqtt']['topic'] #MQTT_TOPIC = info['mqtt']['topic']
MQTT_TOPIC = dev_info['assetcode'] MQTT_TOPIC = f"/device-data/{dev_info['assetcode']}"
MQTT_ID = info['mqtt']['id'] MQTT_ID = info['mqtt']['id']
MQTT_PW = info['mqtt']['pw'] MQTT_PW = info['mqtt']['pw']
MQTT_HOST_IP = info['mqtt']['host_ip'] MQTT_HOST_IP = info['mqtt']['host_ip']
@ -165,8 +165,11 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
prev_a_ai = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] prev_a_ai = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
prev_b_ai = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] prev_b_ai = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
ai_array = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
random_index = random.randint(0, len(my_array) -1)
ai_array = [random.randint(1,50000) for _ in range(16)]
#value list on -> do control data #value list on -> do control data
#추후에 do power on 할 리스트는 어디선가 읽어서 와야 해요 #추<EFBFBD><EFBFBD>에 do power on 할 리스트는 어디선가 읽어서 와야 해요
#do1 do2 나눠야 해요 #do1 do2 나눠야 해요
@ -197,7 +200,7 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
isSuccess = False isSuccess = False
if isSuccess: if isSuccess:
prev_a_ai = a_ai_data 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)
@ -209,13 +212,13 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
port_b_do_value = list(b[17:32]) port_b_do_value = list(b[17:32])
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 = ai_array
# suc_cnt_ai = suc_cnt_ai +1 # suc_cnt_ai = suc_cnt_ai +1
except: except:
isSuccess = False isSuccess = False
if isSuccess: if isSuccess:
prev_b_ai = b_ai_data 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)
@ -224,11 +227,11 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
None None
if isSuccess: if isSuccess:
queue_a.put([timenow,prev_a_ai, port_a_do_value]) queue_a.put([timenow,ai_array, port_a_do_value])
queue_b.put([timenow,prev_b_ai, port_b_do_value]) queue_b.put([timenow,ai_array, port_b_do_value])
else: else:
queue_a.put([0,prev_a_ai, port_a_do_value]) queue_a.put([0,ai_array, port_a_do_value])
queue_b.put([0,prev_b_ai, port_b_do_value]) queue_b.put([0,ai_array, port_b_do_value])
@ -261,7 +264,7 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
} }
lists.append(data_for_list) lists.append(data_for_list)
### 여기서 보냄 ### 여기서 보냄
# 10번 시그널 으면 # 10번 시그널 <EFBFBD>으면
# #
# list mqtt send # list mqtt send
# list clear # list clear
@ -282,6 +285,10 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
# time.sleep(1) # time.sleep(1)
''' '''
###############################################################################
# dummy data thread #
###############################################################################
############################################################################### ###############################################################################
# data process thread # # data process thread #
@ -372,8 +379,8 @@ def data_process_thread(data_queue, ch, chamber):
"assetCode":"NQ-R04-TEST-003", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset) "assetCode":"NQ-R04-TEST-003", #나중에는 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
} }
@ -386,8 +393,8 @@ def data_process_thread(data_queue, ch, chamber):
"assetCode":"NQ-R04-TEST-003", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset) "assetCode":"NQ-R04-TEST-003", #나중에는 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
} }