BioImager  4.9.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
microscope.abc.SerialDeviceMixin Class Reference
Inheritance diagram for microscope.abc.SerialDeviceMixin:
microscope.lights.cobolt.CoboltLaser microscope.lights.deepstar.DeepstarLaser microscope.lights.obis.ObisLaser microscope.lights.sapphire.SapphireLaser

Public Member Functions

 __init__ (self, **kwargs)
 

Static Public Member Functions

 lock_comms (func)
 

Public Attributes

 connection = None
 

Protected Member Functions

bytes _readline (self)
 
int _write (self, bytes command)
 

Protected Attributes

 _comms_lock = threading.RLock()
 

Detailed Description

Mixin for devices that are controlled via serial.

DEPRECATED: turns out that this was a bad idea.  A device that has
  a serial connection is not a serial connection.  The "has a" and
  the not "is a" should have told us that we should have been
  using composition instead of subclassing, but there you go.

Currently handles the flushing and locking of the comms channel
until a command has finished, and the passthrough to the serial
channel.

Definition at line 993 of file abc.py.

Constructor & Destructor Documentation

◆ __init__()

microscope.abc.SerialDeviceMixin.__init__ ( self,
** kwargs )

Definition at line 1007 of file abc.py.

1007 def __init__(self, **kwargs):
1008 super().__init__(**kwargs)
1009 # TODO: We should probably construct the connection here but
1010 # the Serial constructor takes a lot of arguments, and
1011 # it becomes tricky to separate those from arguments to
1012 # the constructor of other parent classes.
1013 self.connection = None # serial.Serial (to be constructed by child)
1014 self._comms_lock = threading.RLock()
1015

Member Function Documentation

◆ _readline()

bytes microscope.abc.SerialDeviceMixin._readline ( self)
protected
Read a line from connection without leading and trailing whitespace.

Reimplemented in microscope.lights.obis.ObisLaser.

Definition at line 1016 of file abc.py.

1016 def _readline(self) -> bytes:
1017 """Read a line from connection without leading and trailing whitespace."""
1018 return self.connection.readline().strip()
1019

◆ _write()

int microscope.abc.SerialDeviceMixin._write ( self,
bytes command )
protected
Send a command to the device.

This is not a simple passthrough to ``serial.Serial.write``,
it will append ``b'\\r\\n'`` to command.  Override this method
if a device requires a specific format.

Reimplemented in microscope.lights.deepstar.DeepstarLaser, microscope.lights.obis.ObisLaser, and microscope.lights.sapphire.SapphireLaser.

Definition at line 1020 of file abc.py.

1020 def _write(self, command: bytes) -> int:
1021 """Send a command to the device.
1022
1023 This is not a simple passthrough to ``serial.Serial.write``,
1024 it will append ``b'\\r\\n'`` to command. Override this method
1025 if a device requires a specific format.
1026 """
1027 return self.connection.write(command + b"\r\n")
1028

◆ lock_comms()

microscope.abc.SerialDeviceMixin.lock_comms ( func)
static
Decorator to flush input buffer and lock communications.

There have been problems with the DeepStar lasers returning
junk characters after the expected response, so it is
advisable to flush the input buffer prior to running a command
and subsequent readline.  It also locks the comms channel so
that a function must finish all its communications before
another can run.

Definition at line 1030 of file abc.py.

1030 def lock_comms(func):
1031 """Decorator to flush input buffer and lock communications.
1032
1033 There have been problems with the DeepStar lasers returning
1034 junk characters after the expected response, so it is
1035 advisable to flush the input buffer prior to running a command
1036 and subsequent readline. It also locks the comms channel so
1037 that a function must finish all its communications before
1038 another can run.
1039
1040 """
1041
1042 @functools.wraps(func)
1043 def wrapper(self, *args, **kwargs):
1044 with self._comms_lock:
1045 self.connection.flushInput()
1046 return func(self, *args, **kwargs)
1047
1048 return wrapper
1049
1050

Member Data Documentation

◆ _comms_lock

microscope.abc.SerialDeviceMixin._comms_lock = threading.RLock()
protected

Definition at line 1014 of file abc.py.

◆ connection

microscope.abc.SerialDeviceMixin.connection = None

Definition at line 1013 of file abc.py.


The documentation for this class was generated from the following file: