Skip to content

Conversation

@Abhay2412
Copy link
Member

Creates a file within the folder Logs and a file name with the current date as the filename.

@Abhay2412 Abhay2412 requested a review from Matt4890 July 3, 2021 17:11
parseData.py Outdated
print(data)

currentDateTime = time.strftime("%Y-%m-%dT%H-%M-%S")
currentDateTime = 'Logs/ParseDataLog' + currentDateTime + '.txt'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable should be "logFilePath" or etc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be defined in the main section (before getting Y or N)

parseData.py Outdated
ser = serial.Serial(port, 9600, timeout=0)
logFile = input('Do you want to see the current logging of data Yes(Y) or No(N)')
if logFile == 'Y':
f = open(currentDateTime, "w")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable name (see above)

parseData.py Outdated
while(True):
port = input('Enter a Serial Port to connect to:') #Linux: /dev/ttyUSBx, Windows: COMx
ser = serial.Serial(port, 9600, timeout=0)
logFile = input('Do you want to see the current logging of data Yes(Y) or No(N)')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"logFile" should be "logToFile"

parseData.py Outdated
Comment on lines 139 to 143
if logFile == 'Y':
f = open(currentDateTime, "w")
f.write(data)
if logFile == 'N':
print('Script has finished running')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Execution shouldn't continue until a definite answer has been given.
e.g.:

logToFile = None
while (logToFile == None):
  c = input("...").strip().upper()[0]
  if (c == 'Y'): logToFile = True
  else if (c == 'N'): logToFile = False

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that logToFile is a boolean after exiting the loop

print('Script has finished running')

while(ser!=None):
time.sleep(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to determine if we log to a file, we need to pass the file path to the readSerial(...) function:

readSerial(ser, data, logFilePath if (logToFile) else None)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to change the readSerial(...) definition to readSerial(ser, data, logFilePath)


#No packet detected
else: i+=1
print(data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right after printing the data, we need to log the same data if needed:

if (logFilePath != None):
  with open(logFilePath, 'a') as logFile:
    logFile.write(data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants