Skip to content

Commit

Permalink
Properly close serial connection
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleshot committed Jun 12, 2024
1 parent e4a12dc commit fde8672
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Configuration and filenames
###########################
try:
VERSION = "1.0.1"
VERSION = "1.0.2"

# Get unique hardware id of Raspberry Pi
# See: https://www.raspberrypi.com/documentation/computers/config_txt.html#the-serial-number-filter
Expand Down Expand Up @@ -274,6 +274,11 @@ def get_cpu_serial():
except Exception as e:
logging.warning("Could not get GPS coordinates: %s", str(e))

try:
sim7600.close()
except Exception as e:
logging.warning("Could not close serial connection with 4G module: %s", str(e))

###########################
# Uploading sensor data
###########################
Expand Down
7 changes: 7 additions & 0 deletions sim7600x.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ def stop_gps_session(self):
except Exception as e:
logging.error("Could not stop GPS session: %s", str(e))

def close(self):
'''Close the serial connection.'''
try:
self.ser.close()
except Exception as e:
logging.error("Could not close serial connection: %s", str(e))

if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
sim7600x = SIM7600X()
Expand Down

0 comments on commit fde8672

Please sign in to comment.