Python Development Environment Setup ####################################### These are the instructions for installing and configuring software to provide the best script development environment for |port_name|. These instructions should only be followed if you plan on developing Python code. If all you wish to do is to load an existing Python script into the station, please see the following page: :doc:`scriptload` Light weight Python coding may be done without installing the development environment. Please see :doc:`scriptmeas` The instructions are geared for a Windows PC. However, Sutron Python development may be done on other platforms too. 1. LinkComm ============================== LinkComm is the program used to communicate with |short_port_name|. It sends Python scripts to |short_port_name|, configures the setup to invoke them, and it can test them as well. LinkComm also integrates into PyCharm, allowing a one-click script send and test. Download LinkComm for Windows: |link_linkcomm_for_win| LinkComm also runs on iOS and Android: |link_linkcomm| 2. Git ================================== Python source code examples are hosted on GitHub. Git is version control software. It plugs nicely into PyCharm, simplifies installation, and allows for contribution to the Sutron Python GitHub project. While you may download those examples through your browser, if you are planning on developing Python code, you really should get `Git software `_. 2.1 Please choose one: ---------------------------- - Either install Git or download the examples A. Either Install Git ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Download Git for Windows: https://git-scm.com/download/win - Install Git - **Use default options** B. Or Download Examples ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Go to https://github.com/SutronPyto/LinkPython - Download the example files (click Clone or download and choose Download ZIP) - Extract the downloaded files to a folder of your choice (e.g. "C:\\pyto") 3. Python ============================ Python is freely available. It is required to run Python code on your PC. - Download https://www.python.org/downloads/ - |6280cc16259545ac472a1a3fcafe952b| - The latest version of Python is likely fine. We developed with 3.5. - Run the executable downloaded from python.org - **Make sure to check the "Add Python to Path" option** - Choose Install Now - If your computer requires administrative privileges to install programs, you may need to do a custom install and make sure to check box to install for all users. |e86ad1236df6be71408d6f25b3123830| You may verify installation is good and OS environment is setup by opening a command window (CMD) and typing in "python" and enter. You should see 3 arrow prompt show up indicating python is running. You can press Ctrl+Z to exit out of the python prompt. 4. PyCharm ============================= PyCharm is an integrated development environment that makes it easier to code in Python. | - PyCharm may be used to write and debug Python code. | - PyCharm may also be used to load Python scripts into Satlink. | - PyCharm features Git integration, making it easy to access the example code and contribute to the Python libraries. 4.1 Install ------------------ 1. | Download PyCharm from:  | https://www.jetbrains.com/pycharm/download/#section=windows | Make sure to get the free community version. 2. | Run the downloaded file and complete PyCharm install with default options 3A. If you have installed Git, hook into the Sutron Python project on GitHub | - |f42404ec67107a3ed5f3643108fe33d0| | - Run PyCharm | - Choose Check out from Version Control -> Git | - |d684229500f463377576feb0cdf551b1| | - For the URL, paste in |link_sutron_github| | - For the Directory, choose any local folder | - Click Clone | - At this point, the source code has been downloaded onto your PC. 3B. If you have downloaded the examples onto your computer (e.g. in "C:\\pyto"): | - Run Pycharm | - Choose Create New Project | - |f977daa87461360eeeeeec230b974bbc| | - Browse over to the folder where the examples are (e.g. in "C:\\pyto\\LinkPython-master") | - Click Create | - Choose Yes if asked to create a project from existing sources 4.2 Settings ------------------ | - |19e6b54499021d93f9687bd29d09a91f| | - Go to PyCharm -> File -> Settings -> Project -> Project Interpreter | - Check that the Python Interpreter says Python 3 | - |39a99a6be278de8fa7b1dc41878b0d95| | - The folders must be marked as source. | - Go to PyCharm -> File -> Settings -> Project -> Project Structure | - Right click pc folder and mark it as source | - Do the same for the src folder 4.3 Verification ------------------ | Verify installation by running main.py | |d1f2a5aa46686fb2dc0bc72e5bc845d3| | - In the PyCharm Project window, expand the project, expand the pc folder, right click main.py and choose Run | - If all went well, PyCharm will say 'All Tests Complete'. 5. Configure PyCharm to use LinkComm ===================================== The steps below will guide you through setting up LinkComm as an External Tool in PyCharm. Doing these steps will allow you to run your scripts on |short_port_name| directly from PyCharm. This will also allow you to easily debug your code since any errors reported by |short_port_name| will be turned into hyperlinks that jump directly to the line containing the error in your code. 5.1 Script load and test ---------------------------- | |ca557bade4290cf151b4ca76a024b9b6| | 1. PyCharm -> File -> Settings -> Tools -> External Tools | 2. Create new tool ("+" icon) | 3. Name it "Script load and test" | 4. Set "Program" to LinkComm.exe path which is usually :: "C:\Program Files (x86)\Sutron\LinkComm\LinkComm.exe" | 5. Set "Arguments" to :: --scripttest $FilePath$ | 6. Click Advanced Options | 7. Set "Output filters" to :: $FILE_PATH$, line $LINE$ | 8. Click OK 5.2 Script save ---------------------------- One more external tool needs to be created for saving scripts. | |f977daa87461360e70a2bc230b974bbc| | 1. Copy the "Script load and test" just created (icon above external tools) | 2. Rename it to "Script save" | 3. Change the "Arguments" to :: --scriptsave | 4. Click OK 5.3 Test out the connection to LinkComm -------------------------------------------------------- Now, if you go to PyCharm -> Tools -> External Tools, you will see two new options: - "Script load and test" - this will send the currently open python file to |short_port_name| and test it out. - "Script save" - this will permanently save the file last sent to |short_port_name| 5.4 Test out the connection to |short_port_name| -------------------------------------------------------- | |d810f7a197b8e701c5af872149e5d082| | 1. Power on the Sutron data logger | 2. Connect to unit via USB | 3. Run LinkComm and connect to the Sutron data logger (see manual for instructions). | 4. Leave LinkComm running. | 5. Run PyCharm and open the project. | 6. In PyCharm, open alarm.py from the src folder | 7. Go to PyCharm -> Tools -> External Tools -> Script load and test | 8. Verify output window shows the file was tested on the Sutron data logger .. |6280cc16259545ac472a1a3fcafe952b| image:: ./media/image1.png :width: 4.50000in :height: 3.00000in .. |e86ad1236df6be71408d6f25b3123830| image:: ./media/image2.png :width: 6.50000in :height: 1.25000in .. |d684229500f463377576feb0cdf551b1| image:: ./media/image3.png :width: 3.0in :height: 0.968in .. |f42404ec67107a3ed5f3643108fe33d0| image:: ./media/image4.png :width: 4.5in :height: 3.88in .. |67a86558cfb1cbbd50d91cd37bcd07ca| image:: ./media/image5.png :width: 6.50000in :height: 1.23958in .. |d810f7a197b8e701c5af872149e5d082| image:: ./media/image6.png :width: 6.1in :height: 6.0in .. |39a99a6be278de8fa7b1dc41878b0d95| image:: ./media/image7.png :width: 6.50000in :height: 2.56000in .. |19e6b54499021d93f9687bd29d09a91f| image:: ./media/image8.png :width: 6.5in :height: 3.000in .. |d1f2a5aa46686fb2dc0bc72e5bc845d3| image:: ./media/image16.png :width: 5.7in :height: 6.0in .. |ca557bade4290cf151b4ca76a024b9b6| image:: ./media/image21.png :width: 6.50000in :height: 4.11458in .. |f977daa87461360e70a2bc230b974bbc| image:: ./media/image23.png :width: 6.50000in :height: 4.11458in .. |f977daa87461360eeeeeec230b974bbc| image:: ./media/image24.png :width: 5.50000in :height: 3.44in