1
0
Fork 0
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")
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)
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
#추<><ECB694>에 do power on 할 리스트는 어디선가 읽어서 와야 해요
#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_do_value = list(b[:16])
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
except:
isSuccess = False
if isSuccess:
prev_a_ai = ai_array
priv_a_ai = ai_array
try:
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_do_value = list(b[17:32])
try:
b_ai_data=port_B_AI.read_registers(0x32, 32)
prev_b_ai = ai_array
#b_ai_data=port_B_AI.read_registers(0x32, 32)
b_ai_data = ai_array
#prev_b_ai = ai_array
# suc_cnt_ai = suc_cnt_ai +1
except:
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_b.put([timenow,ai_array, port_b_do_value])
else:
queue_a.put([0,ai_array, port_a_do_value])
queue_b.put([0,ai_array, port_b_do_value])
queue_a.put([0,prev_a_ai, port_a_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
from multiprocessing import shared_memory
import argparse
import random
'''
전달해야할 데이터
@ -85,7 +85,7 @@ b[:] = a[:]
###############################################################################
#MQTT_TOPIC = info['mqtt']['topic']
MQTT_TOPIC = dev_info['assetcode']
MQTT_TOPIC = f"/device-data/{dev_info['assetcode']}"
MQTT_ID = info['mqtt']['id']
MQTT_PW = info['mqtt']['pw']
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_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
#추후에 do power on 할 리스트는 어디선가 읽어서 와야 해요
#추<EFBFBD><EFBFBD>에 do power on 할 리스트는 어디선가 읽어서 와야 해요
#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
if isSuccess:
prev_a_ai = a_ai_data
prev_a_ai = ai_array
try:
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])
try:
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
except:
isSuccess = False
if isSuccess:
prev_b_ai = b_ai_data
prev_b_ai = ai_array
try:
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
if isSuccess:
queue_a.put([timenow,prev_a_ai, port_a_do_value])
queue_b.put([timenow,prev_b_ai, port_b_do_value])
queue_a.put([timenow,ai_array, port_a_do_value])
queue_b.put([timenow,ai_array, port_b_do_value])
else:
queue_a.put([0,prev_a_ai, port_a_do_value])
queue_b.put([0,prev_b_ai, port_b_do_value])
queue_a.put([0,ai_array, port_a_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)
### 여기서 보냄
# 10번 시그널 으면
# 10번 시그널 <EFBFBD>으면
#
# list mqtt send
# 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)
'''
###############################################################################
# dummy data 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)
"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
}
@ -386,8 +393,8 @@ def data_process_thread(data_queue, ch, chamber):
"assetCode":"NQ-R04-TEST-003", #나중에는 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
}
@ -475,7 +482,7 @@ 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_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))
data_process_ch1 = threading.Thread(target=data_process_thread,args=(ch1_queue, 1, 1))