From 65201ad87570d8900379a178a06c270eb93edaa7 Mon Sep 17 00:00:00 2001 From: Yeongdo Park Date: Tue, 6 Oct 2020 18:14:19 -0700 Subject: [PATCH] remove hard-coded can ids --- Main.py | 21 ++++++++++++--------- ProcessList.py | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Main.py b/Main.py index 3281f3a..d74458c 100644 --- a/Main.py +++ b/Main.py @@ -7,10 +7,13 @@ from PCANBasic import TPCANTimestamp, TPCANMsg #import matplotlib.pyplot as plt #import numpy as np -# Initialize PCAN device and set filter for incoming messages with ID 1979 +id_response = 0x7BB +id_periodic = 0x1DB + +# Initialize PCAN device and set filter for incoming messages with ID id_response PCAN = PCANBasic() res = PCAN.Initialize(PCAN_USBBUS1, PCAN_BAUD_500K) -#PCAN.FilterMessages(PCAN_USBBUS1, 1979, 1979, PCAN_MESSAGE_STANDARD) +#PCAN.FilterMessages(PCAN_USBBUS1, id_response, id_response, PCAN_MESSAGE_STANDARD) filename = input("Please Enter a File Name: ") @@ -18,8 +21,8 @@ filename = input("Please Enter a File Name: ") while True: # Filters messages so we only get cell voltage data PCAN.Reset(PCAN_USBBUS1) - PCAN.FilterMessages(PCAN_USBBUS1, 1979, 1979, PCAN_MESSAGE_STANDARD) - PCAN.FilterMessages(PCAN_USBBUS1, 475, 475, PCAN_MESSAGE_STANDARD) + PCAN.FilterMessages(PCAN_USBBUS1, id_response, id_response, PCAN_MESSAGE_STANDARD) + PCAN.FilterMessages(PCAN_USBBUS1, id_periodic, id_periodic, PCAN_MESSAGE_STANDARD) # Create empty list for cell voltage message strings # Each entry in the list is a message containing the voltage information @@ -42,7 +45,7 @@ while True: while v_message: MSG = PCAN.Read(PCAN_USBBUS1) MSG = MSG[1] - if MSG.ID == 1979: + if MSG.ID == id_response: v_message = False # For the remaining voltages, the cell voltage data is contained in bytes 1 - 7 # Concatenate byte strings @@ -55,14 +58,14 @@ while True: # Filter messages for pack voltage and current #PCAN.Reset(PCAN_USBBUS1) #time.sleep(.005) - #PCAN.FilterMessages(PCAN_USBBUS1, 475, 475, PCAN_MESSAGE_STANDARD) + #PCAN.FilterMessages(PCAN_USBBUS1, id_periodic, id_periodic, PCAN_MESSAGE_STANDARD) #time.sleep(.050) p_message = True while p_message: MSG = PCAN.Read(PCAN_USBBUS1) MSG = MSG[1] - if MSG.ID == 475: + if MSG.ID == id_periodic: p_message = False voltage_byte1 = "{0:08b}".format(MSG.DATA[2]) @@ -84,7 +87,7 @@ while True: #PCAN.Reset(PCAN_USBBUS1) #time.sleep(.005) - #PCAN.FilterMessages(PCAN_USBBUS1, 1979, 1979, PCAN_MESSAGE_STANDARD) + #PCAN.FilterMessages(PCAN_USBBUS1, id_response, id_response, PCAN_MESSAGE_STANDARD) group1_msg = [] for i in range(0, 5): @@ -97,7 +100,7 @@ while True: while p_message: MSG = PCAN.Read(PCAN_USBBUS1) MSG = MSG[1] - if MSG.ID == 1979: + if MSG.ID == id_response: p_message = False group1_msg.append(MSG) diff --git a/ProcessList.py b/ProcessList.py index 02835f2..baea772 100644 --- a/ProcessList.py +++ b/ProcessList.py @@ -6,7 +6,7 @@ def process_list(v): v_string = "".join(v[0:29])[3*8:] # Create an empty list to store the voltage of each cell - voltages = [0.0] * 97 + voltages = [0.0] * 96 for i in range(0, 96): # Each cell has a 16 bit value. Extract the next 16 bits and convert it into a float voltages[i] = float(int(v_string[(i*16):(i*16+16)], 2))