-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Conversation
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' |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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)') |
There was a problem hiding this comment.
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
if logFile == 'Y': | ||
f = open(currentDateTime, "w") | ||
f.write(data) | ||
if logFile == 'N': | ||
print('Script has finished running') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
… to the AvionicsMockData.py as well
Creates a file within the folder Logs and a file name with the current date as the filename.