Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the parseData #10

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Updating the parseData #10

wants to merge 13 commits into from

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
@@ -126,14 +126,21 @@ def readSerial(ser,data):
#No packet detected
else: i+=1
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

if __name__ == "__main__":
ser = None
data = AvionicsData()
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)')
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

if __name__ == "__main__":
ser = None
data = AvionicsData()
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

f = open(currentDateTime, "w")
f.write(data)
if logFile == 'N':
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)

@@ -126,14 +126,21 @@ def readSerial(ser,data):
#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.

None yet

2 participants