Skip to content

Commit

Permalink
TM13 -> Reset to semi-stable version, add comments for read_port prob…
Browse files Browse the repository at this point in the history
…lems
  • Loading branch information
franz-sweepMe committed Apr 24, 2024
1 parent 1362f9f commit 61918af
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/Logger-PREVAC_TM1x/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class Device(EmptyDevice):

description = """
<h3>Prevac TMC1x</h3>
<p>This driver controls Prevac TM13 or TM14 thickness monitors.</p>
<p>This driver controls Prevac TM13 or TM14 thickness monitors.
This driver currently supports only single read out of the crystal frequency and might crash if too many requests
are sent.</p>
<h4>Parameters</h4>
<ul>
<li>The sample rate can only be set for TM14.</li>
Expand Down Expand Up @@ -153,7 +155,10 @@ def call(self) -> (float, float):
""" Device Functions """

def get_device_version(self) -> int:
"""Get the device version from the response to get_frequency."""
"""Get the device version from the response to get_frequency.
TODO: Not working as expected yet. The answer needs to be formatted correctly.
"""
# Send a dummy request for the sample rate to get the device version
command = 0x53
_rate = self.sample_rate_dict[str(self.sample_rate)]
Expand All @@ -164,7 +169,8 @@ def get_device_version(self) -> int:
print(f"Device version response: {response}")
print(f"Device version: {response[7]}")

return response[7]
# For now, always return TM13
return 13

def get_frequency(self) -> float:
"""Request current frequency in Hz.
Expand Down Expand Up @@ -206,7 +212,6 @@ def calculate_thickness(
)
ratio = np.arctan(impedance_ratio * np.tan(np.pi * (frequency - initial_frequency) / frequency))

# TODO: Check unit
# Convert from cm to nm
return normalization * ratio * 1e7 * -1

Expand Down Expand Up @@ -287,8 +292,6 @@ def send_dataframe(self, function_code: int, data: [int]) -> None:
]:
message += chr(char).encode("latin1")

print(f"Sent message: {message}")

self.port.write(message)

@staticmethod
Expand All @@ -302,22 +305,25 @@ def calculate_checksum(contents: list[int]) -> int:

def get_dataframe(self) -> str:
"""Get the response from the device."""

# Problem is that self.port.read() uses rstrip to remove trailing whitespaces, LF/CR or tab characters
# TODO: use of self.port.read_raw() instead of self.port.read()
# TODO: or use of self.port_properties["rstrip"] = False
# TODO: or use of self.port_properties["raw_read"] = True
# TODO: bytewise reading of the protocol
# header = self.port.read_raw(1)
# length = self.port.read_raw()
# length = ord(length)
#
# data = self.port.read_raw(length)

header = self.port.read_raw(1)
message = self.port.read()
header = message[0]
if ord(header) != self.header:
msg = f"PREVAC TM1x: Header does not match. {self.header} != {header}"
raise Exception(msg)

length = self.port.read_raw()
length = ord(length)

data = self.port.read_raw(length)
length = ord(message[1])
data = message[7: 7 + length]

# Checksum is not working, some commands do not return a checksum
# received_checksum = ord(message[-1])
Expand Down

0 comments on commit 61918af

Please sign in to comment.