forked from YujinChu/AWX_collector
최신 코드3
This commit is contained in:
parent
0fe6bc1262
commit
e9cc977949
|
@ -97,7 +97,7 @@ c = np.array(c)
|
|||
# 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[:] = a[:]
|
||||
|
@ -108,7 +108,7 @@ do_value[:] = a[:]
|
|||
# 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[:] = c[:]
|
||||
|
@ -165,16 +165,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=False, close_port_after_each_call=False) # port name, slave address (in decimal)
|
||||
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.serial.baudrate = 115200
|
||||
|
||||
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 = 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.serial.baudrate = 115200
|
||||
|
||||
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 = 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.serial.baudrate = 115200
|
||||
|
||||
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 = 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.serial.baudrate = 115200
|
||||
|
||||
|
||||
|
@ -214,17 +214,19 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
|
|||
port_a_do_value = []
|
||||
for i in list(do_value[:16]):
|
||||
port_a_do_value.append(int(i))
|
||||
port_a_do_value = list(do_value[:16])
|
||||
|
||||
#print("port a do: ", port_a_do_value)
|
||||
#print("do type: {}".format(type(port_a_do_value[0])))
|
||||
|
||||
try:
|
||||
a_ai_data=port_A_AI.read_registers(0x32, 32)
|
||||
prev_a_ai = a_ai_data
|
||||
print("a_ai ;", a_ai_data)
|
||||
# suc_cnt_ai = suc_cnt_ai +1
|
||||
|
||||
except:
|
||||
a_isSuccess = False
|
||||
print("fail")
|
||||
|
||||
#if isSuccess:
|
||||
# prev_a_ai = ai_array
|
||||
|
@ -234,6 +236,7 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
|
|||
# suc_cnt_do = suc_cnt_do +1
|
||||
|
||||
except:
|
||||
print("fail")
|
||||
None
|
||||
|
||||
# PORT B
|
||||
|
@ -248,6 +251,7 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
|
|||
|
||||
except:
|
||||
b_isSuccess = False
|
||||
print("fial")
|
||||
|
||||
#if isSuccess:
|
||||
# prev_b_ai = ai_array
|
||||
|
@ -258,16 +262,17 @@ def cwt_thread(evt, chip_index, port_a_ai_id , port_a_do_id, port_b_ai_id , port
|
|||
|
||||
except:
|
||||
None
|
||||
print("fail")
|
||||
|
||||
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:
|
||||
queue_a.put([0,ai_array, port_a_do_value])
|
||||
queue_a.put([0,prev_a_ai, port_a_do_value])
|
||||
|
||||
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:
|
||||
queue_b.put([0,ai_array, port_b_do_value])
|
||||
queue_b.put([0,prev_b_ai, port_b_do_value])
|
||||
|
||||
|
||||
|
||||
|
@ -337,11 +342,13 @@ def data_process_thread(data_queue, ch, chamber):
|
|||
for i in ai:
|
||||
#짝수 current (확인 필요)
|
||||
ai_index = ai_index +1
|
||||
print("ai list :", ai)
|
||||
if (ai_index%2) == 0:
|
||||
current.append(int(i))
|
||||
print("current :", current)
|
||||
else:
|
||||
voltage.append(int(i))
|
||||
#print(voltage)
|
||||
print("voltage :", voltage)
|
||||
|
||||
|
||||
calculated_voltage = voltage + np.array(correction_value_array)
|
||||
|
@ -551,8 +558,8 @@ def data_process_thread(data_queue, ch, chamber):
|
|||
"assetCode":"S0NQR0423090001", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset)
|
||||
"dataType":"DATA",
|
||||
"data": {
|
||||
"channel": ch, # 채널 입력 <EFBFBD>자
|
||||
"chamber":chamber, #chamber 도 입력 <EFBFBD>자
|
||||
"channel": ch, # 채널 입력 ?자
|
||||
"chamber":chamber, #chamber 도 입력 ?자
|
||||
"slot": ch, #슬롯 값은 chamber와 ch 값으로 만든다
|
||||
"list": data_list_for_send_1
|
||||
}
|
||||
|
@ -565,8 +572,8 @@ def data_process_thread(data_queue, ch, chamber):
|
|||
"assetCode":"S0NQR0423090001", #나중에는 config에서 셋팅되는 값, or model 값으로 변경 (asset)
|
||||
"dataType":"DATA",
|
||||
"data": {
|
||||
"channel": ch, # 채널 입력 <EFBFBD>자
|
||||
"chamber":chamber, #chamber 도 입력 <EFBFBD>자
|
||||
"channel": ch, # 채널 입력 ?자
|
||||
"chamber":chamber, #chamber 도 입력 ?자
|
||||
"slot": ch, #슬롯 값은 chamber와 ch 값으로 만든다
|
||||
"list": data_list_for_send_2
|
||||
}
|
||||
|
@ -578,7 +585,7 @@ def data_process_thread(data_queue, ch, chamber):
|
|||
# print(type(mqtt_msg['data']['list'][0]['do'][0]))
|
||||
|
||||
data_json_str = json.dumps(mqtt_msg, indent=4)
|
||||
#print(data_json_str)
|
||||
print(data_json_str)
|
||||
publish_json_message(client, data_json_str)
|
||||
|
||||
|
||||
|
@ -620,7 +627,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))
|
||||
|
|
Loading…
Reference in New Issue