安裝 pyside GUI庫(約170MB)

sudo apt-get install python3-pyside

安裝 matplotlib繪圖庫

sudo pip3 install python3-matplotlib

Python版本確認

python3 --version

查Python已安裝套件資訊

sudo pip3 list

預裝pyserial套件版本過舊處置方式

結論sudo pip3 install pyserial --upgrade

PC端版本

handy@handy-dell ~ $ sudo pip3 list | grep pyserial
[sudo] password for handy: 
pyserial (3.1.1)

查看RPI端版本

pi@raspberrypi:~/solarpi/dev $ sudo pip3 list | grep pyserial
pyserial (2.6)

RPI端更新

pi@raspberrypi:~/solarpi/dev $ sudo pip3 install pyserial --upgrade
Downloading/unpacking pyserial from https://pypi.python.org/packages/c0/a7/25d801d71d2eecbbf0f1142a9d38aa77be71172295259dabb7d91310289c/pyserial-3.2.1-py2.py3-none-any.whl#md5=cb7dbb38abf35498a183a463a040d871
  Downloading pyserial-3.2.1-py2.py3-none-any.whl (189kB): 189kB downloaded
Installing collected packages: pyserial
  Found existing installation: pyserial 2.6
    Not uninstalling pyserial at /usr/lib/python3/dist-packages, owned by OS
Successfully installed pyserial
Cleaning up...

RPI端版號升級

pi@raspberrypi:~/solarpi/dev $ sudo pip3 list | grep pyserial
pyserial (3.2.1)

單元測試,使用doctest

1) 使用直譯器測試新開發函式功能

    handy@handy-dell ~/democode/pycrc $ python3
    Python 3.4.3 (default, Oct 14 2015, 20:28:29)
    [GCC 4.8.4] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from crc import crc16
    >>> lst = [0x01,0x03,0x00,0x00,0xaa,0xbb,0xaa,0xbb]
    >>> ret = crc16(lst)
    >>> hex(ret)
    '0xdde9'
    >>>

2) 將直譯器跑出來的結果複制貼到源碼的document string

    def crc16(buf):
        ''' return crc, port from DDC team.
        >>> lst = [0x01,0x03,0x00,0x00,0xaa,0xbb,0xaa,0xbb]
        >>> hex(crc16(lst))
        '0xdde9'
        >>> lst = [0x01,0x03,0x00,0x00,0xaa,0xbb,0xcc,0xdd]
        >>> hex(crc16(lst))
        '0x7663'
        >>> lst = [0x01,0x03,0xc0,0x20,0x00,0x18]
        >>> hex(crc16(lst))
        '0x780a'
        '''

3) 使用doctest測測看

python3 -m doctest crc.py -v

結果如下

    Trying:
        lst = [0x01,0x03,0x00,0x00,0xaa,0xbb,0xaa,0xbb]
    Expecting nothing
    ok
    Trying:
        hex(crc16(lst))
    Expecting:
        '0xdde9'
    ok
    Trying:
        lst = [0x01,0x03,0x00,0x00,0xaa,0xbb,0xcc,0xdd]
    Expecting nothing
    ok
    Trying:
        hex(crc16(lst))
    Expecting:
        '0x7663'
    ok
    Trying:
        lst = [0x01,0x03,0xc0,0x20,0x00,0x18]
    Expecting nothing
    ok
    Trying:
        hex(crc16(lst))
    Expecting:
        '0x780a'
    ok
    1 items had no tests:
        crc
    1 items passed all tests:
       6 tests in crc.crc16
    6 tests in 2 items.
    6 passed and 0 failed.
    Test passed.

源碼隱藏:編成*.pyc

1) 利用compileall模組

    handy@handy-dell ~/solarpi/dev2 $ python3
    Python 3.4.3 (default, Oct 14 2015, 20:28:29) 
    [GCC 4.8.4] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import compileall
    >>> compileall.compile_dir(".", force=True)

2) 使用compileall後,檔名會跑掉,使用rename指令重命名

    handy@handy-dell ~/solarpi/dev2/__pycache__ $ ls
    crc.cpython-34.pyc        hearbeat.cpython-34.pyc  pvinverter.cpython-34.pyc
    debug.cpython-34.pyc      __init__.cpython-34.pyc  serial2.cpython-34.pyc
    debug_off.cpython-34.pyc  logging2.cpython-34.pyc  upload.cpython-34.pyc
    gui.cpython-34.pyc        main.cpython-34.pyc
    handy@handy-dell ~/solarpi/dev2/__pycache__ $ rename 's/\.cpython-34//' *
    handy@handy-dell ~/solarpi/dev2/__pycache__ $ ls
    crc.pyc        gui.pyc       logging2.pyc    serial2.pyc
    debug_off.pyc  hearbeat.pyc  main.pyc        upload.pyc
    debug.pyc      __init__.pyc  pvinverter.pyc

results matching ""

    No results matching ""