Skip to content

Commit

Permalink
Add get_firmware_version
Browse files Browse the repository at this point in the history
  • Loading branch information
bessman committed Aug 22, 2024
1 parent 6e52888 commit 43fe8db
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions pslab/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
GET_INDUCTANCE = Byte.pack(4)

GET_VERSION = Byte.pack(5)
GET_FW_VERSION = Byte.pack(6)

RETRIEVE_BUFFER = Byte.pack(8)
GET_HIGH_FREQUENCY = Byte.pack(9)
Expand Down
27 changes: 27 additions & 0 deletions pslab/serial_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
>>> device.disconnect()
"""

from __future__ import annotations

try:
import grp
except ImportError:
Expand Down Expand Up @@ -105,6 +107,7 @@ def __init__(
self.check_serial_access_permission()
self.connect(port=port, baudrate=baudrate, timeout=timeout)
self.connected = self.interface.is_open
self.firmware = self.get_firmware_version()

@staticmethod
def check_serial_access_permission():
Expand Down Expand Up @@ -264,6 +267,30 @@ def get_version(self) -> str:
version = self.interface.readline()
return version.decode("utf-8")

def get_firmware_version(self) -> tuple[int, int, int]:
"""Get firmware version.
Returns
-------
tuple[int, int, int]
major, minor, patch.
"""
self.send_byte(CP.COMMON)
self.send_byte(CP.GET_FW_VERSION)

try:
# Firmware version query was added in firmware version 3.0.0.
major = self.get_byte()
minor = self.get_byte()
patch = self.get_byte()
except serial.SerialException:
major = 2
minor = 0
patch = 0

return major, minor, patch

def get_ack(self) -> int:
"""Get response code from PSLab.
Expand Down

0 comments on commit 43fe8db

Please sign in to comment.