remove hard-coded can ids
This commit is contained in:
parent
cc2ff6901d
commit
65201ad875
2 changed files with 13 additions and 10 deletions
21
Main.py
21
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue