zoukankan      html  css  js  c++  java
  • 痞子衡嵌入式:串口调试工具pzh-com诞生记(1)- 环境搭建(Python2.7.14 + pySerial3.4 + wxPython4.0.3)


      大家好,我是痞子衡,是正经搞技术的痞子。今天痞子衡给大家介绍的是串口调试工具pzh-py-com诞生之环境搭建

      在写pzh-py-com时需要先搭好开发和调试环境,下表列出了开发过程中会用到的所有软件/工具包:

    一、涉及工具列表

    工具 功能 下载地址
    Python 2.7.14 Python官方包(解释器) https://www.python.org/
    pySerial 3.4 Serial Port访问的Python封装库 https://pypi.org/project/pyserial/
    https://github.com/pyserial/pyserial
    https://pythonhosted.org/pyserial/
    wxPython 4.0.3 跨平台开源GUI库 [wxWidgets](https://www.wxwidgets.org/) 的Python封装库 https://www.wxpython.org/
    https://pypi.org/project/wxPython/
    wxFormBuilder 3.8.0 wxPython GUI界面构建工具 https://github.com/wxFormBuilder/wxFormBuilder
    PyCharm Community 2018.02 一款流行的Python集成开发环境 http://www.jetbrains.com/pycharm/
    PyInstaller 3.3.1 Python应用程序打包工具 http://www.pyinstaller.org/
    https://github.com/pyinstaller/pyinstaller
    vspd 9 虚拟串口驱动,可以在PC上虚拟出Serial Port https://www.eltima.com/products/vspdxp/
    sscom 5.13.1 大虾和丁丁联合推出的一款很流行的串口调试工具 http://www.daxia.com/sscom/

    二、开发环境搭建(Python + pySerial + wxPython + wxFormBuilder)

      pzh-py-com工具是一个完全基于Python语言开发的应用软件,首先安装好Python 2.7.14,痞子衡的安装目录为C: ools_mcuPython27,安装完成后确保系统环境变量里包括该路径(C: ools_mcuPython27),因为该路径下包含python.exe,后续python命令需调用这个python.exe完成的。
      在C: ools_mcuPython27Scripts目录下默认有easy_install.exe,这是PEAK(Python Enterprise Application Kit)开发的setuptools包里的工具,这个工具可以用来完成安装python第三方模块的工作。我们需要借助easy_install.exe来安装pip工具:

    PS C: ools_mcuPython27Scripts> .easy_install.exe pip

    Searching for pip
    Best match: pip 9.0.1
    Adding pip 9.0.1 to easy-install.pth file
    Installing pip-script.py script to c:	ools_mcupython27Scripts
    Installing pip.exe script to c:	ools_mcupython27Scripts
    Installing pip3.5-script.py script to c:	ools_mcupython27Scripts
    Installing pip3.5.exe script to c:	ools_mcupython27Scripts
    Installing pip3-script.py script to c:	ools_mcupython27Scripts
    Installing pip3.exe script to c:	ools_mcupython27Scripts
    
    Using c:	ools_mcupython27libsite-packages
    Processing dependencies for pip
    Finished processing dependencies for pip
    

    PS C: ools_mcuPython27Scripts> python -m pip install --upgrade pip

    Collecting pip
      Downloading > https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
    Installing collected packages: pip
      Found existing installation: pip 9.0.1
        Uninstalling pip-9.0.1:
          Successfully uninstalled pip-9.0.1
    Successfully installed pip-18.0
    

      pip是Python的包管理工具,提供了对Python包的查找、下载、安装、卸载的功能。安装好pip工具之后,可以看到C: ools_mcuPython27Scripts目录下多了pip.exe,为方便后续使用pip来安装其他Python包,确保系统环境变量里包括pip路径(C: ools_mcuPython27Scripts)。我们可以借助pip来安装pySerial和wxPython包:

    PS C: ools_mcuPython27Scripts> .pip.exe install pyserial

    Collecting pyserial
      Downloading https://files.pythonhosted.org/packages/0d/e4/2a744dd9e3be04a0c0907414e2a01a7c88bb3915cbe3c8cc06e209f59c30/pyserial-3.4-py2.py3-none-any.whl (193kB)
    Installing collected packages: pyserial
    Successfully installed pyserial-3.4
    

    PS C: ools_mcuPython27Scripts> .pip.exe install wxPython

    Collecting wxPython
      Downloading https://files.pythonhosted.org/packages/88/88/a23b96662c5ab82dd8dbbb68c68dedea466229e8151fd2911713a1cd27b2/wxPython-4.0.3-cp27-cp27m-win_amd64.whl (22.8MB)
    Collecting six (from wxPython)
      Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
    Collecting PyPubSub (from wxPython)
      Downloading https://files.pythonhosted.org/packages/14/80/8e1d34848fea10826763600ca7eeb7a76d914ccab7cb0d64c9c180c30a73/Pypubsub-4.0.0.zip (64kB)
    Collecting typing (from PyPubSub->wxPython)
      Downloading https://files.pythonhosted.org/packages/0d/4d/4e5985d075d241d686a1663fa1f88b61d544658d08c1375c7c6aac32afc3/typing-3.6.4-py2-none-any.whl
    Installing collected packages: six, typing, PyPubSub, wxPython
      Running setup.py install for PyPubSub ... done
      The scripts helpviewer.exe, img2png.exe, img2py.exe, img2xpm.exe, pycrust.exe, pyshell.exe, pyslices.exe, pyslicesshell.exe, pywxrc.exe, wxdemo.exe, wxdocs.exe and wxget.exe are installed in 'c:	ools_mcupython27Scripts'
    Successfully installed PyPubSub-4.0.0 six-1.11.0 typing-3.6.4 wxPython-4.0.3
    

      有了pySerial便可以访问Serial Port,有了wxPython便可以设计GUI。
      单纯使用wxPython设计pzh-py-com GUI界面时仅能是手工写代码布局,手工布局的界面创建和修改起来都比较繁琐,我们需要一款可视化的界面设计工具,痞子衡选择的是wxFormBuilder,从其github官网下载安装包并安装到C: ools_mcuwxFormBuilder目录下。安装完成打开软件便可在Designer里尽情创作界面,创作完成后点击"Python"便可看到Python GUI源代码,这个GUI源代码后续直接复制到JaysPyCOM工程里使用。

      至此pzh-py-com工具开发的Python基础环境便搭好了。

    三、测试环境搭建(PyCharm + vspd + sscom)

      在开发pzh-py-com工具过程中免不了要调试Python代码,所以我们还需要一个Python IDE,痞子衡选择的是PyCharm,在jetbrains官网下载PyCharm community免费版并安装,安装完成后打开PyCharm并创建名为pzh-py-com空工程,成功创建后会看到pzh-py-com目录下自动生成一个.idea的文件夹,该文件夹是用于pycharm管理项目。

      有了PyCharm环境,便可以开始写pzh-py-com代码,代码在开发过程中,需要结合Serial Port进行联合调试,如果手里没有硬件串口设备,可以使用虚拟串口设备,vspd便是著名的虚拟串口驱动,从eltima官网下载vspd标准版并安装,安装完成后打开vspd可看到如下界面,COM10和COM11(COM号是自定义的)便是虚拟出来的串口设备号,并且已经完成了对接。

      虚拟Serial Port设备已经有了并且对接了,最后还需要一个成熟的串口调试助手,作为串口通讯的另一方,痞子衡选取的是非常经典的sscom,从大虾官网下载sscom包,sscom是个免安装的工具,可以直接打开使用,设置sscom使用COM11,将来pzh-py-com使用COM10。

    四、发布环境搭建(PyInstaller)

      pzh-py-com工具开发和调试工作都完成之后,我们希望将她打包成一个独立的可执行文件(即运行设备不需要安装Python+pySerial+wxPython),PyInstaller可以帮助我们完成打包工作,所以我们需要利用pip工具安装PyInstaller包:

    PS C: ools_mcuPython27Scripts> .pip.exe install pyinstaller

    Collecting pyinstaller
      Downloading https://files.pythonhosted.org/packages/3c/86/909a8c35c5471919b3854c01f43843d9b5aed0e9948b63e560010f7f3429/PyInstaller-3.3.1.tar.gz (3.5MB)
    Requirement already satisfied: setuptools in c:	ools_mcupython27libsite-packages (from pyinstaller) (28.8.0)
    Collecting pefile>=2017.8.1 (from pyinstaller)
      Downloading https://files.pythonhosted.org/packages/ed/cc/157f20038a80b6a9988abc06c11a4959be8305a0d33b6d21a134127092d4/pefile-2018.8.8.tar.gz (62kB)
    Collecting macholib>=1.8 (from pyinstaller)
      Downloading https://files.pythonhosted.org/packages/a1/01/845b2df65117dbdabf00c6df879625f4968ede6f512956710f05f4c7663a/macholib-1.10-py2.py3-none-any.whl
    Collecting dis3 (from pyinstaller)
      Downloading https://files.pythonhosted.org/packages/c8/a1/bb0ab17df7e6cbc6d1555dd1c6fdaa09e90842f0f683507042b9dae83e2d/dis3-0.1.2.tar.gz
    Collecting future (from pyinstaller)
      Downloading https://files.pythonhosted.org/packages/00/2b/8d082ddfed935f3608cc61140df6dcbf0edea1bc3ab52fb6c29ae3e81e85/future-0.16.0.tar.gz (824kB)
    Collecting pypiwin32 (from pyinstaller)
      Downloading https://files.pythonhosted.org/packages/13/e8/4f38eb30c4dae36634a53c5b2cd73b517ea3607e10d00f61f2494449cec0/pypiwin32-223.tar.gz
    Collecting altgraph>=0.15 (from macholib>=1.8->pyinstaller)
      Downloading https://files.pythonhosted.org/packages/0a/cc/646187eac4b797069e2e6b736f14cdef85dbe405c9bfc7803ef36e4f62ef/altgraph-0.16.1-py2.py3-none-any.whl
    Collecting pywin32>=223 (from pypiwin32->pyinstaller)
      Downloading https://files.pythonhosted.org/packages/65/83/0b14690d70bcd193a67c8b0a640129717e37a11d8e6a3e28a01e47910737/pywin32-223-cp27-cp27m-win_amd64.whl (7.3MB)
    Installing collected packages: future, pefile, altgraph, macholib, dis3, pywin32, pypiwin32, pyinstaller
      Running setup.py install for future ... done
      Running setup.py install for pefile ... done
      Running setup.py install for dis3 ... done
      Running setup.py install for pypiwin32 ... done
      Running setup.py install for pyinstaller ... done
    Successfully installed altgraph-0.16.1 dis3-0.1.2 future-0.16.0 macholib-1.10 pefile-2018.8.8 pyinstaller-3.3.1 pypiwin32-223 pywin32-223
    

      PyInstaller包安装好之后,环境搭建便大功告成

      至此,串口调试工具pzh-py-com诞生之环境搭建痞子衡便介绍完毕了,掌声在哪里~~~

    欢迎订阅

    文章会同时发布到我的 博客园主页CSDN主页微信公众号 平台上。

    微信搜索"痞子衡嵌入式"或者扫描下面二维码,就可以在手机上第一时间看了哦。

  • 相关阅读:
    at org.apache.catalina.loader.WebappClassLoader.loadClass问题处理
    java ee 中文乱码的问题
    java.lang.IllegalStateException: getWriter() has already been called for this response问题解决
    Project Euler Problem 23 Non-abundant sums
    Project Euler Problem 24 Lexicographic permutations
    Project Euler Problem 19 Counting Sundays
    CCF201703-2 学生排队(100分)
    Project Euler Problem 17 Number letter counts
    CCF201703-1 分蛋糕(100分)
    Project Euler Problem 92 Square digit chains
  • 原文地址:https://www.cnblogs.com/henjay724/p/9416049.html
Copyright © 2011-2022 走看看