BioImager  5.0.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
_utils.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3
19
20import threading
21import typing
22
23import serial
24
25import microscope
26import microscope.abc
27
28
29# Both pySerial and serial distribution packages install an import
30# package named serial. If both are installed we may have imported
31# the wrong one. Check it to provide a better error message. See
32# issue #232.
33if not hasattr(serial, "Serial"):
34 if hasattr(serial, "marshall"):
36 "incorrect imported package serial. It appears that the serial"
37 " package from the distribution serial, instead of pyserial, was"
38 " imported. Consider uninstalling serial and installing pySerial."
39 )
40 else:
42 "imported package serial does not have Serial class"
43 )
44
45
47 """Utility mixin for devices that only trigger "once" with software.
48
49 This mixin avoids code duplication for the many devices whose only
50 supported trigger type and trigger mode are `TriggerType.SOFTWARE`
51 and `TriggerMode.ONCE`.
52
53 """
54
55 @property
56 def trigger_type(self) -> microscope.TriggerType:
57 return microscope.TriggerType.SOFTWARE
58
59 @property
60 def trigger_mode(self) -> microscope.TriggerMode:
61 return microscope.TriggerMode.ONCE
62
64 self, ttype: microscope.TriggerType, tmode: microscope.TriggerMode
65 ) -> None:
66 if ttype is not microscope.TriggerType.SOFTWARE:
68 "the only trigger type supported is software"
69 )
70 if tmode is not microscope.TriggerMode.ONCE:
72 "the only trigger mode supported is 'once'"
73 )
74
75
77 """Utility mixin for devices that only trigger "bulb" with software.
78
79 This mixin avoids code duplication for the many devices whose only
80 supported trigger type and trigger mode are `TriggerType.SOFTWARE`
81 and `TriggerMode.BULB`.
82
83 """
84
85 @property
86 def trigger_type(self) -> microscope.TriggerType:
87 return microscope.TriggerType.SOFTWARE
88
89 @property
90 def trigger_mode(self) -> microscope.TriggerMode:
91 return microscope.TriggerMode.BULB
92
94 self, ttype: microscope.TriggerType, tmode: microscope.TriggerMode
95 ) -> None:
96 if ttype is not microscope.TriggerType.SOFTWARE:
98 "the only trigger type supported is software"
99 )
100 if tmode is not microscope.TriggerMode.BULB:
102 "the only trigger mode supported is 'bulb'"
103 )
104
105 def _do_trigger(self) -> None:
107 "trigger does not make sense in trigger mode bulb, only enable"
108 )
109
110
112 """Wraps a `Serial` instance with a lock for synchronization."""
113
114 def __init__(self, serial: serial.Serial) -> None:
115 self._serial = serial
116 self._lock = threading.RLock()
117
118 @property
119 def lock(self) -> threading.RLock:
120 return self._lock
121
122 def readline(self) -> bytes:
123 with self._lock:
124 return self._serial.readline()
125
126 def readlines(self, hint: int = -1) -> typing.List[bytes]:
127 with self._lock:
128 return self._serial.readlines(hint)
129
130 # Beware: pySerial 3.5 changed the named of its first argument
131 # from terminator to expected. See issue #233.
133 self, terminator: bytes = b"\n", size: typing.Optional[int] = None
134 ) -> bytes:
135 with self._lock:
136 return self._serial.read_until(terminator, size=size)
137
138 def write(self, data: bytes) -> int:
139 with self._lock:
140 return self._serial.write(data)
microscope.TriggerType trigger_type(self)
Definition _utils.py:86
None set_trigger(self, microscope.TriggerType ttype, microscope.TriggerMode tmode)
Definition _utils.py:95
microscope.TriggerMode trigger_mode(self)
Definition _utils.py:90
microscope.TriggerMode trigger_mode(self)
Definition _utils.py:60
None set_trigger(self, microscope.TriggerType ttype, microscope.TriggerMode tmode)
Definition _utils.py:65
microscope.TriggerType trigger_type(self)
Definition _utils.py:56
threading.RLock lock(self)
Definition _utils.py:119
int write(self, bytes data)
Definition _utils.py:138
None __init__(self, serial.Serial serial)
Definition _utils.py:114
bytes read_until(self, bytes terminator=b"\n", typing.Optional[int] size=None)
Definition _utils.py:134
typing.List[bytes] readlines(self, int hint=-1)
Definition _utils.py:126