python
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| python [2021/11/12 15:36] – add z to wait_for_device brandon | python [2026/06/16 15:15] (current) – add section for pymmcore-plus brandon | ||
|---|---|---|---|
| Line 20: | Line 20: | ||
| --> Here is an example script:# | --> Here is an example script:# | ||
| - | **Last tested on Windows | + | **Last tested on Windows |
| This class manages the serial connection. | This class manages the serial connection. | ||
| - | <code python> | + | <code python serialport.py> |
| - | # serialport.py | + | |
| from serial import Serial | from serial import Serial | ||
| from serial import SerialException | from serial import SerialException | ||
| Line 94: | Line 93: | ||
| """ | """ | ||
| # short circuits if serial port is None | # short circuits if serial port is None | ||
| - | | + | |
| - | return True | + | |
| - | else: | + | |
| - | return False | + | |
| def report_to_console(self, | def report_to_console(self, | ||
| """ | """ | ||
| Line 126: | Line 122: | ||
| --> The MS2000 class is a subclass of SerialPort and adds input validation to the constructor.# | --> The MS2000 class is a subclass of SerialPort and adds input validation to the constructor.# | ||
| - | <code python> | + | <code python ms2k.py> |
| - | # ms2k.py | + | |
| from serialport import SerialPort | from serialport import SerialPort | ||
| Line 160: | Line 155: | ||
| def moverel(self, | def moverel(self, | ||
| """ | """ | ||
| - | self.send_command(f" | + | self.send_command(f" |
| self.read_response() | self.read_response() | ||
| def moverel_axis(self, | def moverel_axis(self, | ||
| """ | """ | ||
| - | self.send_command(f" | + | self.send_command(f" |
| self.read_response() | self.read_response() | ||
| def move(self, x: int=0, y: int=0, z: int=0) -> None: | def move(self, x: int=0, y: int=0, z: int=0) -> None: | ||
| """ | """ | ||
| - | self.send_command(f" | + | self.send_command(f" |
| self.read_response() | self.read_response() | ||
| def move_axis(self, | def move_axis(self, | ||
| """ | """ | ||
| - | self.send_command(f" | + | self.send_command(f" |
| self.read_response() | self.read_response() | ||
| def set_max_speed(self, | def set_max_speed(self, | ||
| """ | """ | ||
| - | self.send_command(f" | + | self.send_command(f" |
| self.read_response() | self.read_response() | ||
| def get_position(self, | def get_position(self, | ||
| """ | """ | ||
| - | self.send_command(f" | + | self.send_command(f" |
| response = self.read_response() | response = self.read_response() | ||
| return int(response.split(" | return int(response.split(" | ||
| Line 191: | Line 186: | ||
| def get_position_um(self, | def get_position_um(self, | ||
| """ | """ | ||
| - | self.send_command(f" | + | self.send_command(f" |
| response = self.read_response() | response = self.read_response() | ||
| return float(response.split(" | return float(response.split(" | ||
| Line 202: | Line 197: | ||
| """ | """ | ||
| self.send_command(f" | self.send_command(f" | ||
| - | | + | |
| - | if "B" | + | |
| - | return True | + | def is_device_busy(self) -> bool: |
| - | | + | |
| - | return | + | |
| + | return | ||
| - | def wait_for_device(self, | + | def wait_for_device(self, |
| - | """ | + | """ |
| - | # does not report serial communications by default | + | |
| if not report: | if not report: | ||
| print(" | print(" | ||
| temp = self.report | temp = self.report | ||
| self.report = report | self.report = report | ||
| - | | + | |
| - | while x_busy or y_busy or z_busy: | + | while busy: |
| - | | + | |
| - | y_busy = self.is_axis_busy(" | + | self.report = temp |
| - | z_busy | + | |
| - | self.report = temp | + | |
| </ | </ | ||
| <-- | <-- | ||
| Line 226: | Line 219: | ||
| -->And using the class in a script:# | -->And using the class in a script:# | ||
| - | <code python> | + | <code python main.py> |
| - | # main.py | + | |
| from ms2k import MS2000 | from ms2k import MS2000 | ||
| Line 260: | Line 252: | ||
| - | Note: Make sure you enter the correct COM port and baud rate in the constructor for the MS2000 class. | + | **Note:** Make sure you enter the correct COM port and baud rate in the constructor for the MS2000 class. |
| Line 278: | Line 270: | ||
| def main(): | def main(): | ||
| hardware_cfg = " | hardware_cfg = " | ||
| - | mm_directory = " | + | mm_directory = " |
| version_info = pymmcore.CMMCore().getAPIVersionInfo() | version_info = pymmcore.CMMCore().getAPIVersionInfo() | ||
| Line 312: | Line 304: | ||
| <-- | <-- | ||
| - | \\ | + | ==== Via pymmcore-plus ==== |
| - | ==== Via Pycro-Manager ==== | + | |
| + | See the [[https:// | ||
| + | |||
| + | This library wraps pymmcore and adds additional features like an acquisition engine. This gives you access to the Micro-Manager | ||
| + | |||
| + | ==== Via pycro-manager | ||
| - | See [[https://pycro-manager.readthedocs.io/ | + | See the [[https://github.com/ |
| - | Micro-Manager which has excellent support for ASI devices built in. Using Pycro-Manager | + | Micro-Manager which has excellent support for ASI devices built in. Using pycro-manager |
| + | This requires you to run a Micro-Manager instance in the background and connect to it through a socket. There is also a headless mode where you don't have to open the ui. | ||
| {{tag> python serial}} | {{tag> python serial}} | ||
Address: 29391 W Enid Rd. Eugene, OR 97402, USA | Phone: +1 (541) 461-8181
python.1636749387.txt.gz · Last modified: by brandon
