Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions deapi/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# File containing the Client for connecting to the DE-Server
#
# Last update: 2024-08-07
# Last update: 2025-11-13
# [email protected]


Expand Down Expand Up @@ -51,11 +51,13 @@
logLevel = logging.INFO
logging.basicConfig(format="%(asctime)s DE %(levelname)-8s %(message)s", level=logLevel)
log = logging.getLogger("DECameraClientLib")
log.info("Python : " + sys.version.split("(")[0])
log.info("DEClient : " + version)
log.info("CommandVer: " + str(commandVersion))
log.info("logLevel : " + str(logging.getLevelName(logLevel)))

def print_info():
log.info(f"DEAPI Version: {version} (Command Version: {commandVersion})")
log.info("Python : " + sys.version.split("(")[0])
log.info("DEClient : " + version)
log.info("CommandVer: " + str(commandVersion))
log.info("logLevel : " + str(logging.getLevelName(logLevel)))

class Client:
"""A class for connecting to the DE-Server
Expand Down Expand Up @@ -217,7 +219,7 @@ def connect(self, host: str = "127.0.0.1", port: int = 13240, read_only=False):
self.commandVersion = 3
else:
self.commandVersion = commandVersion
print("Command Version: ", self.commandVersion)
log.info(f"Command Version: {self.commandVersion}")
self._initialize_attributes()
self.update_scan_size()
self.update_image_size()
Expand Down Expand Up @@ -988,7 +990,7 @@ def set_binning(self, bin_x, bin_y, use_hw=True):
retval = True
if commandVersion < 10:
retval = self.SetProperty(
"Binning Mode", "Hardware and Software" if useHW else "Software Only"
"Binning Mode", "Hardware and Software" if use_hw else "Software Only"
)
retval &= self.SetProperty("Binning X", bin_x)
retval &= self.SetProperty("Binning Y", bin_y)
Expand Down Expand Up @@ -1407,7 +1409,7 @@ def set_xy_array(self, positions, width=None, height=None):
packet = struct.pack("I", command.ByteSize()) + command.SerializeToString()
self.socket.send(packet)
ret = self.__ReceiveResponseForCommand(command) != False
print("response", ret)
log.info(f"response {ret}")
except socket.error:
raise socket.error(
"Error sending x-y scan positions to socket. Is the server running?"
Expand Down Expand Up @@ -1770,7 +1772,7 @@ def set_virtual_mask(self, id, w, h, mask):
log.warning("Virtual mask must be a numpy array of type uint8")
mask = mask.astype(np.uint8)
mask_bytes = mask.tobytes()
print("Sending mask of size", len(mask_bytes))
log.info(f"Sending mask of size {len(mask_bytes)}")
self.__sendToSocket(self.socket, mask_bytes, len(mask_bytes))

ret = self.__ReceiveResponseForCommand(command) != False
Expand Down Expand Up @@ -1899,9 +1901,9 @@ def get_movie_buffer(
f"expected: {totalBytes}, received: {movieBufferSize}"
)
else:
print("reading movie buffer", totalBytes)
log.info(f"reading movie buffer {totalBytes}", )
movieBuffer = self._recvFromSocket(self.socket, totalBytes)
print("Done reading movie buffer")
log.info("Done reading movie buffer")
else:
retval = False

Expand Down Expand Up @@ -2215,7 +2217,7 @@ def wait_for_saving_files(self, quiet=True):

duration = self.GetTime() - t0
if not quiet:
print(" %.1fs" % duration)
log.info(f" {duration:.1f}s")
sys.stdout.flush()

def _get_auto_attributes(self, frame_type: FrameType):
Expand Down Expand Up @@ -2385,11 +2387,7 @@ def take_trial_gain_reference(
self.SetProperty("Exposure Time (seconds)", prevExposureTime)

num_el = np.max([attr.eppixpf * frame_rate, attr.eppixps])
print(
"The number of electrons per pixel per second (eppixps): {:.2f}".format(
num_el
)
)
log.info(f"The number of electrons per pixel per second (eppixps): {num_el:.2f}")

if attr.saturation > 0.0001: # Nothing should be saturated in a gain image.
raise ValueError(
Expand Down Expand Up @@ -2449,7 +2447,7 @@ def take_gain_reference(
frame_rate, target_electrons_per_pixel, counting
)

print(
log.info(
f"Gain reference: {exposure_time:.2f} seconds, "
f"total acquisitions: {num_acquisitions}, "
)
Expand Down
2 changes: 1 addition & 1 deletion deapi/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "5.3.0"
versionInfo = list(map(int, version.split(".")))
commandVersion = (versionInfo[0] - 4) * 10 + versionInfo[1] + 2
print(f"DEAPI Version: {version} (Command Version: {commandVersion})")

Loading