Metadata-Version: 2.4
Name: prior_optiscan2_control
Version: 0.1.0
Summary: This library was developed for control Optiscan2 (automated stage for microscopes).
Author-email: Genki Togawa <togawagenki@gmail.com>
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENCE
Requires-Dist: pyserial
Dynamic: license-file

# StageControl

This Python library was developed for control PRIOR Optiscan2 (automated microscope stage) via serial communication (RS-232C/USB).
This is supporting Spiral search in addition to the simple zigzag search.


## Main features
- **Easy connection**: Safe serial port control by the syntax `with`.
- **Two types of algorithm to search**: 
  - `simple_search`: Search in the set grid(number_of_points_x * number_of_points_y).
  - `spiral_search`: Spiral search from the initial location (points_number has to be a square number!).
- **Accurate time management**: Users can set the time of interval/shooting.


## Install

```bash
pip install prior_optiscan2_control
```


## Example

```python
import time
from datetime import datetime
from prior_optiscan2_control import StageControl

port = 'COM1'
baudrate = 9600
interval = 60 # second # one cycle to stop all the observation points
start = "2000-01-01-01-01" # YYYY-mm-dd-HH-MM
step = 100 # μm
x = 5 # number of points on x axis
y = 5 # number of points on y axis
processing_time = 2 # second

cycle = 30

with StageControl(port, baudrate, interval, step) as stage:

    stage.initialize_origin()

    start_time = datetime.strptime(start, "%Y-%m-%d-%H-%M")

    while True:
        now = datetime.now().replace(second = 0, microsecond = 0)

        if now == start_time:
            print("Observation started.")
            break

        elif now > start_time:
            raise RuntimeError("Do not set start time earlier than now.")


        time.sleep(0.5)
    
    try:
        for i in range(cycle):

            stage.simple_search(x, y, processing_time)
            print(f"{i + 1} cycles are finighed.")
    
    except KeyboardInterrupt:
        print("Observation is interrupted.")
    
    else:
        print("Observation finished properly.")

    finally:
        print("Program terminated: ", datetime.now())

```
