#+TITLE: modular_client_python
#+AUTHOR: Peter Polidoro
#+EMAIL: peterpolidoro@gmail.com

* Package Information
  - Name :: modular_client_python
  - Version :: 8.3.0
  - License :: BSD
  - URL :: https://github.com/janelia-pypi/modular_client_python
  - Author :: Peter Polidoro
  - Email :: peterpolidoro@gmail.com

  This Python package (modular_client) creates a class named
  ModularClient, which contains an instance of
  serial_device2.SerialInterface and adds methods to it, like auto
  discovery of available modular devices in Linux, Windows, and Mac OS
  X. This class automatically creates methods from available functions
  reported by the modular client when it is running the appropriate
  firmware. This is the modular device client library for communicating
  with and calling remote methods on modular device servers.

* Example Usage


  #+BEGIN_SRC python

    from modular_client import ModularClient
    dev = ModularClient()
    # Will try to automatically find device if one available. This may be slow if it
    # needs to search many serial ports. If it is not found automatically or to
    # speed up, specify port directly.
    dev = ModularClient(port='/dev/ttyACM0') # Linux specific port
    dev = ModularClient(port='/dev/tty.usbmodem262471') # Mac OS X specific port
    dev = ModularClient(port='COM3') # Windows specific port
    dev.get_device_id()
    dev.get_methods()

  #+END_SRC

  #+BEGIN_SRC python

    from modular_client import ModularClients
    devs = ModularClients()
    # Will try to automatically find all available devices. This may be slow if it
    # needs to search many serial ports. If they are not found automatically or to
    # speed up, specify ports to use.
    devs = ModularClients(use_ports=['/dev/ttyACM0','/dev/ttyACM1']) # Linux
    devs = ModularClients(use_ports='(/dev/ttyACM)[0-1]') # Linux string RE alternative
    devs = ModularClients(use_ports=['/dev/tty.usbmodem262471','/dev/tty.usbmodem262472']) # Mac OS X
    devs = ModularClients(use_ports='(/dev/tty\.usbmodem26247)[1-2]') # Mac OS X RE Alternative
    devs = ModularClients(use_ports=['COM3','COM4']) # Windows
    devs = ModularClients(use_ports='(COM)[3-4]') # Windows RE Alternative
    devs.items()
    # dev = devs[name][form_factor][serial_number]
    devs = ModularClients(use_ports='(/dev/ttyACM)[0-1]',keys=[0,1])
    dev = devs[0]
    devs = ModularClients(use_ports='(/dev/ttyACM)[0-1]',keys='(device)[0-1]')
    dev = devs['device0']
    devs = ModularClients(use_ports='(/dev/ttyACM)[0-1]',ports_as_keys=True)
    dev = devs['/dev/ttyACM0']

  #+END_SRC

* More Detailed Modular Device Information

  [[https://github.com/janelia-modular-devices/modular-devices]]

* Installation

  [[https://github.com/janelia-pypi/python_setup]]

** Install Arduino and Teensyduino on your Host Machine

   [[https://github.com/janelia-arduino/arduino_setup]]

** Linux and Mac OS X

   #+BEGIN_SRC sh

     python3 -m venv ~/venvs/modular_client
     source ~/venvs/modular_client/bin/activate
     pip install modular_client

   #+END_SRC

** Windows

   #+BEGIN_SRC sh

     python3 -m venv C:\venvs\modular_client
     C:\venvs\modular_client\Scripts\activate
     pip install modular_client

   #+END_SRC

* Development

** Build Docker Image

   #+BEGIN_SRC sh

     docker stop $(docker ps -aq)
     docker system prune -f
     docker build -t python_package_development:latest .

   #+END_SRC

** Run Docker Container

   #+BEGIN_SRC sh

     docker run -it --device=/dev/ttyACM0 python_package_development:latest

   #+END_SRC

** Install This Package

   #+BEGIN_SRC sh

     cd python_package
     python setup.py install

   #+END_SRC

** Run ipython and Test

   #+BEGIN_SRC sh

     ipython

   #+END_SRC

** Commit, Tag, and Upload to Pypi

   #+BEGIN_SRC sh

     # git commit ...
     # git tag ...
     python3 setup.py sdist bdist_wheel
     twine upload dist/*
     git clean -xdf

   #+END_SRC
